GraphQL - Get all pull request for an organization

I can get the pull request for a repository. I can list all the repository for an organization too. But is there a direct way to get last 100 Pull Request across all repositories in an organization.

Here is what i have, is there a better way to write this? I will also like to skip the repositories which are archived, or which dont have any pull request. But the below script shows all the repositories and all pull request.

{
organization(login: “MyOrg”) {
        repositories{
           nodes {
              name
                 pullRequests(last: 25) {
                   nodes {
                       id
                      title
                      createdAt
               }
             }
           }
         }
      }
}

I do have an open question on How to filter Pull Request for a date e.g. list all pull request open since 1st April 2019.

Will appriciate any pointers.

I don’t know of a way to do this directly by the series of objects you’re using or something similar. What you could do though is list the last 100 PRs in an organization by using the search interface:

{
  search(query: "org:atom is:pr created:>2019-04-01", type: ISSUE, last: 100) {
    edges {
      node {
        ... on PullRequest {
          url
          title
          createdAt
        }
      }
    }
  }
}

As you can see, the search query is org:atom is:pr created:\>2019-04-01. Since the type is ISSUE, this is saying that you want all PRs (is:pr) in the Atom organization (org:atom) created later than midnight on April 1st.

I hope that helps!

2 Likes

Adding on to this, is there a way to additionally filter by certain repos within that organization? Thanks for the search query suggestion!

The search query syntax is the same as is used on the website, so feel free to experiment with the search box on the main github.com page. I quickly came up with this syntax that lists only PRs in atom/atom and atom/github: is:pr created:\>2019-04-01 repo:atom/atom repo:atom/github

1 Like