Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

Get pull request that was just merged?

Hi,
I'm trying to use GraphQL API to search for a Pull Request that was just merged to base branch (master). I am trying to figure out what's the best way to do this, but I wanted to try to search the Pull Request by its merge commit SHA. I already have the latest commit from master, and I want to find the Pull Request that has the same commit.

I'm still new to GraphQL but this is what I tried so far:

{
repository(owner: "octocat", name: "Hello-World") {
pullRequests(states: MERGED, first: 1, mergeCommit: "$sha", baseRefName: "master") {
edges {
node {
title
body
}
}
}
}
}


I'm getting this error: Field 'pullRequests' doesn't accept argument 'mergeCommit'. Not sure what the right syntax for this is.

1 Reply
Community Manager
Message 2 of 2

Re: Get pull request that was just merged?

If you look at the documentation for the `Repository.pullRequests` connection, there isn't a `mergeCommit` filter. So you'll have to query all the pull requests and filter them yourself by the merge commit SHA. Of course, if you're only looking for the one that was "just merged" you could order them by updated time and only look at the most recent one or so.

 

I hope that helps!