Skip to content

Optimize github anno-prs and github checkout-prs for the case of 500+ PRs in a repo #1040

Description

@PawelLipski

As for now, all PRs are first fetched, even for git machete github checkout-prs <single-PR-number>, for the sake of traversing the PR chain upwards. This takes time due to the pagination limits (100 PRs at most in a single page, as of Sep 2023).

This is rather hard to optimize reasonably... we can consider fetching PRs for the matching set of head branches and/or author (only first match the PRs that have the given author).
/search/issues (v3) REST API cannot be used for that purpose as it does not include PR-specific fields that we can't do without (like head and base branches), only the stuff that's common to issues and PRs. Also, there's no /search/pulls.

Sample relevant v3 query:

curl -sL -H"Authorization: Bearer $(gh auth token)" https://api.github.com/search/issues?q=is:pr+state:open+repo:VirtusLab/git-machete+author:PawelLipski | jq -C | less -r

Thus, our only chance is GraphQL (v4) API. A sample query:

curl -sL -H"Authorization: Bearer $(gh auth token)" https://api.github.com/graphql -d "{\"query\": $(jq -R -s . < query.graphql)}" | jq -C | less -r

where query.graphql has:

{
  search(query: "is:pr author:PawelLipski repo:VirtusLab/git-machete", type: ISSUE, first: 100) {
  ### search(query: "is:pr author:PawelLipski repo:VirtusLab/git-machete", type: ISSUE, first: 100, after: "<endCursor>") {
    issueCount
    edges {
      node {
        ... on PullRequest {
          title
          url
          headRefName
          baseRefName
        }
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    githubRelates to integration with GitHubperformanceSomething works too slow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions