Reputation: 5993
I am using Pygithub to trying to create a pull request.
# push branch
cmd = ["git", "push", "origin", "HEAD:refs/heads/my-branch"]
subprocess.run(cmd, check=True)
...
# then create PR
repo = client.get_repo(MY_GITHUB_REPO)
repo.create_pull(title=title, body=body, head=my-branch, base="master")
I got his Exception
github.GithubException.GithubException: 422 {"message": "Validation Failed", "errors":
[{"resource": "PullRequest", "code": "custom", "message": "not all refs are readable"}],
"documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-pull-request"}
I checked the branch exist on Github but I am getting this exception.
I tried to run a git fetch origin
before the repo.create_pull()
but the error persisted. I am not sure how to get around this.
Upvotes: 2
Views: 2780
Reputation: 1489
Ensure you have enabled read access to "Contents" in your application's settings:
Or, if you are using one, within your "fine-grained" personal access token settings:
Upvotes: 6
Reputation: 1
422 Unprocessable Entity indicates missing_field A required field on a resource has not been set. https://docs.github.com/en/rest/overview/resources-in-the-rest-api#client-errors
or like this issue explains you're pushing to a ref that we use just for the PR metadata. That's also the reason you didn't get a permission denied area, since the PR ref is in the repo you have access to, even though the branch the PR is based on isn't.
https://github.com/isaacs/github/issues/591
Upvotes: 0