Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
reidab opened this issue Mar 25, 2024 · 16 comments · Fixed by #1697 or #1714 · May be fixed by #1722
Open

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

reidab opened this issue Mar 25, 2024 · 16 comments · Fixed by #1697 or #1714 · May be fixed by #1722

Comments

@reidab
Copy link

reidab commented Mar 25, 2024

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"
}
@chrisdp
Copy link

chrisdp commented Mar 25, 2024

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.

@atiqueakhtar
Copy link

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.

@atiqueakhtar
Copy link

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

@danielrbradley
Copy link

@haya14busa
Copy link
Member

Does anyone provide feedback to GitHub?

@chrisdp
Copy link

chrisdp commented Mar 28, 2024

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

@massongit
Copy link
Contributor

massongit commented Mar 29, 2024

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.

@reidab
Copy link
Author

reidab commented Mar 30, 2024

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?

@derekperkins
Copy link

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

@dannyskoog
Copy link

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

@derekperkins
Copy link

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

@dprotaso
Copy link

Do the related actions need bumping ?

eg. reviewdog/action-shellcheck etc?

@skonto
Copy link

skonto commented Apr 24, 2024

@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).

@derekperkins
Copy link

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

@dprotaso
Copy link

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:}]

@massongit massongit reopened this Apr 25, 2024
@massongit
Copy link
Contributor

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.

mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this issue May 5, 2024
 - [x] depends on: reviewdog/action-suggester#52


This reverts #12280 after the upstream fix
 reviewdog/reviewdog#1696
has propagated to reviewdog/action-suggester@v1. This should happen when 
https://github.com/reviewdog/action-suggester/releases
has a release that uses [v0.17.4](https://github.com/reviewdog/reviewdog/releases/tag/v0.17.4) or higher.

When this happens, rebase this pull request and re-trigger to see that it doesn't fail with the 300 dummy files. Then remove the dummy files and merge this pull request.



Co-authored-by: Moritz Firsching <firsching@google.com>
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this issue May 5, 2024
 - [x] depends on: reviewdog/action-suggester#52


This reverts #12280 after the upstream fix
 reviewdog/reviewdog#1696
has propagated to reviewdog/action-suggester@v1. This should happen when 
https://github.com/reviewdog/action-suggester/releases
has a release that uses [v0.17.4](https://github.com/reviewdog/reviewdog/releases/tag/v0.17.4) or higher.

When this happens, rebase this pull request and re-trigger to see that it doesn't fail with the 300 dummy files. Then remove the dummy files and merge this pull request.



Co-authored-by: Moritz Firsching <firsching@google.com>
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this issue May 5, 2024
 - [x] depends on: reviewdog/action-suggester#52


This reverts #12280 after the upstream fix
 reviewdog/reviewdog#1696
has propagated to reviewdog/action-suggester@v1. This should happen when 
https://github.com/reviewdog/action-suggester/releases
has a release that uses [v0.17.4](https://github.com/reviewdog/reviewdog/releases/tag/v0.17.4) or higher.

When this happens, rebase this pull request and re-trigger to see that it doesn't fail with the 300 dummy files. Then remove the dummy files and merge this pull request.



Co-authored-by: Moritz Firsching <firsching@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment