Code Monkey home page Code Monkey logo

reviewdog / reviewdog Goto Github PK

View Code? Open in Web Editor NEW
7.4K 53.0 395.0 4.18 MB

๐Ÿถ Automated code review tool integrated with any code analysis tools regardless of programming language

Home Page: https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b#.8xctbaw5u

License: MIT License

Go 96.52% Shell 2.18% HTML 1.15% Dockerfile 0.15%
linter go lint ci code-review github gitlab codereview cli code-quality static-analysis static-code-analysis bitbucket

reviewdog's Introduction

reviewdog - A code review dog who keeps your codebase healthy.


reviewdog provides a way to post review comments to code hosting services, 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 the diff of patches to review.

reviewdog also supports running in the local environment to filter the output of lint tools by diff.

design doc

Table of Contents

github-pr-check sample comment in pull-request commit status sample-comment.png reviewdog-local-demo.gif

Installation

# Install the latest version. (Install it into ./bin/ by default).
$ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s

# Specify installation directory ($(go env GOPATH)/bin/) and version.
$ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]

# In alpine linux (as it does not come with curl by default)
$ wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s [vX.Y.Z]

Nightly releases

You can also use nightly reviewdog release to try the latest reviewdog improvements every day!

$ curl -sfL https://raw.githubusercontent.com/reviewdog/nightly/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

GitHub Action: reviewdog/action-setup

steps:
- uses: reviewdog/action-setup@v1
  with:
    reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]

homebrew / linuxbrew

You can also install reviewdog using brew:

$ brew install reviewdog/tap/reviewdog
$ brew upgrade reviewdog/tap/reviewdog

Scoop on Windows

> scoop install reviewdog

Build with go install

$ go install github.com/reviewdog/reviewdog/cmd/reviewdog@latest

Input Format

'errorformat'

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 FETCH_HEAD"
name description
%f file name
%l line number
%c column number
%m error message
%% the single '%' character
... ...

Please see reviewdog/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.

You can also try errorformat on the Playground!

With this 'errorformat' feature, reviewdog can support any tool output with ease.

Available pre-defined 'errorformat'

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                                      - http://www.scala-sbt.org/
...
$ golint ./... | reviewdog -f=golint -diff="git diff FETCH_HEAD"

You can add supported pre-defined 'errorformat' by contributing to reviewdog/errorformat

Reviewdog Diagnostic Format (RDFormat)

reviewdog supports Reviewdog Diagnostic Format (RDFormat) as a generic diagnostic format and it supports both rdjson and rdjsonl formats.

This rdformat supports rich features like multiline ranged comments, severity, rule code with URL, and code suggestions.

$ <linter> | <convert-to-rdjson> | reviewdog -f=rdjson -reporter=github-pr-review
# or
$ <linter> | <convert-to-rdjsonl> | reviewdog -f=rdjsonl -reporter=github-pr-review

Example: ESLint with RDFormat

eslint reviewdog rdjson demo

You can use eslint-formatter-rdjson to output rdjson as eslint output format.

$ npm install --save-dev eslint-formatter-rdjson
$ eslint -f rdjson . | reviewdog -f=rdjson -reporter=github-pr-review

Or you can also use reviewdog/action-eslint for GitHub Actions.

Diff

reviewdog with gofmt example

reviewdog supports diff (unified format) as an input format especially useful for code suggestions. reviewdog can integrate with any code suggestions tools or formatters to report suggestions.

-f.diff.strip: option for -f=diff: strip NUM leading components from diff file names (equivalent to 'patch -p') (default is 1 for git diff) (default 1)

$ <any-code-fixer/formatter> # e.g. eslint --fix, gofmt
$ TMPFILE=$(mktemp)
$ git diff >"${TMPFILE}"
$ git stash -u && git stash drop
$ reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review < "${TMPFILE}"

Or you can also use reviewdog/action-suggester for GitHub Actions.

If diagnostic tools support diff output format, you can pipe the diff directly.

$ gofmt -s -d . | reviewdog -name="gofmt" -f=diff -f.diff.strip=0 -reporter=github-pr-review
$ shellcheck -f diff $(shfmt -f .) | reviewdog -f=diff

checkstyle format

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-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

SARIF format

reviewdog supports SARIF 2.1.0 JSON format. You can use reviewdog with -f=sarif option.

# Local
$ eslint -f @microsoft/eslint-formatter-sarif . | reviewdog -f=sarif -diff="git diff"

Code Suggestions

eslint reviewdog suggestion demo reviewdog with gofmt example

reviewdog supports code suggestions feature with rdformat or diff input. You can also use reviewdog/action-suggester for GitHub Actions.

reviewdog can suggest code changes along with diagnostic results if a diagnostic tool supports code suggestions data. You can integrate reviewdog with any code fixing tools and any code formatter with diff input as well.

Code Suggestions Support Table

Note that not all reporters provide support for code suggestions.

-reporter Suggestion support
local NO [1]
github-check NO [2]
github-pr-check NO [2]
github-pr-review OK
gitlab-mr-discussion OK
gitlab-mr-commit NO [2]
gerrit-change-review NO [1]
bitbucket-code-report NO [2]
gitea-pr-review NO [2]
  • [1] The reporter service supports the code suggestion feature, but reviewdog does not support it yet. See #678 for the status.
  • [2] The reporter service itself doesn't support the code suggestion feature.

reviewdog config file

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 for both CI service and local environment including editor integration with ease.

.reviewdog.yml

runner:
  <tool-name>:
    cmd: <command> # (required)
    errorformat: # (optional if you use `format`)
      - <list of errorformat>
    format: <format-name> # (optional if you use `errorformat`. e.g. golint,rdjson,rdjsonl)
    name: <tool-name> # (optional. you can overwrite <tool-name> defined by runner key)
    level: <level> # (optional. same as -level flag. [info,warning,error])

  # examples
  golint:
    cmd: golint ./...
    errorformat:
      - "%f:%l:%c: %m"
    level: warning
  govet:
    cmd: go vet -all .
    format: govet
  your-awesome-linter:
    cmd: awesome-linter run
    format: rdjson
    name: AwesomeLinter
$ reviewdog -diff="git diff FETCH_HEAD"
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 -runners to run only specified runners.
$ reviewdog -diff="git diff FETCH_HEAD" -runners=golint,govet
project/run_test.go:61:28: [golint] error strings should not end with punctuation
# 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>

Reporters

