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-16199.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The automerge sweep now logs the "install the ok-to-test workflow" approval warning once per PR head instead of every tick ([#16199](https://github.com/hivecommons/hive/issues/16199)).
10 changes: 8 additions & 2 deletions src/pkg/github/automerge/automerge_held_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const (
// waiting on a person's approval.
workflowRunConclusionActionRequired = "action_required"
workflowApprovalWorkflowMissingPrefix = "workflow-approval-required:missing-workflow:"
// workflowApprovalGraceWarnKey keys the once-per-head grace warning in
// terminalHoldLogged separately from the hold reason itself, so the sweep
// loop's "automerge hold" line (keyed on the bare reason) still fires.
workflowApprovalGraceWarnKey = "workflow-approval-grace-warned:"
// workflowApprovalUntrustedPrefix: the repository's merge bot (Prow) owns
// `/ok-to-test` and only honours it from its trusted users, which a
// GitHub App login never is. Posting again cannot succeed; a person must
Expand Down Expand Up @@ -224,8 +228,10 @@ func (c *Engine) workflowApprovalAttention(ctx context.Context, displayRepo, own
c.postWorkflowApprovalCommand(ctx, displayRepo, owner, repo, number, headSHA)
}
if !firstSeen.IsZero() && headOlderThan(c.now, firstSeen, workflowApprovalGrace) {
c.warn("automerge workflow approval still required after ok-to-test grace; install the self-contained hive ok-to-test workflow",
"repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand)
if c.markTerminalHoldLogged(owner, repo, number, headSHA, workflowApprovalGraceWarnKey+contextName) {
c.warn("automerge workflow approval still required after ok-to-test grace; install the self-contained hive ok-to-test workflow",
"repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand)
}
return workflowApprovalWorkflowMissingPrefix + contextName
}
c.info("automerge workflow approval required; posted ok-to-test command if needed", "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "command", workflowApprovalCommand)
Expand Down
15 changes: 15 additions & 0 deletions src/pkg/github/automerge/automerge_held_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package automerge
// and names a head whose runs were never created instead of polling it forever.

import (
"bytes"
"context"
"log/slog"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -395,6 +397,8 @@ func TestTrySweepTrustedBotWorkflowApprovalMissingWorkflowAfterGrace(t *testing.
c := newAutoMergeSweepClient(api.URL)
c.trustedBotAuthors = func() map[string]bool { return map[string]bool{"dependabot[bot]": true} }
c.now = func() time.Time { return now }
var logs bytes.Buffer
c.logger = slog.New(slog.NewTextHandler(&logs, nil))

_, reason, err := c.trySweepSelfAuthoredPR(context.Background(), "widget", "acme", "widget", 23, true)
if err != nil {
Expand All @@ -414,6 +418,17 @@ func TestTrySweepTrustedBotWorkflowApprovalMissingWorkflowAfterGrace(t *testing.
if len(comments) != 1 || comments[0] != workflowApprovalCommandBody("sha23") {
t.Fatalf("comments = %q, want one %q command with the head marker", comments, workflowApprovalCommand)
}
if _, _, err = c.trySweepSelfAuthoredPR(context.Background(), "widget", "acme", "widget", 23, true); err != nil {
t.Fatalf("third tick returned error: %v", err)
}
if n := strings.Count(logs.String(), "still required after ok-to-test grace"); n != 1 {
t.Fatalf("grace warning logged %d times across repeat ticks, want once per head", n)
}
// The grace warning must not claim the hold reason's own dedupe key, or the
// sweep loop's once-per-head "automerge hold" line would never fire.
if !c.markTerminalHoldLogged("acme", "widget", 23, "sha23", reason) {
t.Fatalf("hold reason %q already marked logged by the grace warning; sweep loop would skip its automerge hold line", reason)
}
}

func TestTrySweepTrustedBotSentinelBlocksWorkflowApprovalAttention(t *testing.T) {
Expand Down
Loading