go-github icon indicating copy to clipboard operation
go-github copied to clipboard

Unable to create pull request

Open Nyxonios opened this issue 4 years ago • 2 comments

Hello! So I use multi-gitter which allows me to run scripts to make changes and create PRs over multiple repositories. However, I noticed that I received errors due to some problems in this library (which multi-gitter uses).

Context I am doing the changes on a GitHub enterprise instance. So, I run a script to update dependencies in multiple repositories and then create a PR in each repository with these changes. However, when the PR is to be created, the following error occurs:

json: cannot unmarshal array into Go value of type github.PullRequest

I can see that the issue originates here: https://github.com/google/go-github/blob/master/github/pulls.go#L255-L272

I can see that what we actually get back is a response from the GET repos/<ORG>/<REPO>/pulls endpoint and not the POST repos/<ORG>/<REPO>/pulls. I added the https://github.com/gmlewis/go-httpdebug/ to the transport to get the corresponding CURL commands, and indeed it looks like we are doing 2 equivalent curl requests, this is the output from this debug:

2022/07/01 10:46:31 curl -X POST \
  http://<GITHUB_ENTERPRISE_INSTANCE>/api/v3/repos/<ORG>/<REPO>/pulls \
  -H 'Accept: application/vnd.github.v3+json' \
  -H 'Authorization: <REDACTED>' \
  -H 'Content-Type: application/json' \
  -H 'User-Agent: go-github' \
  -d '{"title":"Upgraded dependencies and go version","head":"<BASE>","base":"master","body":"","draft":false}
'
2022/07/01 10:46:32 curl -X GET \
  http://<GITHUB_ENTERPRISE_INSTANCE>/api/v3/repos/<ORG>/<REPO>/pulls \
  -H 'Accept: application/vnd.github.v3+json' \
  -H 'Authorization: <REDACTED>' \
  -H 'Content-Type: application/json' \
  -H 'Referer: http://github.schibsted.io/api/v3/repos/<ORG>/<REPO>/pulls' \
  -H 'User-Agent: go-github'

I can see that nothing else is run except the function Create (the above-linked function) and still we get these debug statements.

So, because of some to me unknown reason, we are calling (or doing the curl equivalent of calling): POST mhttp://<GITHUB_ENTERPRISE_INSTANCE>/api/v3/repos/<ORG>/<REPO>/pulls ... then GET http://<GITHUB_ENTERPRISE_INSTANCE>/api/v3/repos/<ORG>/<REPO>/pulls ... when we should only do the POST call.

I have tried this on the versions v35.2 and v45.2 and they produce the same output.

Nyxonios avatar Jul 01 '22 09:07 Nyxonios

Thank you for the report, @Mseller .

So the thing of great interest here is the response you get back from the curl -X POST... if you are indeed getting back an array of objects, then your version of GitHub Enterprise is not adhering to the official docs: https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request and you need to contact GitHub Enterprise Tech Support (which your company is obviously already paying for) and give them your version of GitHub Enterprise you are running, and ask them why you are getting back an array when you are supposed to be getting back an object.

Please report back here with their response and we can proceed from there.

gmlewis avatar Jul 01 '22 13:07 gmlewis

Closing due to inactivity.

gmlewis avatar Mar 17 '25 22:03 gmlewis