reviewdog can report results both in the local environment and review services as continuous integration.

Reporter: Local (-reporter=local) [default]

reviewdog can find newly introduced findings by filtering linter results using diff. You can pass the diff command as -diff arg.

$ golint ./... | reviewdog -f=golint -diff="git diff FETCH_HEAD"

Reporter: GitHub Checks (-reporter=github-pr-check)

github-pr-check sample annotation with option 1 github-pr-check sample

github-pr-check reporter reports results to GitHub Checks.

You can change the report level for this reporter by level field in config file or -level flag. You can control GitHub status check results with this feature. (default: error)

Level GitHub Status
info neutral
warning neutral
error failure

There are two options to use this reporter.

Option 1) Run reviewdog from GitHub Actions w/ secrets.GITHUB_TOKEN

Example: .github/workflows/reviewdog.yml

- name: Run reviewdog
  env:
    REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    golint ./... | reviewdog -f=golint -reporter=github-pr-check

See GitHub Actions section too. You can also use public reviewdog GitHub Actions.

Option 2) Install reviewdog GitHub Apps

reviewdog CLI sends a request to reviewdog GitHub App server and the server post results as GitHub Checks, because Check API is only supported for GitHub App and GitHub Actions.

  1. Install reviewdog Apps. https://github.com/apps/reviewdog
  2. 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.

Caution

As described above, github-pr-check reporter with Option 2 depends 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.

UPDATE: Started getting support by opencollective and GitHub sponsor. See Supporting reviewdog

You can use github-pr-review reporter or use run reviewdog under GitHub Actions if you don't want to depend on reviewdog server.

Reporter: GitHub Checks (-reporter=github-check)

It's basically the same as -reporter=github-pr-check except it works not only for Pull Request but also for commit.

sample comment outside diff

You can create reviewdog badge for this reporter.

Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)

sample-comment.png

github-pr-review reporter reports results to GitHub PullRequest review comments using GitHub Personal API Access Token. GitHub Enterprise is supported too.

$ export REVIEWDOG_GITHUB_API_TOKEN="<token>"
$ reviewdog -reporter=github-pr-review

For GitHub Enterprise, set the API endpoint by an 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

See GitHub Actions section too if you can use GitHub Actions. You can also use public reviewdog GitHub Actions.

Reporter: GitHub PR Annotations (-reporter=github-pr-annotations)

github-pr-annotations uses the GitHub Actions annotation format to output errors and warnings to stdout e.g.

::error line=11,col=41,file=app/index.md::[vale] reported by reviewdog ๐Ÿถ%0A[demo.Spelling] Did you really mean 'boobarbaz'?%0A%0ARaw Output:%0A{"message": "[demo.Spelling] Did you really mean 'boobarbaz'?", "location": {"path": "app/index.md", "range": {"start": {"line": 11, "column": 41}}}, "severity": "ERROR"}

This reporter requires a valid GitHub API token to generate a diff, but will not use the token to report errors.

Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)

gitlab-mr-discussion sample

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

The CI_API_V4_URL environment variable, defined automatically by Gitlab CI (v11.7 onwards), will be used to find out the Gitlab API URL.

Alternatively, GITLAB_API can also be defined, in which case it will take precedence over CI_API_V4_URL.

$ export GITLAB_API="https://example.gitlab.com/api/v4"
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL

Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)

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

Reporter: Gerrit Change review (-reporter=gerrit-change-review)

gerrit-change-review reporter reports results to Gerrit Change using Gerrit Rest APIs.

The reporter supports Basic Authentication and Git-cookie based authentication for reporting results.

Set GERRIT_USERNAME and GERRIT_PASSWORD environment variables for basic authentication, and put GIT_GITCOOKIE_PATH for git cookie-based authentication.

$ export GERRIT_CHANGE_ID=changeID
$ export GERRIT_REVISION_ID=revisionID
$ export GERRIT_BRANCH=master
$ export GERRIT_ADDRESS=http://<gerrit-host>:<gerrit-port>
$ reviewdog -reporter=gerrit-change-review

Reporter: Bitbucket Code Insights Reports (-reporter=bitbucket-code-report)

bitbucket-code-report bitbucket-code-annotations

bitbucket-code-report generates the annotated Bitbucket Code Insights report.

For now, only the no-filter mode is supported, so the whole project is scanned on every run. Reports are stored per commit and can be viewed per commit from Bitbucket Pipelines UI or in Pull Request. In the Pull Request UI affected code lines will be annotated in the diff, as well as you will be able to filter the annotations by This pull request or All.

If running from Bitbucket Pipelines, no additional configuration is needed (even credentials). If running locally or from some other CI system you would need to provide Bitbucket API credentials:

  • For Basic Auth you need to set the following env variables: BITBUCKET_USER and BITBUCKET_PASSWORD
  • For AccessToken Auth you need to set BITBUCKET_ACCESS_TOKEN
$ export BITBUCKET_USER="my_user"
$ export BITBUCKET_PASSWORD="my_password"
$ reviewdog -reporter=bitbucket-code-report

To post a report to the Bitbucket Server use BITBUCKET_SERVER_URL variable:

$ export BITBUCKET_USER="my_user"
$ export BITBUCKET_PASSWORD="my_password"
$ export BITBUCKET_SERVER_URL="https://bitbucket.my-company.com"
$ reviewdog -reporter=bitbucket-code-report

Supported CI services

Example: .github/workflows/reviewdog.yml

name: reviewdog
on: [pull_request]
jobs:
  reviewdog:
    name: reviewdog
    runs-on: ubuntu-latest
    steps:
      # ...
      - uses: reviewdog/action-setup@v1
        with:
          reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
      - name: Run reviewdog
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          reviewdog -reporter=github-pr-check -runners=golint,govet
          # or
          reviewdog -reporter=github-pr-review -runners=golint,govet
Example (github-check reporter):

.github/workflows/reviewdog

Only github-check reporter can run on the push event too.

name: reviewdog (github-check)
on:
  push:
    branches:
      - master
  pull_request:

jobs:
  reviewdog:
    name: reviewdog
    runs-on: ubuntu-latest
    steps:
      # ...
      - name: Run reviewdog
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          reviewdog -reporter=github-check -runners=golint,govet

Public Reviewdog GitHub Actions

You can use public GitHub Actions to start using reviewdog with ease! ๐ŸŽ‰ โ–ถ๏ธ ๐ŸŽ‰

... and more on GitHub Marketplace.

Missing actions? Check out reviewdog/action-template and create a new reviewdog action!

Please open a Pull Request to add your created reviewdog actions here โœจ. I can also put your repositories under reviewdog org and co-maintain the actions. Example: action-tflint.

Graceful Degradation for Pull Requests from forked repositories

Graceful Degradation example

GITHUB_TOKEN for Pull Requests from a forked repository doesn't have write access to Check API nor Review API due to GitHub Actions restriction.

Instead, reviewdog uses Logging commands of GitHub Actions to post results as annotations similar to github-pr-check reporter.

Note that there is a limitation for annotations created by logging commands, such as max # of annotations per run. You can check GitHub Actions log to see full results in such cases.

reviewdog badge reviewdog

As github-check reporter support running on commit, we can create reviewdog GitHub Action badge to check the result against master commit for example. ๐ŸŽ‰

Example:

<!-- Replace <OWNER> and <REPOSITORY>. It assumes workflow name is "reviewdog" -->
[![reviewdog](https://github.com/<OWNER>/<REPOSITORY>/workflows/reviewdog/badge.svg?branch=master&event=push)](https://github.com/<OWNER>/<REPOSITORY>/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster)

Travis CI

Travis CI (-reporter=github-pr-check)

If you use -reporter=github-pr-check in Travis CI, you don't need to set REVIEWDOG_TOKEN.

Example:

install:
  - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
  - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin

script:
  - reviewdog -conf=.reviewdog.yml -reporter=github-pr-check

Travis CI (-reporter=github-pr-review)

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>

install:
  - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
  - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin

script:
  - >-
    golint ./... | reviewdog -f=golint -reporter=github-pr-review

Examples

Circle CI

Store REVIEWDOG_GITHUB_API_TOKEN (or REVIEWDOG_TOKEN for github-pr-check) in Environment variables - CircleCI

.circleci/config.yml sample

version: 2
jobs:
  build:
    docker:
      - image: golang:latest
    steps:
      - checkout
      - run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ./bin
      - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-review

      # Deprecated: prefer GitHub Actions to use github-pr-check reporter.
      - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-check

GitLab CI

Store REVIEWDOG_GITLAB_API_TOKEN in GitLab CI variable.

.gitlab-ci.yml sample

reviewdog:
  script:
    - reviewdog -reporter=gitlab-mr-discussion
    # Or
    - reviewdog -reporter=gitlab-mr-commit

Bitbucket Pipelines

No additional configuration is needed.

bitbucket-pipelines.yml sample

pipelines:
  default:
    - step:
        name: Reviewdog
        image: golangci/golangci-lint:v1.31-alpine
        script:
          - wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | 
              sh -s -- -b $(go env GOPATH)/bin
          - golangci-lint run --out-format=line-number ./... | reviewdog -f=golangci-lint -reporter=bitbucket-code-report

Common (Jenkins, local, etc...)

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. "reviewdog" for https://github.com/reviewdog/errorformat)
CI_REPO_NAME repository name (e.g. "errorformat" for https://github.com/reviewdog/errorformat)
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>"

If a CI service doesn't provide information such as Pull Request ID - reviewdog can guess it by a branch name and commit SHA. Just pass the flag guess:

$ reviewdog -conf=.reviewdog.yml -reporter=github-pr-check -guess

Jenkins with GitHub pull request builder plugin

$ 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

# To submit via reviewdog server using github-pr-check reporter
$ REVIEWDOG_TOKEN="<token>" reviewdog -reporter=github-pr-check
# Or, to submit directly via API using github-pr-review reporter
$ REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-review
# Or, to submit directly via API using github-pr-check reporter (requires GitHub App Account configured)
$ REVIEWDOG_SKIP_DOGHOUSE=true REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-check

Exit codes

By default reviewdog will return 0 as exit code even if it finds errors. If -fail-on-error flag is passed, reviewdog exits with 1 when at least one error was found/reported. This can be helpful when you are using it as a step in your CI pipeline and want to mark the step failed if any error found by linter.

See also -level flag for github-pr-check/github-check reporters. reviewdog will exit with 1 if reported check status is failure as well if -fail-on-error=true.

Filter mode

reviewdog filter results by diff and you can control how reviewdog filter results by -filter-mode flag. Available filter modes are as below.

added (default)

Filter results by added/modified lines.

diff_context

Filter results by diff context. i.e. changed lines +-N lines (N=3 for example).

file

Filter results by added/modified file. i.e. reviewdog will report results as long as they are in added/modified file even if the results are not in actual diff.

nofilter

Do not filter any results. Useful for posting results as comments as much as possible and check other results in console at the same time.

-fail-on-error also works with any filter-mode and can catch all results from any linters with nofilter mode.

Example:

$ reviewdog -reporter=github-pr-review -filter-mode=nofilter -fail-on-error

Filter Mode Support Table

Note that not all reporters provide full support for filter mode due to API limitation. e.g. github-pr-review reporter uses GitHub Review API but this API don't support posting comments outside diff context, so reviewdog will use Check annotation as fallback to post those comments [1].

-reporter \ -filter-mode added diff_context file nofilter
local OK OK OK OK
github-check OK OK OK OK
github-pr-check OK OK OK OK
github-pr-review OK OK Partially Supported [1] Partially Supported [1]
github-pr-annotations OK OK OK OK
gitlab-mr-discussion OK OK OK Partially Supported [2]
gitlab-mr-commit OK Partially Supported [2] Partially Supported [2] Partially Supported [2]
gerrit-change-review OK OK? [3] OK? [3] Partially Supported? [2][3]
bitbucket-code-report NO [4] NO [4] NO [4] OK
gitea-pr-review OK OK Partially Supported [2] Partially Supported [2]
  • [1] Report results that are outside the diff file with Check annotation as fallback if it's running in GitHub actions instead of Review API (comments). All results will be reported to console as well.
  • [2] Report results that are outside the diff file to console.
  • [3] It should work, but not been verified yet.
  • [4] Not implemented at the moment

Debugging

Use the -tee flag to show debug info.

reviewdog -filter-mode=nofilter -tee

Articles

๐Ÿฆ Author

haya14busa GitHub followers

Contributors

Contributors

Supporting reviewdog

Become GitHub Sponsor for each contributor or become a backer or sponsor from opencollective.

Become a backer

reviewdog's People

Contributors

bgpat avatar carl-printreleaf avatar carmanchris31 avatar dependabot[bot] avatar epmatt avatar haya14busa avatar i-sevostyanov avatar irgaly avatar jsoref avatar lafriks avatar lgellrich avatar massongit avatar mavimo avatar mgrachev avatar mheap avatar nakatanakatana avatar nmotod avatar oohira avatar polamjag avatar renovate-bot avatar renovate[bot] avatar roobre avatar shogo82148 avatar sivchari avatar step-security-bot avatar taraspos avatar timakin avatar trim21 avatar tsuyoshicho avatar warashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reviewdog's Issues

Authentication with repository API tokens is unsafe for PR builds

Reviewdog is specifically designed to run in CI's PR/MR builds, in order to generate code reviews.

In these conditions it's not safe to use private environment variables. PR's should be regarded as "untrusted code" and not run in CI's with access to private information before they're accepted (which is what the CI build does).

Even if the variables aren't being added as clear text, the author of the PR can add a keylogger and steal your variables.

Travis has enabled a protection against this, but this also means reviewdog can't access the key.

It's possible to avoid this by using the "checks"-reporter instead, but I prefer code reviews over checks.

This seems like a great tool that I want to use, but this issue is a deal breaker for me. I think the GitHub App has to do this instead, like with your "checks"-reporter or other solutions like stickler-ci or HoundCI.

Check filtered finding when error is on another line than `git diff`

I'm trying out to create a PHP Linter.

I have a file like this:

public function create()
{
    // i make a mistake below by forgetting the trailing ;  line 33
    blaat()  // <-- line 34
}

My php linter gives the following error:

src/AdminBundle/Job/PostAdminMessageToSlackJob.php:35: PHP Parse error: syntax error, unexpected '$job' (T_VARIABLE)

And Reviewdog marks this finding as filtered:

Findings (0)
Filtered Findings (1)
src/AdminBundle/Job/PostAdminMessageToSlackJob.php:35: PHP Parse error: syntax error, unexpected '$job' (T_VARIABLE)

That's because Reviewdog does a strict lookup for the given row number in the git diff. But in PHP the error will sometimes be on the next line.

Any idea how to solve this?

Doesn't Github allow for adding checks to lines that didn't change? It always shows ยฑ5 lines before and after right? Maybe we can take that margin into account here?

gofmt support

Hi there!

It'd be great if reviewdog supported gofmt.

My case:

  1. A not formatted file main.go
$> cat main.go 
package main

import "fmt"

func main() { HelloWorld() }

func HelloWorld() {fmt.Println("hello world")}
  1. reviewdog config
$> cat reviewdog.yml                                                                                                                                                                                            
runner:
  golint:
    cmd: golint $(go list ./... | grep -v /vendor/)
    errorformat:
      - "%f:%l:%c: %m"
  gofmt:
    cmd: gofmt -l -s .|xargs -I{} echo {}:1 file {} is not gofmted
    errorformat:
      - "%f:%l %m"
  1. The diff:
$> git diff HEAD~1

diff --git a/main.go b/main.go
index fff5c2b..66228c0 100644
--- a/main.go
+++ b/main.go
@@ -2,4 +2,6 @@ package main
 
 import "fmt"
 
-func main() { fmt.Println("vim-go")}
+func main() { HelloWorld() }
+
+func HelloWorld() {fmt.Println("hello world")}
  1. The result of execution:
$> reviewdog -diff='git diff HEAD~1'
main.go:7:1: [golint] exported function HelloWorld should have comment or be unexported

AFAIU that's because of "FilteredCheck.InDiff" that remains false during the "FilterCheck" step.

How would you fix it?
I'd like to fix it myself and send PR if you don't mind.

Thanks in advance

Add documentation for Jenkins

ใ“ใกใ‚‰ใฎใƒ„ใƒผใƒซใ‚’JenkinsไธŠใงๅˆฉ็”จใ•ใ›ใฆใ„ใŸใ ใใพใ—ใŸใ€‚
ใ‚ใ‚ŠใŒใจใ†ใ”ใ–ใ„ใพใ™ใ€‚

ไธ€็‚นใฏใพใฃใŸ้ƒจๅˆ†ใŒใ‚ใ‚‹ใฎใงREADMEใซ่ฟฝ่จ˜ใ—ใฆใŠใ„ใฆใ„ใŸใ ใ‘ใ‚‹ใจๅฌ‰ใ—ใ„ใชใจๆ€ใ„ใพใ™ใ€‚

jenkinsใงGitHub pull request builder pluginใ‚’ไฝฟ็”จใ—ใŸใจใใซCI_COMMITใ‚’ไปฅไธ‹ใฎๅ€คใซใ™ใ‚‹ใจๅคฑๆ•—ใ—ใพใ™ใ€‚

export CI_COMMIT=$(git rev-parse HEAD)

[{Resource:PullRequestReviewComment Field:commit_id Code:custom Message:commit_id is not part of the pull request}]

ใ“ใ‚Œใฏไปฎใซใƒžใƒผใ‚ธใ•ใ‚ŒใŸใ‚ณใƒŸใƒƒใƒˆใงAPIใ‚’ใŸใŸใ„ใฆใ„ใ‚‹ใ‹ใ‚‰ใ ใจๆ€ใ„ใพใ™ใ€‚
ไปฅไธ‹ใฎใ‚ˆใ†ใซใ™ใ‚‹ใจๆญฃใ—ใๆˆๅŠŸใ—ใพใ™ใ€‚

export CI_COMMIT=${ghprbActualCommit}

reviewdog POST api.github.com 422 Validation Failed

tried on Travis always got that https://travis-ci.org/thunderdb/ThunderDB/jobs/371431240 (the last line)

and I also tried on my Macbook with

export TRAVIS=true
export TRAVIS_PULL_REQUEST=1
export TRAVIS_PULL_REQUEST_BRANCH=feature/routing
export TRAVIS_COMMIT=758d84fee7292ef61bcb3d63572ee300bc7cf0cf
export TRAVIS_PULL_REQUEST_SHA=3216c2fd342af8e264a0aa8658dcf9cdb6a5a710
export TRAVIS_REPO_SLUG=thunderdb/ThunderDB
export TRAVIS_SECURE_ENV_VARS=true
export REVIEWDOG_GITHUB_API_TOKEN=xxxxxx

still:
reviewdog: POST https://api.github.com/repos/thunderdb/ThunderDB/pulls/1/reviews: 422 Validation Failed [{Resource: Field: Code: Message:}]

run reviewdog using project based config

Use reviewdog.yml in the root project to run reviewdog might be useful.

For now, we have to add -ci or -diff arg in accordance with the situation, so we cannot run lint easily both in local and CI server.

By using reviewdog conf file, we can run reviewdog $ reviewdog [-diff="git diff master"] or $ reviewdog -ci=droneio. It's really easy to run and easy to integrate with editor or commit hook.

Security

In CI server, reviewdog needs secret GitHub API token and attackers can create pull-request to get secret token if CI service is not secure.
Drone.io handles this problem with checksum of yml file, but if we introduce reviewdog conf file, checksum of drone.yml doesn't protect the secret token.

To handle this problem, reviewdog can store secret token in memory, remove secret env var, and run linter commands

stop command when parse a very long line linter text

$ cat linter.log
text
text text
............ very long line (stop parsing in this lines
reviewdog target line
text
$ cat linter.log | reviewdog -efm="%f(%l,%c): %m" -diff="git diff develop" 

my linter.log has 15178 characters in the largest line.

now, avoid this case, I use cut command:

$ cat linter.log | cut -b-10240 | reviewdog ...
reviewdog target line

Is this a bug?

Thanks.

PS.
reviewdog is nice tool ๐Ÿ˜„
Thanks again.

Error retrieving token for reviewdog.app

I went to https://reviewdog.app/gh/{owner}/{repo} to get my token after setting up the GitHub integration and got this error. When I login at reviewdog.app, it shows that my account is successfully connected. Anything else I can try?

failed to get repo: &github.ErrorResponse{Response:(*http.Response)(0xc008515170), Message:"Resource not accessible by integration", Errors:[]github.Error(nil), Block:(*struct { Reason string "json:\"reason,omitempty\""; CreatedAt *github.Timestamp "json:\"created_at,omitempty\"" })(nil), DocumentationURL:"https://developer.github.com/v3/repos/#get"}

Cannot 'go get' due to some API changes in go-github

I tried to install the command with go get but failed. It seems go-github changed some of the APIs (see google/go-github#529).

$ go get -u github.com/haya14busa/reviewdog/cmd/reviewdog 
# github.com/haya14busa/reviewdog
./github.go:132: not enough arguments in call to g.cli.PullRequests.CreateReview
        have (string, string, int, *github.PullRequestReviewRequest)
        want ("context".Context, string, string, int, *github.PullRequestReviewRequest)
./github.go:151: not enough arguments in call to g.cli.PullRequests.CreateComment
        have (string, string, int, *github.PullRequestComment)
        want ("context".Context, string, string, int, *github.PullRequestComment)
./github.go:190: not enough arguments in call to g.cli.PullRequests.Get
        have (string, string, int)
        want ("context".Context, string, string, int)
./github.go:208: not enough arguments in call to g.cli.PullRequests.ListComments
        have (string, string, int, nil)
        want ("context".Context, string, string, int, *github.PullRequestListCommentsOptions)

can't install reviewdog command on Travis-ci

Errors when I try to install reviewdog command on travis-ci:

$ go get github.com/haya14busa/reviewdog/cmd/reviewdog
package github.com/haya14busa/reviewdog/cmd/reviewdog
	imports context: unrecognized import path "context"

The command "go get github.com/haya14busa/reviewdog/cmd/reviewdog" failed and exited with 1 during .

maybe, it's cause that Golang version on travis-ci is 1.4 . (I'm using travis-ci for PHP project. so, i can't change golang version easily.)
ref. go-swagger/go-swagger#679

get diff returns 404 from GitHub API on private repo

I'm using reviewdog on an open source project and it works great. I'm trying to run it now on a private repo and it isn't working. I'm running on CircleCI and I have REVIEWDOG_GITHUB_API_TOKEN set. I verified that the api token user is a collaborator on the private repo. Is reviewdog using the api token when it accesses the diff?

#!/bin/bash -eo pipefail
go tool vet -all -shadowstrict . 2>&1 | reviewdog -f=govet -ci="circle-ci"
reviewdog: fail to get diff: GET https://api.github.com/repos/my/repo/pulls/268: 404 Not Found []
Exited with code 1

Comment when file is generally modified/added/deleted

I have a use case where I'd like to make a comment to the reviewer as soon as an RPC data structure is modified. Essentially I want to ask if the deploy of the microservice is backwards compatible. In the best of worlds I'll implement an AST for Java parsing the source code and adding a warning by each field. That said, right now I'd happily just add a comment as soon as an RPC class file changes.

Question: In the readme all error formats contain a line. Is it possible to simply add a generic warning for a whole file (and warn if the file changes)? Any other approach? Is reviewdog the right tool for this?

-reporter=github-pr-review doesn't work on private repo

We have reviewdog working with github-pr-review on our public repos, but it isn't working on our private repo. It is running in CircleCI and it shows that it is exiting with a golint suggestion, but then the review never posts to the PR. The personal token has all repo permissions and is only in use by reviewdog, which shows recent usage, so the token is being used at some point. Do you have any suggestions on how to debug this further?

PS. I'd prefer to run github-pr-check, but that is overly backed up on your personal server at this point. Is this something easily self-hosted and registered ourselves through GitHub apps?

cc @josephbergevin

Doghouse server is broken after Github API changes

I am trying to run golint on a subdirectory in my repo using this command:

golint -set_exit_status ./pkg/... | reviewdog -f=golint -diff="git diff origin/master" -reporter=github-pr-check

But it is giving me a 422 Invalid request error - along with the message: "annotation_level", "path" weren't supplied. []

I can get this to run successfully by changing my command to this:

cd pkg && golint -set_exit_status ./... | reviewdog -f=golint -diff="git diff origin/master" -reporter=github-pr-check

But then the links referenced in the errors don't include the pkg folder, so they don't work.

I there a reviewdog flag I need to include to be able to make one of the above run commands work properly?

Support Pull Request Reviews for GitHub Enterprise

Hello, haya14busa! Thanks for this great tool!

I can see in the code that reviewdog knows how to post comments in one big review but the behavior is disabled for Enterprise users. From what I can tell the Enterprise API now supports reviews. Can we get that feature enabled?

ProjectConf: support files/directories/etc... based run

cont #47

With #47, reviewdog behavior can be configured by reviewdog.yml.
However, we cannot specify changed files, directories, or whatever with reviewdog.yml.

Example without reviewdog.yml:

$ vint $(git diff --name-only master | grep '.vim') | reviewdog -diff="git diff master" -efm="%f:%l:%c: %m"
autoload/vital/__vital__/Data/String.vim:9:11: Prefer single quoted strings (see Google VimScript Style Guide (Strings))

[Propose] Support of .netrc file

Some CI systems use .netrc file to authenticate to Github, and allowing reviewdog to use it reduces the trouble of setting REVIEWDOG_GITHUB_API_TOKEN variable.

I cannot truly get how the `diff` option works

My lint tool is outputting data in flycheck format:

lib/wallet_web/views/error_helpers.ex:13: F: Pipe chain should start with a raw value.

Which is pretty simple efm: %f:%l: %t: %m,%f:%l:%c: %t: %m (works perfectly in NeoVim). Additionally I have git diff output that contain:

diff --git a/lib/wallet_web/views/error_helpers.ex b/lib/wallet_web/views/error_helpers.ex
index ef43fe2..ed63698 100644
--- a/lib/wallet_web/views/error_helpers.ex
+++ b/lib/wallet_web/views/error_helpers.ex
@@ -9,7 +9,8 @@ defmodule WalletWeb.ErrorHelpers do
   Generates tag for inlined form input errors.
   """
   def error_tag(form, field) do
-    Enum.map(Keyword.get_values(form.errors, field), fn error ->
+    Keyword.get_values(form.errors, field)
+    |> Enum.map(fn error ->
       content_tag(:span, translate_error(error), class: "help-block")
     end)
   end

So as you can see, the 13 line in file lib/wallet_web/views/error_helpers.ex has changed and is the added one.

So why reviewdog -diff="git diff" results with no data? Is there anything wrong with my setup?

runner:
  credo:
    cmd: mix credo suggest --format=flycheck
    errorformat:
      - '%f:%l:%c: %t: %m'
      - '%f:%l: %t: %m'

Is there any option to see the filtered out lines and reason why that line was filtered out?


Tested with precompiled binaries for 0.9.11 (which reports 0.9.10 when reviewdog -version by the way) and with current HEAD (ffb00ef).

-reporter=github-pr-check doesn't work for private repo?

failed to run checker: fail to parse diff: GET https://api.github.com/repos/xxx/xxx/pulls/xxx: 403 Resource not accessible by integration []

reviewdog doesn't have necessary permission? It has read permission of pull requests, so i wonder why...

go get failed unless GO111MODULE=on

This is expected behavior?

% go version
go version go1.12.4 darwin/amd64

% go get -u github.com/reviewdog/reviewdog/cmd/reviewdog
package github.com/google/go-github/v24/github: cannot find package "github.com/google/go-github/v24/github" in any of:
        /usr/local/Cellar/go/1.12.4/libexec/src/github.com/google/go-github/v24/github (from $GOROOT)
        /Users/hamakn/dev/src/github.com/google/go-github/v24/github (from $GOPATH)

% GO111MODULE=on go get -u github.com/reviewdog/reviewdog/cmd/reviewdog
// OK if there is no Gopkg.lock

[Bug] using `map` in a concurrent job is unsafe.

Overview

The function Run in project.go accesses map in concurrent jobs in an errgroup closure.
But it sometimes causes fatal error: concurrent map writes .

Detail

When I try to run reviewdog -reporter=local -diff="git diff master" command in a remote CI job (in CircleCI), I came across the error.
An environment where it uses Go (>=1.6) randomly causes fatal error: concurrent map writes, if you try to insert values to map in concurrent processes.
The cause of a panic is them.
https://github.com/haya14busa/reviewdog/blob/master/project/run.go#L19
https://github.com/haya14busa/reviewdog/blob/master/project/run.go#L52

And stacktrace is as follows.

#!/bin/bash -eo pipefail
reviewdog -reporter=local -diff="git diff master"
fatal error: concurrent map writes

goroutine 8 [running]:
runtime.throw(0x7ac15b, 0x15)
	/usr/local/go/src/runtime/panic.go:617 +0x72 fp=0xc000178e40 sp=0xc000178e10 pc=0x42d312
runtime.mapassign_faststr(0x7341a0, 0xc0000137a0, 0xc00001a878, 0x8, 0x0)
	/usr/local/go/src/runtime/map_faststr.go:211 +0x42a fp=0xc000178ea8 sp=0xc000178e40 pc=0x41420a
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:52 +0x2a3 fp=0xc000178f88 sp=0xc000178ea8 pc=0x6d9c73
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0a50)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57 fp=0xc000178fd0 sp=0xc000178f88 pc=0x677377
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000178fd8 sp=0xc000178fd0 pc=0x458d51
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 1 [runnable]:
regexp.onePassPrefix(0xc000180a50, 0xc000138990, 0x0, 0x0)
	/usr/local/go/src/regexp/onepass.go:40 +0x20d
regexp.compile(0xc00001bb68, 0x4, 0xd4, 0x40, 0xc00001bb68, 0x4)
	/usr/local/go/src/regexp/regexp.go:198 +0x1e9
regexp.Compile(...)
	/usr/local/go/src/regexp/regexp.go:131
github.com/haya14busa/errorformat.NewEfm(0x7a7193, 0x7, 0xc000091a40, 0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:498 +0x94a
github.com/haya14busa/errorformat.NewErrorformat(0xc00000e380, 0x2, 0x2, 0x8123e0, 0xc0001341a8, 0x50)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:38 +0xcc
github.com/haya14busa/reviewdog.NewErrorformatParserString(0xc00000e380, 0x2, 0x2, 0x5, 0xc000134228, 0x1)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:60 +0x43
github.com/haya14busa/reviewdog.NewParser(0xc0000efbb0, 0x8123e0, 0x0, 0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:42 +0xfe
github.com/haya14busa/reviewdog/project.RunAndParse(0x821220, 0xc00001a068, 0xc000010058, 0xc000010058, 0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:32 +0x1f6
github.com/haya14busa/reviewdog/project.Run(0x821220, 0xc00001a068, 0xc000010058, 0x81aca0, 0xc000090d50, 0x81da00, 0xc0000d0410, 0x789901, 0xc0000cd790)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:64 +0x5d
main.run(0x81b140, 0xc000010010, 0x81b160, 0xc000010018, 0xa54aa0, 0x0, 0xc0000200b8)
	/go/pkg/mod/github.com/haya14busa/[email protected]/cmd/reviewdog/main.go:248 +0x3c6
main.main()
	/go/pkg/mod/github.com/haya14busa/[email protected]/cmd/reviewdog/main.go:139 +0xd2

goroutine 5 [select]:
os/exec.(*Cmd).Start.func2(0xc00010a840)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 7 [select]:
os/exec.(*Cmd).Start.func2(0xc00010a9a0)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 9 [select]:
os/exec.(*Cmd).Start.func2(0xc00010ab00)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 10 [IO wait]:
internal/poll.runtime_pollWait(0x7fa97b19fb88, 0x72, 0xffffffffffffffff)
	/usr/local/go/src/runtime/netpoll.go:182 +0x56
internal/poll.(*pollDesc).wait(0xc0000a7038, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x9b
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0000a7020, 0xc00017d000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:169 +0x19b
os.(*File).read(...)
	/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc0000101c8, 0xc00017d000, 0x1000, 0x1000, 0xc000078488, 0x4426ec, 0x1000)
	/usr/local/go/src/os/file.go:108 +0x70
io.(*multiReader).Read(0xc00016e060, 0xc00017d000, 0x1000, 0x1000, 0x0, 0xc000172070, 0x0)
	/usr/local/go/src/io/multi.go:26 +0xac
bufio.(*Scanner).Scan(0xc000170080, 0x0)
	/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/haya14busa/errorformat.(*Scanner).Scan(0xc000179e70, 0xc000172070)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:167 +0x33
github.com/haya14busa/reviewdog.(*ErrorformatParser).Parse(0xc0000101c0, 0x81ae80, 0xc00016e060, 0x2, 0xc000078758, 0x2, 0x2, 0x2)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:70 +0x121
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:48 +0x238
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0b40)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 11 [select]:
os/exec.(*Cmd).Start.func2(0xc00010ac60)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 12 [IO wait]:
internal/poll.runtime_pollWait(0x7fa97b19f9e8, 0x72, 0xffffffffffffffff)
	/usr/local/go/src/runtime/netpoll.go:182 +0x56
internal/poll.(*pollDesc).wait(0xc0000a7278, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x9b
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0000a7260, 0xc000194000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:169 +0x19b
os.(*File).read(...)
	/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc000010210, 0xc000194000, 0x1000, 0x1000, 0xc00017bc88, 0x4426ec, 0x1000)
	/usr/local/go/src/os/file.go:108 +0x70
io.(*multiReader).Read(0xc00016e0a0, 0xc000194000, 0x1000, 0x1000, 0x0, 0xc0001720e0, 0x0)
	/usr/local/go/src/io/multi.go:26 +0xac
bufio.(*Scanner).Scan(0xc000170100, 0x0)
	/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/haya14busa/errorformat.(*Scanner).Scan(0xc00017be70, 0xc0001720e0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:167 +0x33
github.com/haya14busa/reviewdog.(*ErrorformatParser).Parse(0xc000010208, 0x81ae80, 0xc00016e0a0, 0x2, 0xc000079758, 0x2, 0x2, 0x2)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:70 +0x121
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:48 +0x238
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0c30)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 13 [select]:
os/exec.(*Cmd).Start.func2(0xc00010adc0)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 14 [IO wait]:
internal/poll.runtime_pollWait(0x7fa97b19f848, 0x72, 0xffffffffffffffff)
	/usr/local/go/src/runtime/netpoll.go:182 +0x56
internal/poll.(*pollDesc).wait(0xc0000a74b8, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x9b
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0000a74a0, 0xc000169000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:169 +0x19b
os.(*File).read(...)
	/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc000010258, 0xc000169000, 0x1000, 0x1000, 0xc00007a488, 0x4426ec, 0x1000)
	/usr/local/go/src/os/file.go:108 +0x70
io.(*multiReader).Read(0xc000162060, 0xc000169000, 0x1000, 0x1000, 0x0, 0xc000166070, 0x0)
	/usr/local/go/src/io/multi.go:26 +0xac
bufio.(*Scanner).Scan(0xc000164080, 0x0)
	/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/haya14busa/errorformat.(*Scanner).Scan(0xc00008ae70, 0xc000166070)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:167 +0x33
github.com/haya14busa/reviewdog.(*ErrorformatParser).Parse(0xc000010250, 0x81ae80, 0xc000162060, 0x2, 0xc00007a758, 0x2, 0x2, 0x2)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:70 +0x121
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:48 +0x238
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0d20)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 15 [select]:
os/exec.(*Cmd).Start.func2(0xc00010af20)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 16 [IO wait]:
internal/poll.runtime_pollWait(0x7fa97b19f6a8, 0x72, 0xffffffffffffffff)
	/usr/local/go/src/runtime/netpoll.go:182 +0x56
internal/poll.(*pollDesc).wait(0xc0000a76f8, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x9b
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0000a76e0, 0xc00019a000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:169 +0x19b
os.(*File).read(...)
	/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc0000102a0, 0xc00019a000, 0x1000, 0x1000, 0xc00008bc88, 0x4426ec, 0x1000)
	/usr/local/go/src/os/file.go:108 +0x70
io.(*multiReader).Read(0xc0001620a0, 0xc00019a000, 0x1000, 0x1000, 0x0, 0xc0001660e0, 0x0)
	/usr/local/go/src/io/multi.go:26 +0xac
bufio.(*Scanner).Scan(0xc000164100, 0x0)
	/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/haya14busa/errorformat.(*Scanner).Scan(0xc00008be70, 0xc0001660e0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:167 +0x33
github.com/haya14busa/reviewdog.(*ErrorformatParser).Parse(0xc000010298, 0x81ae80, 0xc0001620a0, 0x2, 0xc00007b758, 0x2, 0x2, 0x2)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:70 +0x121
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:48 +0x238
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0e10)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 18 [select]:
os/exec.(*Cmd).Start.func2(0xc00010b080)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 19 [IO wait]:
internal/poll.runtime_pollWait(0x7fa97b19f508, 0x72, 0xffffffffffffffff)
	/usr/local/go/src/runtime/netpoll.go:182 +0x56
internal/poll.(*pollDesc).wait(0xc0000a7938, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x9b
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0000a7920, 0xc000195000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:169 +0x19b
os.(*File).read(...)
	/usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc0000102e8, 0xc000195000, 0x1000, 0x1000, 0xc0001a0488, 0x4426ec, 0x1000)
	/usr/local/go/src/os/file.go:108 +0x70
io.(*multiReader).Read(0xc00016e0e0, 0xc000195000, 0x1000, 0x1000, 0x0, 0xc000172150, 0x0)
	/usr/local/go/src/io/multi.go:26 +0xac
bufio.(*Scanner).Scan(0xc000170180, 0x0)
	/usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/haya14busa/errorformat.(*Scanner).Scan(0xc000174e70, 0xc000172150)
	/go/pkg/mod/github.com/haya14busa/[email protected]/errorformat.go:167 +0x33
github.com/haya14busa/reviewdog.(*ErrorformatParser).Parse(0xc0000102e0, 0x81ae80, 0xc00016e0e0, 0x2, 0xc0001a0758, 0x2, 0x2, 0x2)
	/go/pkg/mod/github.com/haya14busa/[email protected]/parser.go:70 +0x121
github.com/haya14busa/reviewdog/project.RunAndParse.func1(0x0, 0x0)
	/go/pkg/mod/github.com/haya14busa/[email protected]/project/run.go:48 +0x238
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0f00)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x57
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

goroutine 20 [runnable]:
os/exec.(*Cmd).Start.func2(0xc00010b1e0)
	/usr/local/go/src/os/exec/exec.go:416 +0xc4
created by os/exec.(*Cmd).Start
	/usr/local/go/src/os/exec/exec.go:415 +0x62d

goroutine 21 [runnable]:
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0000137d0, 0xc0000d0ff0)
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54
created by golang.org/x/sync/errgroup.(*Group).Go
	/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66
Exited with code 2

Environment

go version: 1.11
reviewdog version: 0.9.11
docker image: circleci/golang:1.11

Github check for private repo on Travis CI fails due to `403 Forbidden` error

Running the latest 0.9.9 release through the new Github app integration check. However, reviewdog fails with the following:

reviewdog: status=400: fail to parse diff: GET https://api.github.com/repos/{owner}/{repo}/pulls/123:
403 Resource not accessible by integration []

The command I'm running is:

$ ./bin/reviewdog -version
0.9.9

$ ./bin/rubocop --config .rubocop.yml --rails | ./bin/reviewdog -f=rubocop -reporter=github-pr-check
reviewdog: status=400: fail to parse diff: GET https://api.github.com/repos/{owner}/{repo}/pulls/123:
403 Resource not accessible by integration []

I've tried this both with the REVIEWDOG_TOKEN set and unset. Same error both times.

If it helps, here's what Github shows the app config as:

image

Parsers should be able to return results for multiple tools

Golang CI is a great tool, collecting a number of Go linting tools in one binary. It is capable of outputting a checkstyle format (and a custom json format as well) which can contain the actual linter which raised an issue.

It would be nice, if the actual tool could be detected by the parser itself.

Looking for maintainers

The maintenance of this project seems to be stopped.

@haya14busa If you have enough time for maintenance, I'm going to support you.
What do you think about moving the reviewdog repository to an organization?

git merge-base fails in Jenkins Multi-branch workspace when branch becomes not ff-mergable

reviewdog get diffs using git merge-base, but in Jenkins multi-branch workspace, this fails in some condition (and I think reviewdog can do nothing about it...).

Situation

Jenkins multi-branch plugin fetches only target branch by following git fetch, which only obtains target branch's change.

git fetch --no-tags --progress git@myserver:myrepository.git +refs/heads/MyBranch:refs/remotes/origin/MyBranch

And reviewdog determines base commit using github pull request api.

In following situation the base commit obtained by github api does not exist in workspace, therefore git merge-base fails.

  • MyBranch, which is ff-mergable to BaseBranch is pushed to Jenkins
    • at this time, BaseBranch's HEAD is exists in workspace so reviewdog can work properly
  • Some new commit is added to BaseBranch
  • MyBranch is pushed again
    • at this time, MyBranch is not ff-mergable to BaseBranch
    • jenkins only obtains changes in MyBranch by git fetch, so new commits in BaseBranch does not exist in this workspace
    • reviewdog tries to git merge-base, but fails because HEAD of BaseBranch does not exist in the workspace.

Possible solution

I think reviewdog can do nothing about it ๐Ÿ˜ญ
Jenkins, or users should call git fetch BaseBranch before calling reviewdog.

Running a private reviewdog server

I'd like to be able to run a private reviewdog server, so that we can use the github-pr-check reporter against GitHub Enterprise. Do you have the source code and/or any documentation on the server?

GitHub: cannot use diff provided by GitHub

I reported below message to GitHub support


application/vnd.github.v3.diff media type is not usable for creating a PullRequest comment to PullRequest with file renames.

Document: https://developer.github.com/v3/pulls/comments/#create-a-comment

To comment on a specific line in a file, you will need to first determine the
position in the diff. GitHub offers a application/vnd.github.v3.diff media
type which you can use in a preceding request to view the pull request's
diff.

Document says that we can get a pull request diff to determin the position in the diff with application/vnd.github.v3.diff media type.
However, diff is not support git diff --find-renames, so we cannot use the diff to determin the position if pull request contains rename file change.

$ curl -H "Accept: application/vnd.github.v3.diff" 'https://api.github.com/repos/haya14busa/reviewdog/pulls/17' > pr17.diff

pr17.diff content is here. https://github.com/haya14busa/reviewdog/pull/17/files#diff-3f1590a5a42dea59fdf7dc68dbcf112c

I'm sorry, but it's not minimum reproducible pull-request, but please see below.

diff --git a/watchdogs.go b/watchdogs.go
deleted file mode 100644
index a1dd247..0000000
--- a/watchdogs.go
+++ /dev/null

https://gist.github.com/haya14busa/d3be48dba9d12e91c60b9a5d711da9b5#file-pr17-diff-L2000-L2004

diff --git a/reviewdog.go b/reviewdog.go
new file mode 100644
index 0000000..ae92e5e
--- /dev/null
+++ b/reviewdog.go

https://gist.github.com/haya14busa/d3be48dba9d12e91c60b9a5d711da9b5#file-pr17-diff-L1719-L1723

In files view (https://github.com/haya14busa/reviewdog/pull/17/files#diff-3f1590a5a42dea59fdf7dc68dbcf112cL1),
this change is handles as watchdogs.go -> reviewdog.go, but diff shows a/watchdogs.go -> /dev/null and /dev/null -> b/reviewdog.go.

So, we cannot determine the position in renamed files because hunk information (@@) is completely lost.

Please add --find-renames equivalent support to application/vnd.github.v3.diff.
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.