Using apiv4, can I get all PRs that have been merged into a branch?

Using the following query, I can get all PRs that have been merged *from* my branch into other branches:

{
organization(login: "MyOrg") {
   repository(name: "MyRepo") {
      ref(qualifiedName: "refs/heads/MyBranch") {
        associatedPullRequests(first:10) {
edges {
node {
id
}
}
}
    }
  }
}

which is not very useful to me. I have tried to get all refs and get the associatedPullRequests from all refs with myBranch as the baseName, however I have far too many refs for this work and I really want the most recently created PRs. As far as I know there is no way to sort head refs by creation date/last commit date, so I am stuck

Turns out the solution was simple… just use pullRequests instead of associatedPullRequests

{
organization(login: "MyOrg") {
  repository(name: "MyRepo") {
    pullRequests(baseRefName:"MyBranch") {
      nodes{
        title
          }
        }
      }
    }
  }
}
1 Like