reviewdog / reviewdog

🐶 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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub Pull Request diff API responds with 406 — diff too large

reidab opened this issue · comments

We've started seeing several of our GitHub actions builds with reviewdog fail this morning because the GitHub API is returning a 406 error code on diffs larger than 3,000 lines. This seems to be new GitHub API behavior because the same version of reviewdog worked was passing on these same PRs three days ago.

The error message currently has no relevant Google results. Searching around on GitHub, I only find one mention of Code:too_large with field: diff anywhere, and it's from another reviewdog user today: platformsh/platformsh-docs#3885 (comment)

We've seen this both when running from actions like https://github.com/reviewdog/action-brakeman and from custom actions that invoke reviewdog manually.

An example reviewdog error when running with reviewdog -name=Hadolint -reporter=github-check -efm='%f:%l %m' -level=warning:

reviewdog: post failed for Hadolint: fail to parse diff: 
GET https://api.github.com/repos/thedyrt/<redacted>/pulls/<redacted>: 
406 Sorry, the diff exceeded the maximum number of lines (3000)
 [{Resource:PullRequest Field:diff Code:too_large Message:}]

The API response from GitHub:

{
  "message": "Sorry, the diff exceeded the maximum number of lines (3000)",
  "errors": [
    {
      "resource": "PullRequest",
      "field": "diff",
      "code": "too_large"
    }
  ],
  "documentation_url": "https://docs.github.com/rest/pulls/pulls#get-a-pull-request"
}

Seeing similar issues with PRs with lots of files. We have an automation to sync assets from designers and it had around 1200 files changed. Failed in the same way but with a different message about to many files.

Hi @haya14busa ,

Encountering the same issue as #1696 with the reviewdog action failing due to GitHub's new diff size limit. This is impacting our large PR workflows severely. Any known workarounds or planned updates to address this?

Appreciate your efforts on reviewdog.

Thanks.

Hi @reidab @chrisdp Did you find any workaround for this issue?

Does anyone provide feedback to GitHub?

No work around yet. Might have to remove reviewdog from our flows if some solution isn't found.

https://github.com/massongit/action-golangci-lint/actions/runs/8465852986/job/23193377688?pr=2

  reviewdog: post failed for golangci: fail to parse diff: GET https://api.github.com/repos/massongit/action-golangci-lint/pulls/2: 406 Sorry, the diff exceeded the maximum number of files (300). Consider using 'List pull requests files' API or locally cloning the repository instead. [{Resource:PullRequest Field:diff Code:too_large Message:}]

If your pull requests have a large number of files as above, you may be able to use the list pull requests files API ( https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files ) instead of the get a pull request API.

It seems possible to work around this using the PR files API in many cases, but it's not a drop-in replacement. The files JSON response still returns the patch text, but it's not in the same multi-file format that the other endpoint returns. The docs claim that the files API can return results in the same application/vnd.github.diff format as the base PR API, but this doesn't seem to actually work. Setting Accept: application/vnd.github.diff still seems to return JSON. I have an inquiry in to GitHub support about whether this is a bug or if the docs are wrong.

Is there a reason that we need to be fetching this diff from GitHub instead of just using git to generate it locally from the repo? Is there an existing DiffService that already does this that we could use as fallback?

This hasn't resolved the issue for us in GitHub Actions.

time=2024-04-16T17:24:53.361Z level=INFO msg="fallback to use git command"
reviewdog: fail to get diff: failed to get merge-base commit: exit status 128

I'm guessing this has something to do with the shallow clone it does at checkout. Do we need to fetch head with git beforehand?

/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +71ca3938e27ea342224c721a0bfdd16db4e908d6:refs/remotes/pull/4248/merge

This hasn't resolved the issue for us in GitHub Actions.


time=2024-04-16T17:24:53.361Z level=INFO msg="fallback to use git command"

reviewdog: fail to get diff: failed to get merge-base commit: exit status 128

I'm guessing this has something to do with the shallow clone it does at checkout. Do we need to fetch head with git beforehand?

/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +71ca3938e27ea342224c721a0bfdd16db4e908d6:refs/remotes/pull/4248/merge

Same here. After the patch we started to face this other issue.

In our case we had to adjust the Git checkout command in our GitHub action job to use a fetch depth of 0 (as opposed to the default of 1).

While setting fetch-depth: 0 did solve this specific issue, it caused other problems like running out of disk space, taking 10 minutes to clone, etc. It's also not ideal that every GitHub user will have to update their checkout rather than this fallback working by default.

I'm not a git expert, but it seems that if we did a fetch like this, using GitHub default env vars, the necessary branch would be available for the subsequent git merge-base command. Thoughts?

/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 $GITHUB_HEAD_REF

https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

Do the related actions need bumping ?

eg. reviewdog/action-shellcheck etc?

@dprotaso it seems that some are on the right version https://github.com/reviewdog/action-yamllint/blob/master/Dockerfile#L3, others not https://github.com/reviewdog/action-shellcheck/blob/master/action.yml#L63.
Even with 0.17.4 it seems things are not fixed for us, probably hitting the repository limits (20K lines).

@massongit thanks for the two PRs! It's working great for us now

Yeah it's still happening - do folks have any suggestions here?

reviewdog: post failed for woke: fail to parse diff: GET https://api.github.com/repos/knative/serving/pulls/15066: 406 Sorry, the diff exceeded the maximum number of lines (20000) [{Resource:PullRequest Field:diff Code:too_large Message:}]

Currently, this issue is only resolved when the reporter is github-pr-review.
Therefore, I think that github-check, github-pr-check and github-pr-annotations also need to be resolved.

We unfortunatley saw the error again today.

reviewdog: post failed for Cspell: fail to parse diff: GET https://api.github.com/repos/MyOrg/my-repo/pulls/327: 406 Sorry, the diff exceeded the maximum number of files (300). Consider using 'List pull requests files' API or locally cloning the repository instead. [{Resource:PullRequest Field:diff Code:too_large Message:}]

We call reviewdog with:

reviewdog -conf=.reviewdog.yml -reporter=github-pr-check -tee -runners=Rubocop,Brakeman,Cspell -fail-on-error=true