fix(edge-case): fetching associatedPRs
on 100+ context.commits
in success
lifecycle
#892
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request addresses the following edge cases in our consumption of GraphQL at fetching
associatedPRs
forcontext.commits
list in thesuccess
lifecycle of the plugin.1. Fetching
associatedPRs
for 100+context.commits
We currently use GraphQL Fragments to query
associatedPRs
for each commit in thecontext.commits
array, this grants us the ability to getassociatedPRs
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 queryassociatedPRs
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 thebuildAssociatedPRsQuery
utils that builds the GraphQL query fragment, requests theassociatedPRs
per chunk and ends up merging/consolidating all response nodes from each chunks into on final array ofassociatedPRs
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 thepageInfo
value in the response object, which triggers a call to this query if initial responsehasNextPage
istrue
and uses theendCursor
value as the starting point for next response nodes to fetch.Important to state that this logic is consumed inside each
context.commits
chunks to consolidate the paginatedassociatedPRs
response node in the finalassociatedPRs
array.Related Issue
Fixes #868
Screencast/Screenshot
Demo (Setting
chunk-size
and graphql query page request size propertyfirst
to1
)screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.6.mp4