Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-graphql-batch-maintainer-edits.md
Original file line number Diff line number Diff line change
@@ -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.
40 changes: 23 additions & 17 deletions src/pkg/github/pr_batch_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ query($owner: String!, $name: String!, $first: Int!, $cursor: String) {
baseRefOid
updatedAt
isDraft
maintainerCanModify
mergeable
mergeStateStatus
reviewDecision
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) != "" {
Expand Down
68 changes: 68 additions & 0 deletions src/pkg/github/pr_batch_graphql_maintainer_edits_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading