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-16350.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix(github): a merge-queue-required operator alert now clears on its own once the base branch's rules no longer include a merge queue, instead of lingering until the PR closes (#16350)
5 changes: 4 additions & 1 deletion src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ five minutes (`mergeAlertRevalidateInterval` in
`src/pkg/github/merge_failure_alert.go`): an alert is dropped once the blocked
PR is no longer open, and a fork-approval alert is dropped as soon as the PR
head has no workflow runs still `action_required` — i.e. the operator approved
them or relaxed the repo/org setting. API errors keep the alert in place.
them or relaxed the repo/org setting. A merge-queue-required alert is dropped
once the base branch's active rules, read successfully, no longer include a
merge queue; otherwise it stays until the PR is closed or merged. API errors
keep the alert in place.

**Unprotected base branches are allowed.** The watcher no longer makes a
separate branch-protection lookup and no longer refuses solely because the base
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/github/merge_failure_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ func (c *Client) revalidateMergeFailureAlerts(ctx context.Context, nowFn func()
})
resolved = rerr == nil && runs != nil && runs.GetTotalCount() == 0
}
if !resolved && w.entry.key == "merge-queue-required" && pr.GetBase().GetRef() != "" {
// Positive evidence the rule is gone: the base branch's active
// rules were read successfully and none is a merge queue.
rules, _, rerr := c.client.Repositories.GetRulesForBranch(ctx, owner, name, pr.GetBase().GetRef(), nil)
resolved = rerr == nil && rules != nil && len(rules.MergeQueue) == 0
}
if !resolved {
continue
}
Expand Down
61 changes: 61 additions & 0 deletions src/pkg/github/merge_failure_alert_revalidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,64 @@ func TestRevalidateMergeFailureAlerts_AppPermissionClearsOnSuccessfulRead(t *tes
t.Fatalf("expected app-permission alert cleared, got %v", sink.clears)
}
}

const mergeQueueRequiredErr = "merging PR o/r#7 (squash): PUT https://api.github.test/repos/o/r/pulls/7/merge: 405 Repository rule violations found\n\nChanges must be made through the merge queue"

// A merge-queue-required alert retires while the PR is still open once the
// base branch's rules no longer include a merge queue.
func TestRevalidateMergeFailureAlerts_MergeQueueRequiredClearsWhenRuleRemoved(t *testing.T) {
var rulesStatus atomic.Int32
rulesStatus.Store(http.StatusOK)
var queued atomic.Bool
queued.Store(true)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch {
case r.Method == http.MethodGet && strings.Contains(r.URL.Path, "/pulls/"):
_, _ = io.WriteString(w, `{"number":7,"state":"open","head":{"sha":"abc"},"base":{"ref":"main"}}`)
case r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/rules/branches/main"):
if code := int(rulesStatus.Load()); code != http.StatusOK {
w.WriteHeader(code)
return
}
if queued.Load() {
_, _ = io.WriteString(w, `[{"type":"merge_queue","parameters":{}}]`)
return
}
_, _ = io.WriteString(w, `[{"type":"deletion"}]`)
default:
w.WriteHeader(http.StatusInternalServerError)
}
}))
defer srv.Close()

c := testMergeClient(t, srv.URL)
sink := &recordingMergeAlertSink{}
c.SetMergeFailureAlertSink(sink)
c.raiseMergeFailureAlert("o/r", 7, mergeQueueRequiredErr)
if len(sink.adds) != 1 {
t.Fatalf("expected 1 alert, got %d", len(sink.adds))
}

now := time.Date(2026, 11, 2, 12, 0, 0, 0, time.UTC)
nowFn := func() time.Time { return now }
c.revalidateMergeFailureAlerts(context.Background(), nowFn)
if len(sink.clears) != 0 {
t.Fatalf("alert cleared while merge queue rule still applies: %v", sink.clears)
}

queued.Store(false)
rulesStatus.Store(http.StatusBadGateway)
now = now.Add(mergeAlertRevalidateInterval)
c.revalidateMergeFailureAlerts(context.Background(), nowFn)
if len(sink.clears) != 0 {
t.Fatalf("alert cleared on rules read error: %v", sink.clears)
}

rulesStatus.Store(http.StatusOK)
now = now.Add(mergeAlertRevalidateInterval)
c.revalidateMergeFailureAlerts(context.Background(), nowFn)
if len(sink.clears) != 1 || sink.clears[0] != sink.adds[0].id {
t.Fatalf("expected merge-queue-required alert cleared, got %v", sink.clears)
}
}
Loading