Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(edge-case): fetching associatedPRs on 100+ context.commits in success lifecycle #892

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

babblebey
Copy link
Member

@babblebey babblebey commented Aug 2, 2024

This Pull Request addresses the following edge cases in our consumption of GraphQL at fetching associatedPRs for context.commits list in the success lifecycle of the plugin.

1. Fetching associatedPRs for 100+ context.commits

We currently use GraphQL Fragments to query associatedPRs for each commit in the context.commits array, this grants us the ability to get associatedPRs for alot of commits by making just one request. BUT, we are limited to a fragment of only 100 items which means that we can only query associatedPRs for 100 commits in one request, and needing to make another request for the next set of 100 incases where there's more than 100.

THE FIX: Implemented logic to split the context.commits array into chunks of 100 items, which is then consumed by the buildAssociatedPRsQuery utils that builds the GraphQL query fragment, requests the associatedPRs per chunk and ends up merging/consolidating all response nodes from each chunks into on final array of associatedPRs

2. When associatedPRs response nodes is more than 100 (kinda unlikely, but wouldn't hurt to address 🤔)

When associatedPRs are fetched for each commit, there's a possibility that the response items is more than 100 🫣. Important to note that "Maximum response nodes is 100 items with the rest paginated" this means we can only get back 100 nodes and the rest split to another page of 100 max nodes.

THE FIX: Implemented a second graphQL query loadSingleCommitAssociatedPRs (seen below) which is used to fetch the next page in a paginated response for individual associatedPRs. This is made possible with the pageInfo value in the response object, which triggers a call to this query if initial response hasNextPage is true and uses the endCursor value as the starting point for next response nodes to fetch.

const loadSingleCommitAssociatedPRs = `#graphql
  query getCommitAssociatedPRs($owner: String!, $repo: String!, $sha: String!, $cursor: String) {
    repository(owner: $owner, name: $repo) {
      commit: object(oid: $sha) {
        ...on Commit {
          associatedPullRequests(after: $cursor, first: 1) {
            pageInfo {
              endCursor
              hasNextPage
            }
            nodes {
              url
              number
              body
            }
          }
        }
      }
    }
  }
`;

Important to state that this logic is consumed inside each context.commits chunks to consolidate the paginated associatedPRs response node in the final associatedPRs array.

Related Issue

Fixes #868

Screencast/Screenshot

Demo (Setting chunk-size and graphql query page request size property first to 1)

screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.6.mp4

@babblebey babblebey changed the title fix(success): edge case fetching 100+ associatedPRs on context.commits fix(edge-case): fetching associatedPRs on 100+ context.commits in success lifecycle Aug 9, 2024
@babblebey babblebey marked this pull request as ready for review August 9, 2024 18:06
@babblebey babblebey merged commit dfe47e9 into master Aug 15, 2024
6 checks passed
@babblebey babblebey deleted the feat/100-commits-plus branch August 15, 2024 18:34
Copy link

🎉 This issue has been resolved in version 10.1.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edge Case: Address fetching associatedPRs from more than 100 commits with GraphQL
2 participants