Home > Blockchain >  How to get the merge_method for a merged GitHub pull request
How to get the merge_method for a merged GitHub pull request

Time:12-07

I am trying determine the merge method applied to a GitHub pull request.

There is a merge_method attribute on the API for merging a PR.

https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request

But I do not see this available on the response for the GET

https://docs.github.com/en/rest/reference/pulls#get-a-pull-request

I'm not finding much about this anywhere, has anyone come up with a clever solution to compute this value? Or will it be added the API in the near future?

CodePudding user response:

GitHub doesn't store this information because the pull request can have been merged by means other than the merge button on a pull request.

For example, if I perform a manual merge of a PR and the main branch myself and then push the result to the main branch, that will close the pull request as merged, since the main branch now includes the head of the pull request. This is also true if I do a fast forward merge, which might be the behavior done by a rebase through the web interface.

You can even close a pull request for branch A by merging it into branch B and then merging branch B into the main branch, using the web interface, the API, or otherwise. GitHub uses this technique for its deployment trains, where B is a train and A is a normal feature branch.

Essentially, any time the main branch is updated to include the head of the feature branch in a pull request, that pull request is considered merged. The exception is squash merges, where this doesn't happen, which are treated specially. So there's no guaranteed way to find out this information.

  • Related