Get all pull requests for an org

community-help

#1

I’m attempting to get a query working that gets all pull requests across an organization. I’ve so far put the following together, but what really confuses me is how to properly query pages/cursors. I’ve provided two sets of cursors, one for repos and the other for pull requests. What’s the correct order of querying?

My thought was:

  1. Init query
  2. Query all PR cursors until none are left
  3. Query repo cursor, loop back to step 2 until none are left

This is really slow, and just ends up getting rate limited anyway. So I feel I must be going about this completely wrong. Is there a better approach?

query OrgPRs($org: String!, $repoCursor: String, $prCursor: String) {
  organization(login: $org) {
    repositories(first: 10, after: $repoCursor, isLocked: false, isFork: false, orderBy: {field: UPDATED_AT, direction: DESC}) {
      pageInfo {
        hasNextPage
        endCursor
      }
      edges {
        node {
          pullRequests(first: 100, after: $prCursor, orderBy: {field: CREATED_AT, direction: DESC}) {
            pageInfo {
              hasNextPage
              endCursor
            }
            edges {
              node {
                resourcePath
                number
                title
                body
                createdAt
                mergedAt
                updatedAt
                closed
                reviews(first: 100) {
                  nodes {
                    author {
                      login
                    }
                  }
                }
                mergeCommit {
                  commitUrl
                }
                repository {
                  name
                }
                author {
                  login
                }
              }
            }
          }
        }
      }
    }
  }
  rateLimit {
    limit
    cost
    remaining
    resetAt
  }
}