Python、JavaScript、CSS等语言的GitHub PR代码审查自动化工具。
项目描述
Lintly
Python、JavaScript、CSS等语言的GitHub PR代码审查自动化工具。
用法
首先,pip
安装lintly
$ pip install lintly
Lintly需要Python 3.6+。
接下来,将环境变量LINTLY_API_KEY
设置为您的GitHub API密钥
$ export LINTLY_API_KEY="12345"
最后,将您的代码审查工具的输出通过管道传递给lintly
脚本
$ flake8 | lintly
现在您将看到带有代码审查错误的审核...
...以及提交检查...
...在您的pull requests上!太酷了!🎉
支持的代码审查工具
-
$ flake8 | lintly --format=flake8
-
$ black . --diff --check | lintly --format=black
-
- 对于pylint,您必须使用
json
输出格式。
$ pylint . --output-format=json | lintly --format=pylint-json
- 对于pylint,您必须使用
-
$ eslint . | lintly --format=eslint
-
$ stylelint . | lintly --format=stylelint
-
$ bandit -r . --format=json | lintly --format=bandit-json
-
$ gitleaks --path=. --redact --no-git --report=>(lintly --format=gitleaks)
-
$ hadolint path/to/Dockerfile --format json | lintly --format=hadolint
-
$ terrascan scan -d path/to/terraform/file -o json | lintly --format=terrascan
-
$ trivy --quiet fs -f json path/to/directory/ | lintly --format=trivy
-
$ tfsec path/to/directory/ -f json | lintly --format=tfsec
-
$ cfn-lint template.yaml | lintly --format=cfn-lint
-
$ cfn_nag_scan --input-path cloudformation-template.yaml --output-format=json | lintly --format=cfn-nag
-
$ checkmake Makefile --format={{.LineNumber}}:{{.Rule}}:{{.Violation}} | lintly --format=checkmake
-
$ semgrep --config "p/r2c-security-audit" --json | lintly --format=semgrep
-
[deps-checker]
$ deps-checker path/to/dependency/file | lintly --format=deps-checker
可以通过修改 lintly/parsers.py
模块来添加额外的 linters。
配置
至少 Lintly 需要知道以下信息,以确定如何发布正确的 GitHub PR Review:
- GitHub API 密钥 (
--api-key
或LINTLY_API_KEY
环境变量)- 在此处生成您的 API 密钥:https://github.com/settings/tokens/new。API 密钥需要以下 GitHub 权限:
repo:status
以便 Lintly 在 PR 上发布提交状态。public_repo
以便 Lintly 在公共仓库上创建 PR 审查。repo
以便 Lintly 在私有仓库上创建 PR 审查。
- 在此处生成您的 API 密钥:https://github.com/settings/tokens/new。API 密钥需要以下 GitHub 权限:
- GitHub 仓库 (
--repo
或LINTLY_REPO
环境变量)- 这是您的仓库格式,例如
grantmcconnaughey/lintly
。
注意:大多数持续集成平台都会自动提供此值。
- 这是您的仓库格式,例如
- PR 号码 (
--pr
或LINTLY_PR
环境变量)注意:大多数持续集成平台都会自动提供此值。
- Slack Webhook (
--slack
或SLACK_WEBHOOK
环境变量)将消息发布到 Slack。消息将包括违规摘要和 PR 链接。
- LINTLY_FILE_OVERRIDE (
LINTLY_FILE_OVERRIDE
环境变量)用环境变量中提供的内容覆盖工具提供的文件/路径。当 linter 工具不提供完整路径和文件名时很有用。例如 TTAM Super-linter 可以覆盖工具并提供信息。
这些配置值可以通过环境变量提供给 Lintly,在支持 CI 平台上运行时自动发现,或通过传递给 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|checkmake|bandit-json|gitleaks|hadolint|terrascan|trivy|tfsec|semgrep]
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 平台无缝工作。要添加对新 CI 平台的支持,请向 ci.py 仓库提交一个 PR。
使用这些 CI 平台时,将自动检测仓库、PR 号码和提交 SHA。
GitHub Actions 示例
要使用 GitHub Actions 与 Lintly,创建一个名为 .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 示例
要使用 Travis CI 与 Lintly,将以下内容添加到您的 .travis.yml
配置文件中:
language: python
jobs:
include:
- stage: lint
install: pip install lintly
script: flake8 | lintly --format=flake8
stages:
- lint
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。