From 15c824e46514915a022dee27fdb62b483a691588 Mon Sep 17 00:00:00 2001 From: Danathar Date: Sat, 7 Nov 2026 10:14:29 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(github):=20GraphQL=20PR=20ba?= =?UTF-8?q?tch=20keeps=20"allow=20edits=20by=20maintainers"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GraphQL PR batch stored each PR's detail without maintainerCanModify, and EnrichCIStatus reuses that detail in place of a REST GET, so every fork PR read as not editable. The hold guard then stopped keeping held fork PRs current without asking GitHub ("a fork the Hive app cannot push to") on projectbluefin/gutenprint-printer-app#196 and hplip-printer-app#199, whose forks allow maintainer edits. ReachableAction and the dashboard's adopted-push check read the same field. Ask for maintainerCanModify in the batch query and carry it into the stored detail. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-graphql-batch-maintainer-edits.md | 1 + src/pkg/github/pr_batch_graphql.go | 40 ++++++----- .../pr_batch_graphql_maintainer_edits_test.go | 68 +++++++++++++++++++ 3 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 changelog.d/fixed-graphql-batch-maintainer-edits.md create mode 100644 src/pkg/github/pr_batch_graphql_maintainer_edits_test.go diff --git a/changelog.d/fixed-graphql-batch-maintainer-edits.md b/changelog.d/fixed-graphql-batch-maintainer-edits.md new file mode 100644 index 0000000000..ab3fd2c01f --- /dev/null +++ b/changelog.d/fixed-graphql-batch-maintainer-edits.md @@ -0,0 +1 @@ +- Fork PRs that allow edits by maintainers no longer read as forks the hive cannot push to. The GraphQL PR batch (`graphql_pr_batch`, on by default) stored each PR's detail without `maintainerCanModify`, and the scan reused that detail in place of a REST read, so every fork PR came out "not editable". The hold guard then stopped keeping held fork PRs current without asking GitHub, and posted "a fork the Hive app cannot push to" on projectbluefin/gutenprint-printer-app#196 and projectbluefin/hplip-printer-app#199, whose forks both allow maintainer edits. The repair queue's push-or-comment-only choice and the dashboard's adopted-PR push check read the same field. The batch query now asks for `maintainerCanModify` and carries it into the stored detail. diff --git a/src/pkg/github/pr_batch_graphql.go b/src/pkg/github/pr_batch_graphql.go index ee3a54cd66..6b8280c80a 100644 --- a/src/pkg/github/pr_batch_graphql.go +++ b/src/pkg/github/pr_batch_graphql.go @@ -20,6 +20,7 @@ query($owner: String!, $name: String!, $first: Int!, $cursor: String) { baseRefOid updatedAt isDraft + maintainerCanModify mergeable mergeStateStatus reviewDecision @@ -80,13 +81,17 @@ type graphQLPRBatchResponse struct { } type graphQLPRBatchNode struct { - Number int `json:"number"` - HeadRefOID string `json:"headRefOid"` - BaseRefOID string `json:"baseRefOid"` - UpdatedAt time.Time `json:"updatedAt"` - IsDraft bool `json:"isDraft"` - Mergeable string `json:"mergeable"` - MergeStateStatus string `json:"mergeStateStatus"` + Number int `json:"number"` + HeadRefOID string `json:"headRefOid"` + BaseRefOID string `json:"baseRefOid"` + UpdatedAt time.Time `json:"updatedAt"` + IsDraft bool `json:"isDraft"` + // MaintainerCanModify is "allow edits by maintainers". The stored + // detail stands in for a REST GET, so leaving it out read every fork PR + // as one the hive cannot push to (projectbluefin/gutenprint-printer-app#196). + MaintainerCanModify bool `json:"maintainerCanModify"` + Mergeable string `json:"mergeable"` + MergeStateStatus string `json:"mergeStateStatus"` reviewDecisionNode Labels struct { Nodes []struct { @@ -250,16 +255,17 @@ func (c *Client) storeGraphQLPRBatchNode(repo string, n graphQLPRBatchNode) { state := graphQLMergeStateStatusToREST(n.MergeStateStatus) mergeable := graphQLMergeable(n.Mergeable) pr := &gh.PullRequest{ - Number: gh.Ptr(n.Number), - State: gh.Ptr("open"), - Title: gh.Ptr(n.Title), - UpdatedAt: &gh.Timestamp{Time: n.UpdatedAt}, - User: &gh.User{Login: gh.Ptr(n.Author.Login)}, - Draft: gh.Ptr(n.IsDraft), - Mergeable: mergeable, - MergeableState: gh.Ptr(state), - Head: &gh.PullRequestBranch{SHA: gh.Ptr(n.HeadRefOID), Ref: gh.Ptr(n.HeadRefName)}, - Base: &gh.PullRequestBranch{SHA: gh.Ptr(n.BaseRefOID), Ref: gh.Ptr(n.BaseRefName)}, + Number: gh.Ptr(n.Number), + State: gh.Ptr("open"), + Title: gh.Ptr(n.Title), + UpdatedAt: &gh.Timestamp{Time: n.UpdatedAt}, + User: &gh.User{Login: gh.Ptr(n.Author.Login)}, + Draft: gh.Ptr(n.IsDraft), + MaintainerCanModify: gh.Ptr(n.MaintainerCanModify), + Mergeable: mergeable, + MergeableState: gh.Ptr(state), + Head: &gh.PullRequestBranch{SHA: gh.Ptr(n.HeadRefOID), Ref: gh.Ptr(n.HeadRefName)}, + Base: &gh.PullRequestBranch{SHA: gh.Ptr(n.BaseRefOID), Ref: gh.Ptr(n.BaseRefName)}, } for _, l := range n.Labels.Nodes { if strings.TrimSpace(l.Name) != "" { diff --git a/src/pkg/github/pr_batch_graphql_maintainer_edits_test.go b/src/pkg/github/pr_batch_graphql_maintainer_edits_test.go new file mode 100644 index 0000000000..b203b582e4 --- /dev/null +++ b/src/pkg/github/pr_batch_graphql_maintainer_edits_test.go @@ -0,0 +1,68 @@ +package github + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "strings" + "sync/atomic" + "testing" + "time" +) + +// The GraphQL batch stores a PR detail that EnrichCIStatus reuses in place +// of a REST GET, and the PR's "allow edits by maintainers" is read from that +// detail. Without the field the batch detail said "no" for every fork PR: +// the hold guard stopped updating projectbluefin/gutenprint-printer-app#196 +// and hplip-printer-app#199 as "a fork the Hive app cannot push to" without +// ever asking GitHub, while both forks allowed maintainer edits. +func TestGraphQLPRBatchCarriesMaintainerCanModify(t *testing.T) { + restore := resetPRDetailCacheForTest(time.Now, 128) + defer restore() + + withEdits := func(node string, allow bool) string { + return strings.Replace(node, `"isDraft":false,`, fmt.Sprintf(`"isDraft":false,"maintainerCanModify":%t,`, allow), 1) + } + var pullGets atomic.Int32 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.URL.Path == "/graphql": + fmt.Fprintf(w, `{"data":{"repository":{"pullRequests":{"pageInfo":{"hasNextPage":false,"endCursor":""},"nodes":[%s,%s]}},"rateLimit":{"cost":3,"remaining":4997,"resetAt":"2026-10-08T23:00:00Z"}}}`, + withEdits(gqlPRNodeJSON(1, "BEHIND", "MERGEABLE", "sha-1", "completed", "success"), true), + withEdits(gqlPRNodeJSON(2, "BEHIND", "MERGEABLE", "sha-2", "completed", "success"), false)) + case strings.Contains(r.URL.Path, "/pulls/"): + pullGets.Add(1) + t.Fatalf("unexpected REST pull GET %s: the batch detail should be reused", r.URL.Path) + case r.URL.Path == "/rate_limit": + fmt.Fprint(w, `{"resources":{"core":{"limit":5000,"remaining":4999,"reset":1791500400},"graphql":{"limit":5000,"remaining":4997,"reset":1791500400}}}`) + default: + t.Fatalf("unexpected path %s", r.URL.Path) + } + })) + defer srv.Close() + c := newTestClient(t, srv, "org", []string{"repo"}) + c.SetGraphQLPRBatchConfig(func() bool { return true }, func() int { return 50 }) + + c.prefetchOpenPRDetailsGraphQL(context.Background(), "org", "repo", "org/repo") + prs := []PullRequest{ + {Repo: "org/repo", Number: 1, HeadSHA: "sha-1", UpdatedAt: mustTime("2026-10-08T20:00:00Z"), FromFork: true}, + {Repo: "org/repo", Number: 2, HeadSHA: "sha-2", UpdatedAt: mustTime("2026-10-08T20:00:00Z"), FromFork: true}, + } + c.EnrichCIStatus(context.Background(), prs) + if got := pullGets.Load(); got != 0 { + t.Fatalf("REST pull GETs = %d, want 0", got) + } + if prs[0].MergeableState != "behind" { + t.Fatalf("mergeable_state = %q, want behind from the batch", prs[0].MergeableState) + } + if !prs[0].MaintainerCanModify { + t.Fatal("fork PR that allows maintainer edits read as not editable from the batch detail") + } + if prs[1].MaintainerCanModify { + t.Fatal("fork PR that does not allow maintainer edits read as editable") + } + if got := ReachableAction(prs[0]); got != ReachableActionPush { + t.Fatalf("ReachableAction = %q, want %q for an editable fork", got, ReachableActionPush) + } +}