PyGithub / PyGithub/PyGithub

404 Git diff of pull request

Open
#2,768 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
1.9k
Avg merge
17m
Merged PRs (30d)
2

Description

I have Github App installed on my private testing repository.
I am trying to get the actual git diff content of a pull request (not just the url).
If I access the diff endpoint in my browser, I get the expected output, so the endpoint, which pr.diff_url provides is correct. Important note is that when I access it from the browser, there is a token parameter added.

here is my authentication process:

auth = github.Auth.AppAuth(app_id, app_key)
gi = github.GithubIntegration(auth=auth)
installation_id = vars.private_repo_installation_id
try:
    installation = gi.get_app_installation(installation_id)
except Exception as e:
    print("Installation not found.")
    exit()
g = installation.get_github_for_installation()
repo = g.get_repo(<repo-name>)
pr = repo.get_pull(<pr-number>)

then, using the requests library:

response = requests.get(pr.diff_url)
if response.status_code == 200:
    diff_content = response.text
else:
    print(f"Failed to fetch diff content. Status code: {response.status_code}")

For public repos, it works fine, but for private repositories, I get status code 404.
I assumed it was the lack of authentication (although the status code is 404, not 403 or 401)
so I added:

headers = {"Authorization": f"token {gi.get_access_token(installation_id)}"}

and later in the request:

response = requests.get(pr.diff_url, headers=headers)

yet the 404 persists.

but I am unsure how to use it, couldn't find any examples in the documentation. The following code still encounters 404 error:

token = gi.get_access_token(installation_id)
token = token.token
url = pr.diff_url + '?token=' + token
response = requests.get(url)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the private-repository case using the shown GitHub App authentication flow, then inspect how pr.diff_url and installation access tokens are handled. Done means identifying why the authenticated request returns 404 and documenting or correcting the supported way to retrieve the pull request diff content.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.