跳转到主要内容

Python、JavaScript、CSS等代码的自动化GitHub PR代码审查器。

项目描述

Lintly

Build Status codecov

Python、JavaScript、CSS等代码的自动化GitHub PR代码审查器。

用法

首先,pip安装lintly

$ pip install lintly

Lintly需要Python 2.7或3.4+。

接下来,设置环境变量LINTLY_API_KEY为您的GitHub API密钥

$ export LINTLY_API_KEY="12345"

最后,将您的linter输出通过管道传递给lintly脚本

$ flake8 | lintly

现在您将看到包含linting错误的审查...

Lintly review on a pull request

...以及提交检查...

Lintly commit check on a pull request

...在您的pull请求上!太棒了!🎉

支持的linters

  • flake8

    $ flake8 | lintly --format=flake8
    
  • black

    $ black . --check 2>&1 >/dev/null | lintly --format=black
    
  • pylint

    • 对于pylint,您必须使用json输出格式。
    $ pylint . --output-format=json | lintly --format=pylint-json
    
  • eslint

    $ eslint . | lintly --format=eslint
    
  • stylelint

    $ stylelint . | lintly --format=stylelint
    
  • cfn-lint

    $ cfn-lint template.yaml | lintly --format=cfn-lint
    
  • cfn-nag

    $ cfn_nag_scan --input-path cloudformation-template.yaml --output-format=json | lintly --format=cfn-nag
    

可以通过修改lintly/parsers.py模块添加额外的linters。

配置

至少Lintly需要以下信息来确定如何发布正确的GitHub PR审查

  • GitHub API密钥 (--api-keyLINTLY_API_KEY环境变量)
    • 在此处生成自己的API密钥。API密钥需要以下GitHub范围
      • repo:status 以便Lintly可以在PR上发布提交状态。
      • public_repo 以便Lintly可以在公共仓库上创建pull请求审查。
      • repo 以便Lintly可以在私有仓库上创建pull请求审查。
  • GitHub仓库 (--repoLINTLY_REPO环境变量)
    • 这是您以grantmcconnaughey/lintly格式的仓库。

    注意:大多数持续集成平台会自动提供此值。

  • 拉取请求编号 (--prLINTLY_PR 环境变量)

    注意:大多数持续集成平台会自动提供此值。

这些配置值可以通过环境变量提供给Lintly,在支持的持续集成平台中运行时会自动发现,或者通过作为Lintly CLI的参数传入。

选项

可以通过运行 lintly --help 来查看所有配置值的列表。

Usage: lintly [OPTIONS]

  Slurp up linter output and send it to a GitHub PR review.

Options:
  --api-key TEXT                  The GitHub API key to use for commenting on
                                  PRs (required)
  --repo TEXT                     The GitHub repo name in the format
                                  {owner}/{repo}
  --pr TEXT                       The pull request number for this build
                                  (required)
  --commit-sha TEXT               The commit Lintly is running against
                                  (required)
  --format [unix|flake8|pylint-json|eslint|eslint-unix|stylelint|black|cfn-lint|cfn-nag]
                                  The linting output format Lintly should
                                  expect to receive. Default "flake8"
  --context TEXT                  Override the commit status context
  --fail-on [any|new]             Whether Lintly should fail if any violations
                                  are detected or only if new violations are
                                  detected. Default "any"
  --post-status / --no-post-status
                                  Used to determine if Lintly should post a PR
                                  status to GitHub. Default true
  --request-changes / --no-request-changes
                                  Whether Lintly should post violations as a
                                  PR request for changes instead of a comment
                                  review. Default true
  --use-checks / --no-use-checks  Whether Lintly should try to use the GitHub
                                  Checks API to report on changes requested.
                                  This only works when running as a GitHub
                                  App. Default false
  --log                           Send Lintly debug logs to the console.
                                  Default false
  --exit-zero / --no-exit-zero    Whether Lintly should exit with error code
                                  indicating amount of violations or not.
                                  Default false
  --help                          Show this message and exit.

支持的持续集成平台

Lintly与ci.py支持的所有持续集成平台无缝配合。要添加对新的持续集成平台的支持,请向ci.py仓库提交一个PR。

当使用这些持续集成平台时,将自动检测仓库、拉取请求编号和提交SHA。

GitHub Actions 示例

要使用Lintly与GitHub Actions,创建一个名为 .github/workflows/lint.yaml 的文件,内容如下:

name: Lint

on: [pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dependencies
      run: pip install flake8 lintly
    - name: Lint with flake8
      run: flake8 | lintly
      env:
        LINTLY_API_KEY: ${{ secrets.GITHUB_TOKEN }}

Travis CI 示例

要使用Lintly与Travis CI,将以下内容添加到您的 .travis.yml 配置文件中:

language: python

jobs:
  include:
    - stage: lint
      install: pip install lintly
      script: flake8 | lintly --format=flake8

stages:
  - lint

项目详情


下载文件

下载适合您平台的电影。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分发

lintly-0.6.0.tar.gz (369.3 kB 查看哈希)

上传时间

构建分发

lintly-0.6.0-py2.py3-none-any.whl (23.3 kB 查看哈希)

上传时间 Python 2 Python 3

由以下机构支持