[Repo Assist] Batch open-PR fetch in submit: N API calls β 1 - #12
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
gh stack submit called FindPRForBranch once per active branch β an N sequential GraphQL round-trips for an N-branch stack. Add FindOpenPRsForBranches that constructs a single batched GraphQL query using field aliases (one aliased pullRequests field per branch, filtered to OPEN state), matching FindPRForBranch semantics. Pre-fetch all open PRs in one call before the submit loop, then look up each branch's result from the map. If the batch call fails, submit falls back to per-branch FindPRForBranch so the command still works. For a 5-branch stack, this reduces 5 sequential API calls to 1 during the PR create/update phase of submit. Changes: - github.Client: add FindOpenPRsForBranches([]string) using gql.Do with a dynamically-constructed aliased query (OPEN state only) - ClientOps interface: add FindOpenPRsForBranches - MockClient: add FindOpenPRsForBranchesFn; default returns nil to trigger fallback to FindPRForBranch in existing tests - submit.go: pre-fetch with FindOpenPRsForBranches, fall back gracefully - submit_test.go: add TestSubmit_BatchFetchesOpenPRs (verifies batch called once, per-branch not called) and TestSubmit_BatchFetchFallback (verifies fallback on error) Co-authored-by: Copilot <[email protected]>
20 tasks
25 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 is an automated pull request from Repo Assist, an AI assistant.
Summary
gh stack submitcalledFindPRForBranchonce per active branch to check whether a PR already exists β an N sequential GraphQL round-trips for an N-branch stack.This PR adds
FindOpenPRsForBranchesthat sends a single batched GraphQL query using field aliases (one aliasedpullRequestsper branch, filtered toOPENstate), then pre-fetches all results before the submit loop.Impact
All
gh stack submitruns benefit.How it works
FindOpenPRsForBranchesconstructs a raw GraphQL query:{ repository(owner: "owner", name: "repo") { b0: pullRequests(headRefName: "feat/01", states: [OPEN], first: 1) { nodes { id number ... } } b1: pullRequests(headRefName: "feat/02", states: [OPEN], first: 1) { nodes { id number ... } } } }This uses
gql.Do(rawQuery, nil, &resp)to send a raw query string, bypassing the struct-based query builder which doesn't support dynamic aliases. Results are distributed back to amap[branch]β*PullRequest.Graceful fallback
If
FindOpenPRsForBranchesreturns an error (e.g. API version mismatch),submitfalls back to the original per-branchFindPRForBranchcalls β no user-visible degradation, just slower.Changes
internal/github/github.go: NewFindOpenPRsForBranches([]string) (map[string]*PullRequest, error)usinggql.Dowith dynamically-constructed aliased query (OPEN state filter)internal/github/client_interface.go: AddedFindOpenPRsForBranchestoClientOpsinterfaceinternal/github/mock_client.go: AddedFindOpenPRsForBranchesFn; default returnsnil, nilto trigger graceful fallback toFindPRForBranchin existing testscmd/submit.go: Pre-fetch withFindOpenPRsForBranches, fall back gracefully on errorcmd/submit_test.go:TestSubmit_BatchFetchesOpenPRs(verifies batch is called once, per-branch not called);TestSubmit_BatchFetchFallback(verifies fallback works on error)Relationship to PR #7
PR #7 adds a similar batch optimization for
syncStackPRs(fetching any-state PRs). This PR is independent β it targets thesubmitPR-lookup path (open PRs only) and can be reviewed and merged separately.Test Status
Tests could not be run in this environment because the Go toolchain requires network access to
proxy.golang.org/sum.golang.org(blocked by firewall). The CI workflow will run the full test suite. The fallback path (openPRs == nil β FindPRForBranch) ensures existing tests continue to work without modification.