CI | Status |
---|---|
Travis CI | |
CircleCI | |
drone.io | |
codecov |
"reviewdog" provides a way to post review comments to code hosting service, such as GitHub, automatically by integrating with any linter tools with ease. It uses an output of lint tools and posts them as a comment if findings are in diff of patches to review.
reviewdog also supports run in the local environment to filter an output of lint tools by diff.
- Installation
- Input Format
- reviewdog config file
- Reporters
- Reporter: Local (-reporter=local) [default]
- Reporter: GitHub Checks (-reporter=github-pr-check)
- Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)
- Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)
- Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)
- Supported CI services
- Articles
Get the binary release (recommended way)
or
$ go get -u github.com/haya14busa/reviewdog/cmd/reviewdog
reviewdog accepts any compiler or linter result from stdin and parses it with scan-f like 'errorformat', which is the port of Vim's errorformat feature.
For example, if the result format is {file}:{line number}:{column number}: {message}
,
errorformat should be %f:%l:%c: %m
and you can pass it as -efm
arguments.
$ golint ./...
comment_iowriter.go:11:6: exported type CommentWriter should have comment or be unexported
$ golint ./... | reviewdog -efm="%f:%l:%c: %m" -diff="git diff master"
name | description |
---|---|
%f | file name |
%l | line number |
%c | column number |
%m | error message |
%% | the single '%' character |
... | ... |
Please see haya14busa/errorformat and :h errorformat if you want to deal with a more complex output. 'errorformat' can handle more complex output like a multi-line error message.
By this 'errorformat' feature, reviewdog can support any tools output with ease.
But, you don't have to write 'errorformat' in many cases. reviewdog supports pre-defined errorformat for major tools.
You can find available errorformat name by reviewdog -list
and you can use it
with -f={name}
.
$ reviewdog -list
golint linter for Go source code - https://github.com/golang/lint
govet Vet examines Go source code and reports suspicious problems - https://golang.org/cmd/vet/
sbt the interactive build tool - https://www.scala-sbt.org/
...
$ golint ./... | reviewdog -f=golint -diff="git diff master"
You can add supported pre-defined 'errorformat' by contributing to haya14busa/errorformat
reviewdog also accepts checkstyle XML format as well. If the linter supports checkstyle format as a report format, you can use -f=checkstyle instead of using 'errorformat'.
# Local
$ eslint -f checkstyle . | reviewdog -f=checkstyle -diff="git diff"
# CI (overwrite tool name which is shown in review comment by -name arg)
$ eslint -f checkstyle . | reviewdog -f=checkstyle -name="eslint" -reporter=github-pr-check
Also, if you want to pass other Json/XML/etc... format to reviewdog, you can write a converter.
$ <linter> | <convert-to-checkstyle> | reviewdog -f=checkstyle -name="<linter>" -reporter=github-pr-check
reviewdog can also be controlled via the .reviewdog.yml configuration file instead of "-f" or "-efm" arguments.
With .reviewdog.yml, you can run the same commands both CI service and local environment including editor integration with ease.
runner:
<tool-name>:
cmd: <command> # (required)
errorformat: # (optional if there is supporeted format for <tool-name>. see reviewdog -list)
- <list of errorformat>
name: <tool-name> # (optional. you can overwrite <tool-name> defined by runner key)
# examples
golint:
cmd: golint ./...
errorformat:
- "%f:%l:%c: %m"
govet:
cmd: go tool vet -all -shadowstrict .
$ reviewdog -diff="git diff master"
project/run_test.go:61:28: [golint] error strings should not end with punctuation
project/run.go:57:18: [errcheck] defer os.Setenv(name, os.Getenv(name))
project/run.go:58:12: [errcheck] os.Setenv(name, "")
# You can use -conf to specify config file path.
$ reviewdog -conf=./.reviewdog.yml -reporter=github-pr-check
Output format for project config based run is one of the following formats.
<file>: [<tool name>] <message>
<file>:<lnum>: [<tool name>] <message>
<file>:<lnum>:<col>: [<tool name>] <message>
reviewdog can report results both in local environment and review services as continuous integration.
reviewdog can find newly introduced findings by filtering linter results
using diff. You can pass diff command as -diff
arg.
$ golint ./... | reviewdog -f=golint -diff="git diff master"
github-pr-check reporter reports results to GitHub Checks. Since GitHub Checks API is only for GitHub Apps, reviewdog CLI send a request to reviewdog GitHub App server and the server post results as GitHub Checks.
- Install reviewdog Apps. https://github.com/apps/reviewdog
- Set
REVIEWDOG_TOKEN
or run reviewdog CLI in trusted CI providers.
- Get token from
https://reviewdog.app/gh/{owner}/{repo-name}
.
$ export REVIEWDOG_TOKEN="<token>"
$ reviewdog -reporter=github-pr-check
Note: Token is not required if you run reviewdog in Travis or AppVeyor.
As described above, github-pr-check reporter is depending on reviewdog GitHub App server. The server is running with haya14busa's pocket money for now and I may break things, so I cannot ensure that the server is running 24h and 365 days.
github-pr-check reporter is better than github-pr-review reporter in general because it provides more rich feature and has less scope, but please bear in mind the above caution and please use it on your own risk.
You can use github-pr-review reporter if you don't want to depend on reviewdog server.
github-pr-review reporter reports results to GitHub PullRequest review comments using GitHub Personal API Access Token. GitHub Enterprise is supported too.
- Go to https://github.com/settings/tokens and generate new API token.
- Check
repo
for private repositories orpublic_repo
for public repositories.
$ export REVIEWDOG_GITHUB_API_TOKEN="<token>"
$ reviewdog -reporter=github-pr-review`
For GitHub Enterprise, set API endpoint by environment variable.
$ export GITHUB_API="https://example.githubenterprise.com/api/v3/"
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL
Required GitLab version: >= v10.8.0
gitlab-mr-discussion reporter reports results to GitLab MergeRequest discussions using
GitLab Personal API Access token.
Get the token with api
scope from https://gitlab.com/profile/personal_access_tokens.
$ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
$ reviewdog -reporter=gitlab-mr-discussion
For self-hosted GitLab, set API endpoint by environment variable.
$ export GITLAB_API="https://example.gitlab.com/api/v4"
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL
gitlab-mr-commit is similar to gitlab-mr-discussion reporter but reports results to each commit in GitLab MergeRequest.
gitlab-mr-discussion is recommended, but you can use gitlab-mr-commit reporter if your GitLab version is under v10.8.0.
$ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
$ reviewdog -reporter=gitlab-mr-commit
If you use -reporter=github-pr-check in Travis CI, you don't need to set REVIEWDOG_TOKEN
.
Example:
env:
global:
- REVIEWDOG_VERSION="0.9.10"
install:
- mkdir -p ~/bin/ && export export PATH="~/bin/:$PATH"
- curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o ~/bin/reviewdog && chmod +x ~/bin/reviewdog
script:
- reviewdog -conf=.reviewdog.yml -reporter=github-pr-check
Store GitHub API token by travis encryption keys.
$ gem install travis
$ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=<token> --add env.global
Example:
env:
global:
- secure: <token>
- REVIEWDOG_VERSION="0.9.10"
install:
- mkdir -p ~/bin/ && export export PATH="~/bin/:$PATH"
- curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o ~/bin/reviewdog && chmod +x ~/bin/reviewdog
script:
- >-
golint ./... | reviewdog -f=golint -reporter=github-pr-review
Examples
Store REVIEWDOG_TOKEN
or REVIEWDOG_GITHUB_API_TOKEN
in
Environment variables - CircleCI
version: 2
jobs:
build:
docker:
- image: golang:latest
environment:
REVIEWDOG_VERSION: "0.9.10"
steps:
- checkout
- run: curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o reviewdog && chmod +x ./reviewdog
- run: go vet ./... 2>&1 | ./reviewdog -f=govet -reporter=github-pr-check
# or
- run: go vet ./... 2>&1 | ./reviewdog -f=govet -reporter=github-pr-review
Store REVIEWDOG_GITLAB_API_TOKEN
in GitLab CI variable.
reviwedog:
script:
- reviewdog -reporter=gitlab-mr-discussion
# Or
- reviewdog -reporter=gitlab-mr-commit
You can use reviewdog to post review comments from anywhere with following environment variables.
name | description |
---|---|
CI_PULL_REQUEST |
Pull Request number (e.g. 14) |
CI_COMMIT |
SHA1 for the current build |
CI_REPO_OWNER |
repository owner (e.g. "haya14busa" for https://github.com/haya14busa/reviewdog) |
CI_REPO_NAME |
repository name (e.g. "reviewdog" for https://github.com/haya14busa/reviewdog) |
CI_BRANCH |
[optional] branch of the commit |
$ export CI_PULL_REQUEST=14
$ export CI_REPO_OWNER=haya14busa
$ export CI_REPO_NAME=reviewdog
$ export CI_COMMIT=$(git rev-parse HEAD)
and set a token if required.
$ REVIEWDOG_TOKEN="<token>"
$ REVIEWDOG_GITHUB_API_TOKEN="<token>"
$ REVIEWDOG_GITLAB_API_TOKEN="<token>"
$ export CI_PULL_REQUEST=${ghprbPullId}
$ export CI_REPO_OWNER=haya14busa
$ export CI_REPO_NAME=reviewdog
$ export CI_COMMIT=${ghprbActualCommit}
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need
$ REVIEWDOG_TOKEN="<token>" reviewdog -reporter=github-pr-check
# Or
$ REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-review
- reviewdog — A code review dog who keeps your codebase healthy
- reviewdog ♡ GitHub Check — improved automated review experience
haya14busa (https://github.com/haya14busa)