Get pull request associated with a commit #24679
-
I was wondering if it’s possible to get a pull request associated with a commit. With a merge-commit or squash-merging I can infer the associated pull request from the commit message, but in the case of rebase-merging the commits are directly appended to the master branch which makes this impossible. It seems like GitHub has a way of associating commits that have been merged using rebase-merging as can be seen in the following screenshot (all appended commits show this): I’ve been digging through the V4 and V3 API but I couldn’t find a way to associate commits with a PR. Is this somehow possible? For more context: I’m currently working on supporting rebase-merging in Release Drafter (release-drafter/release-drafter#106). |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 1 reply
-
Hey @timonvs, Thanks for being here! This is a great question, you can do this using the search UI but I don’t think there is a way to do it programmatically via the API. I’ll dig a little dipper and post any updates here. Hopefully another user might have more insight into this question. |
Beta Was this translation helpful? Give feedback.
-
Thanks @andreagriffiths11. It’s indeed possible with the search API (https://help.github.com/articles/searching-issues-and-pull-requests/#search-by-commit-sha). For my use case however that would not work very well because I need be able to identify PRs from a bunch of commits. Doing a request for every commit would be very ineffecient and I’d quickly hit the API limits. Ideally I’d be able to do the following GraphQL query:
|
Beta Was this translation helpful? Give feedback.
-
@timonvs thanks for clarifying, I believe that schema is not supported yet, but has been requested. |
Beta Was this translation helpful? Give feedback.
-
I figured out how to do this using github3.py. It assumes you have cloned the repo locally.
|
Beta Was this translation helpful? Give feedback.
-
I was just randomly looking at the GraphQL API changelog and I saw that the |
Beta Was this translation helpful? Give feedback.
-
Here’s an example query which demonstrates how to fetch associated pull requests of the five latest commits on the master branch:
|
Beta Was this translation helpful? Give feedback.
-
Here is another example graphql query that takes a specific sha and outputs the associated PR’s:
|
Beta Was this translation helpful? Give feedback.
-
Thanks! precisely what I was looking for. So commits are abstracted behind GitObjects 🤭 |
Beta Was this translation helpful? Give feedback.
-
OrderByField issue @caleb15 @timonvs can you guys help me? |
Beta Was this translation helpful? Give feedback.
I was just randomly looking at the GraphQL API changelog and I saw that the
associatedPullRequests
field has recently been added (https://developer.github.com/v4/changelog/2019-03-08-schema-changes/) which resolves this issue. Thanks a lot @andreagriffiths11 🙏