From 2ad8276b09318a7eafc1b8c03fc170d79bb18325 Mon Sep 17 00:00:00 2001 From: Karibhou Date: Mon, 9 Nov 2026 23:53:34 +0000 Subject: [PATCH 1/2] fix(automerge): post /ok-to-test once on admitted non-member fork PRs On a Prow-managed repository the trigger plugin runs presubmits for a non-member's fork PR only after a trusted user comments /ok-to-test, so an admitted contributor-lane PR (#17359) sat green on GitHub Actions while Tide reported "Jobs ... have not succeeded". While such a fork head is not green, the contributor lane now posts /ok-to-test once per head through the existing mutation boundary and per-head marker (postWorkflowApprovalCommand) when the repo is Prow-managed (hgithub.ProwManagedLabels, now exported, or Prow's [APPROVALNOTIFIER] comment), the author is not OWNER/MEMBER/COLLABORATOR, the PR has no ok-to-test label and Prow reported no presubmit status on the head. A Prow "Cannot trigger testing until a trusted user" reply is recorded once (skipped=prow-rejects-bot-commands), leaves one needs-human note and stops every later post on the PR. The relay's read-only evaluation posts nothing. Fixes #17474 Hive-Run: hivecommons/hive#17474 Hive-Plan: hivecommons/hive#17451 child 1 (prow /ok-to-test on fork PRs) Hive-Spec: hivecommons/hive#17474#scope Signed-off-by: Karibhou --- .../fixed-17474-prow-ok-to-test-fork-prs.md | 1 + src/docs/fork-pr-presubmit-stall-runbook.md | 8 +- src/docs/hive-merge.md | 18 ++ .../automerge/automerge_contributor_lane.go | 5 + .../automerge_contributor_lane_test.go | 9 + .../automerge_contributor_prow_ok_to_test.go | 149 ++++++++++++++ ...omerge_contributor_prow_ok_to_test_test.go | 183 ++++++++++++++++++ .../github/automerge/automerge_held_runs.go | 14 +- src/pkg/github/pr_decision_operator.go | 6 +- src/pkg/github/pr_decision_operator_test.go | 4 +- 10 files changed, 382 insertions(+), 15 deletions(-) create mode 100644 changelog.d/fixed-17474-prow-ok-to-test-fork-prs.md create mode 100644 src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go create mode 100644 src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go diff --git a/changelog.d/fixed-17474-prow-ok-to-test-fork-prs.md b/changelog.d/fixed-17474-prow-ok-to-test-fork-prs.md new file mode 100644 index 0000000000..4fd52169f1 --- /dev/null +++ b/changelog.d/fixed-17474-prow-ok-to-test-fork-prs.md @@ -0,0 +1 @@ +- The contributor lane now posts `/ok-to-test` once per head on a fork PR it admitted whose author is not an org member or collaborator, when the repository is Prow-managed, the PR has no `ok-to-test` label and Prow has reported no presubmit on the head ([#17474](https://github.com/hivecommons/hive/issues/17474)). Previously Prow's trigger plugin never ran its presubmits on such a PR, so Tide reported `Jobs … have not succeeded` on a head that was green on GitHub Actions until a person posted the command (#17359 sat about four hours). If Prow rejects the App (`Cannot trigger testing until a trusted user`), the lane logs `skipped=prow-rejects-bot-commands` once, leaves one needs-human note and stops posting on that PR. diff --git a/src/docs/fork-pr-presubmit-stall-runbook.md b/src/docs/fork-pr-presubmit-stall-runbook.md index f19f959b70..5ce9801981 100644 --- a/src/docs/fork-pr-presubmit-stall-runbook.md +++ b/src/docs/fork-pr-presubmit-stall-runbook.md @@ -22,6 +22,8 @@ gh pr view --repo / --comments | grep -i -E "tide|not mergeable|r ## 2. Start the presubmits +The contributor lane now posts `/ok-to-test` itself, once per head, on a fork PR it admitted whose author is not an org member or collaborator ([#17474](https://github.com/hivecommons/hive/issues/17474); see [hive-merge.md](hive-merge.md)). This step is needed only when that did not help: the PR carries the hive's `needs-human` note saying Prow rejected the App (`Cannot trigger testing until a trusted user`), or the lane did not admit the PR. + A human with write access comments on the PR. This is Prow's `/ok-to-test` (trigger plugin, shows as Tide `Jobs X, Y have not succeeded`), not the same-repo `hive-ok-to-test` GitHub Actions workflow (shows as `workflow-approval-required:`; see [github-app-setup.md](github-app-setup.md)), which never covers fork heads: ```text @@ -43,8 +45,10 @@ ask that owner to comment `/approve`. ## 4. Permanent fixes (not done by this runbook) -- Post `/ok-to-test` once when the hive opens or pushes to a fork PR for a - non-member agent, or add contributor agents to the Prow trusted org or team. +- Done in #17474: the contributor lane posts `/ok-to-test` once per head on an + admitted non-member fork PR. Making the hive App (or contributor agents) a + Prow trusted user remains a Prow configuration choice; until then Prow + rejects the App's command and step 2 applies. - Relay `/lgtm` and `/approve` with the approving human's token, or add the hive App to `OWNERS`; surface Prow's rejection reply on the board instead of showing "approved". diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index 9520943bbc..38b0e49504 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -825,6 +825,24 @@ nor one touching `.github/workflows/**`. The App needs **Actions: Read and write** for the call; without it the approve fails, is logged once per head, and the PR waits for a person as before. +The lane also asks Prow to start presubmits for any admitted author +(hivecommons/hive#17474). On a Prow-managed repository (Prow's labels such as +`size/*` or `needs-ok-to-test`, or its `[APPROVALNOTIFIER]` comment) the +trigger plugin runs presubmits for a non-member's fork PR only after a trusted +user comments `/ok-to-test`, so #17359 sat green on GitHub Actions while Tide +reported `Jobs … have not succeeded`. While such a fork head is not green, the +author's `author_association` is not `OWNER`, `MEMBER` or `COLLABORATOR`, the +PR has no `ok-to-test` label and Prow has reported no presubmit status on the +head (a status other than `tide` from the account that reports `tide`), the +lane posts `/ok-to-test` once per head with the same per-head marker and +mutation-boundary dedupe as the trusted-lane command. If Prow replies +`Cannot trigger testing until a trusted user`, the lane logs it once with +`skipped=prow-rejects-bot-commands`, leaves one +`` needs-human note and never posts the +command on that PR again; making the App a Prow trusted user is the +repository's Prow configuration. The merge-request relay's read-only +evaluation posts nothing. + A PR merges through this tier only when all of the following hold: - The PR author is admitted by one of three paths: diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index e8a1f108d7..7810eed186 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1458,6 +1458,11 @@ func (c *Engine) evaluateContributorLanePR(ctx context.Context, displayRepo, own return eval, reason, err } if !green { + if !relay { + // A non-member fork head on a Prow repo gets no presubmits until + // someone posts /ok-to-test (#17474); the relay stays read-only. + c.requestProwPresubmitsForFork(ctx, displayRepo, owner, repo, pr, number, headSHA) + } if strings.HasPrefix(reason, requiredCheckMissingPrefix) { _, reason = c.approveHeldRunsForRegistryTrusted(ctx, displayRepo, owner, repo, pr, number, headSHA, claim, policy, files, reason) } diff --git a/src/pkg/github/automerge/automerge_contributor_lane_test.go b/src/pkg/github/automerge/automerge_contributor_lane_test.go index ea8fb4f6c8..1a64bdf960 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane_test.go +++ b/src/pkg/github/automerge/automerge_contributor_lane_test.go @@ -113,6 +113,9 @@ type contributorLaneFixture struct { // headStatus, when set, is the combined-status state and check-run // conclusion reported for sha7; empty means "success". headStatus string + // headStatuses is what GET commits/sha7/statuses (every commit status, + // with its creator) serves; nil serves an empty list. + headStatuses []map[string]any // baseRef, when set, gives the PR base a branch name and serves the // branch, protection and compare routes the current-base gate // (automerge_current_base.go) and release hold need; empty leaves the @@ -347,6 +350,12 @@ func newContributorLaneAPI(t *testing.T, fx *contributorLaneFixture) *httptest.S "total_count": 1, "statuses": []map[string]string{{"context": "ci/build", "state": headStatus}}, }) + case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha7/statuses": + statuses := fx.headStatuses + if statuses == nil { + statuses = []map[string]any{} + } + json.NewEncoder(w).Encode(statuses) case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha7/check-runs": run := map[string]string{"name": "build", "status": "completed", "conclusion": headStatus} if fx.checkCompletedAt != "" { diff --git a/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go b/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go new file mode 100644 index 0000000000..f1ebb2f69c --- /dev/null +++ b/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go @@ -0,0 +1,149 @@ +package automerge + +// Prow presubmits on non-member fork PRs (hivecommons/hive#17474, #17451). +// +// On a Prow-managed repository the trigger plugin runs presubmits only for a +// PR whose author is one of its trusted users (an org member or collaborator) +// or that carries `ok-to-test`. A contributor-lane fork PR by a non-member +// therefore never gets them, neither when it is opened nor after the hive's +// own base refresh, and Tide reports "Jobs … have not succeeded" on a PR that +// is green on GitHub Actions (#17359 sat about four hours until a person +// commented `/ok-to-test`). +// +// For a fork PR the contributor lane admitted (the hive vouches for the author +// and refreshes or merges the PR), the lane posts `/ok-to-test` once per head +// through the mutation boundary and per-head marker the held-runs path uses +// (postWorkflowApprovalCommand). If Prow answers that the App is not a trusted +// user, the lane records that once (hgithub.PRApprovalCommandsSkippedProw), +// leaves one needs-human note and never posts the command on the PR again. +// Whether the App is a Prow trusted user is the repository's Prow config, not +// the hive's to decide. + +import ( + "context" + "strings" + + gh "github.com/google/go-github/v72/github" + hgithub "github.com/hivecommons/hive/pkg/github" +) + +const ( + // prowOkToTestLabel is the trigger plugin's label for a PR whose + // presubmits a trusted user released; it persists across pushes. + prowOkToTestLabel = "ok-to-test" + // prowTideContext is the commit status Tide itself reports; its creator + // is the Prow account that also reports the presubmit jobs. + prowTideContext = "tide" +) + +// prowTrustedAssociations are the author_association values Prow's trigger +// plugin trusts by default: presubmits already run for these authors. +var prowTrustedAssociations = map[string]bool{ + "OWNER": true, + "MEMBER": true, + "COLLABORATOR": true, +} + +// requestProwPresubmitsForFork posts `/ok-to-test` once for headSHA when pr is +// a fork PR by a non-member on a Prow-managed repository (Prow's labels or its +// approve plugin's comment), carries no `ok-to-test` label, and Prow has +// reported no presubmit status on the head. A Prow rejection of the App's +// command is recorded once per PR and stops every later post. The caller +// must already have admitted the PR to the contributor lane. +func (c *Engine) requestProwPresubmitsForFork(ctx context.Context, displayRepo, owner, repo string, pr *gh.PullRequest, number int, headSHA string) { + if c == nil || c.gh == nil || pr == nil || strings.TrimSpace(headSHA) == "" || !c.isForkPR(pr) { + return + } + if prowTrustedAssociations[strings.ToUpper(strings.TrimSpace(pr.GetAuthorAssociation()))] { + return + } + labels := labelNames(pr.Labels) + if hasLabel(labels, prowOkToTestLabel) || c.workflowApprovalUntrustedKnown(owner, repo, number) { + return + } + _, first := c.markWorkflowApprovalCommandSeen(owner, repo, number, headSHA) + state, scanned := c.workflowApprovalCommentState(ctx, displayRepo, owner, repo, number, headSHA, first) + if !scanned { + return + } + if state.rejected { + c.markWorkflowApprovalUntrusted(owner, repo, number) + if !state.rejectionNoted { + c.postWorkflowApprovalUntrustedNote(ctx, displayRepo, owner, repo, number, headSHA, prowPresubmitsRejectedNote(strings.TrimSpace(c.transport.AppBotLogin()))) + } + c.warn("contributor-lane ok-to-test not posted again: Prow rejected the App's command on this fork PR; a trusted user must post it", + "repo", displayRepo, "pr", number, "sha", headSHA, "skipped", hgithub.PRApprovalCommandsSkippedProw) + return + } + if state.postedForHead || !(hgithub.ProwManagedLabels(labels) || state.prowManaged) { + return + } + if c.prowPresubmitStatusPresent(ctx, displayRepo, owner, repo, number, headSHA) { + return + } + c.postWorkflowApprovalCommand(ctx, displayRepo, owner, repo, number, headSHA) +} + +// prowPresubmitStatusPresent reports whether Prow already reported a job on +// headSHA: a commit status other than Tide's own, created by the account that +// created Tide's status. Without a Tide status nothing on the head can be +// attributed to Prow, so it reports false. A lookup failure reports true so +// nothing is posted on evidence that could not be read; the next comment scan +// tries again. +func (c *Engine) prowPresubmitStatusPresent(ctx context.Context, displayRepo, owner, repo string, number int, headSHA string) bool { + var statuses []*gh.RepoStatus + opts := &gh.ListOptions{PerPage: 100} + for { + page, resp, err := c.gh.Repositories.ListStatuses(hgithub.WithRESTCaller(ctx, "hive:contributor_lane_automerge_sweep"), owner, repo, headSHA, opts) + if err != nil { + c.warn("contributor-lane could not list commit statuses for Prow presubmits", "repo", displayRepo, "pr", number, "sha", headSHA, "error", err) + return true + } + statuses = append(statuses, page...) + if resp == nil || resp.NextPage == 0 { + break + } + opts.Page = resp.NextPage + } + prow := "" + for _, st := range statuses { + if st != nil && strings.EqualFold(strings.TrimSpace(st.GetContext()), prowTideContext) { + prow = hgithub.SafeGetLogin(st.GetCreator()) + break + } + } + if prow == "" { + return false + } + for _, st := range statuses { + if st == nil || strings.EqualFold(strings.TrimSpace(st.GetContext()), prowTideContext) { + continue + } + if strings.EqualFold(hgithub.SafeGetLogin(st.GetCreator()), prow) { + return true + } + } + return false +} + +// prowPresubmitsRejectedNote is the one needs-human comment posted when Prow +// refuses the App's `/ok-to-test` on a non-member fork PR. +func prowPresubmitsRejectedNote(appLogin string) string { + if appLogin == "" { + appLogin = "the Hive App" + } + var b strings.Builder + b.WriteString(workflowApprovalRejectedMarker) + b.WriteString("\nneeds-human: Prow has not run this fork PR's presubmits. Its author is not one of Prow's trusted users, so the trigger plugin waits for `") + b.WriteString(workflowApprovalCommand) + b.WriteString("`; Hive posted it and Prow rejected `") + b.WriteString(appLogin) + b.WriteString("` (\"") + b.WriteString(prowOkToTestRejection) + b.WriteString("\"). Hive will not post the command again on this PR.\n\nA maintainer can comment `") + b.WriteString(workflowApprovalCommand) + b.WriteString("` (plus `/test all` for the current head), or make `") + b.WriteString(appLogin) + b.WriteString("` a Prow trusted user so Hive's command counts.") + return b.String() +} diff --git a/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go b/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go new file mode 100644 index 0000000000..b884c6cfd8 --- /dev/null +++ b/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go @@ -0,0 +1,183 @@ +package automerge + +// Prow presubmits on non-member fork PRs (hivecommons/hive#17474). #17359 +// sat green on GitHub Actions for hours because Prow never ran its +// presubmits for a non-member fork head and nobody posted /ok-to-test. These +// pin that the contributor lane posts the command once per head on exactly +// that shape, never otherwise, and stops for good once Prow rejects the App. + +import ( + "context" + "strings" + "testing" + "time" +) + +const ( + prowOkToTestTestContext = "verify PR contents" + prowOkToTestTestBot = "kubestellar-prow[bot]" + prowOkToTestTestFork = "karibhou/widget" +) + +// prowStatus is a commit status as GET commits/{sha}/statuses serves it. +func prowStatus(name, creator string) map[string]any { + return map[string]any{"context": name, "state": "pending", "creator": map[string]string{"login": creator}} +} + +// prowOkToTestFixture is an admitted contributor-lane fork PR by a non-member +// on a Prow-managed repository whose Prow presubmit is a required check that +// never appeared on the head. +func prowOkToTestFixture() contributorLaneFixture { + fx := validContributorFixture() + fx.baseRef = "main" + fx.requiredContexts = []string{"ci/build", prowOkToTestTestContext} + fx.headRepo = prowOkToTestTestFork + fx.labels = []string{"size/S", "needs-ok-to-test"} + fx.headStatuses = []map[string]any{prowStatus(prowTideContext, prowOkToTestTestBot)} + return fx +} + +func runProwOkToTestTicks(t *testing.T, fx *contributorLaneFixture, ticks int) { + t.Helper() + api := newContributorLaneAPI(t, fx) + defer api.Close() + policy := defaultContributorLanePolicy() + clock := &contributorLaneClock{at: time.Date(2026, 11, 9, 12, 0, 0, 0, time.UTC)} + engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock)}) + for tick := 1; tick <= ticks; tick++ { + if _, _, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy); err != nil { + t.Fatalf("tick %d err = %v", tick, err) + } + // Past the comment re-scan interval, so a later tick reads the + // thread again and would post again if nothing deduped it. + clock.advance(workflowApprovalRecheck + time.Minute) + } + if fx.merges != 0 { + t.Fatalf("merges = %d, want 0 while the Prow presubmit is missing", fx.merges) + } +} + +func TestContributorLanePostsProwOkToTestForNonMemberFork(t *testing.T) { + command := workflowApprovalCommandBody("sha7") + for _, tc := range []struct { + name string + mutate func(fx *contributorLaneFixture) + wantPost bool + }{ + {name: "non-member fork on a Prow repo posts once", wantPost: true}, + {name: "first-time contributor fork posts once", mutate: func(fx *contributorLaneFixture) { fx.association = "FIRST_TIME_CONTRIBUTOR" }, wantPost: true}, + { + name: "approve plugin comment alone marks the repo as Prow-managed", + mutate: func(fx *contributorLaneFixture) { + fx.labels = nil + fx.prComments = []map[string]any{prowComment(3, "[APPROVALNOTIFIER] This PR is **NOT APPROVED**")} + }, + wantPost: true, + }, + { + name: "a status from another account is not a presubmit", + mutate: func(fx *contributorLaneFixture) { + fx.headStatuses = append(fx.headStatuses, prowStatus("hive/queue", testHiveAppBotLogin)) + }, + wantPost: true, + }, + {name: "no Tide status means no presubmit evidence", mutate: func(fx *contributorLaneFixture) { fx.headStatuses = nil }, wantPost: true}, + {name: "same-repo head is not a fork", mutate: func(fx *contributorLaneFixture) { fx.headRepo = "" }}, + {name: "org member is trusted by Prow", mutate: func(fx *contributorLaneFixture) { fx.association = "MEMBER" }}, + {name: "collaborator is trusted by Prow", mutate: func(fx *contributorLaneFixture) { fx.association = "COLLABORATOR" }}, + {name: "ok-to-test label already released the presubmits", mutate: func(fx *contributorLaneFixture) { fx.labels = []string{"size/S", "ok-to-test"} }}, + {name: "repository without Prow", mutate: func(fx *contributorLaneFixture) { fx.labels = nil }}, + { + name: "Prow already reported a presubmit on the head", + mutate: func(fx *contributorLaneFixture) { + fx.headStatuses = append(fx.headStatuses, prowStatus("native-queue-policy", prowOkToTestTestBot)) + }, + }, + { + name: "command already on the thread for this head", + mutate: func(fx *contributorLaneFixture) { fx.prComments = []map[string]any{appComment(3, command)} }, + }, + { + // Without a verified claim or registry tier the hive does not + // vouch for the author, so it must not release their code to CI. + name: "author the lane did not admit", + mutate: func(fx *contributorLaneFixture) { + fx.association = "FIRST_TIME_CONTRIBUTOR" + fx.issueComments = nil + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + fx := prowOkToTestFixture() + if tc.mutate != nil { + tc.mutate(&fx) + } + runProwOkToTestTicks(t, &fx, 3) + posted := 0 + for _, body := range fx.allComments { + if body == command { + posted++ + } + } + want := 0 + if tc.wantPost { + want = 1 + } + if posted != want { + t.Fatalf("ok-to-test posts = %d (comments %q), want %d across three ticks", posted, fx.allComments, want) + } + }) + } +} + +// A restarted hive finds its own command for the head on the thread and does +// not post it a second time. +func TestContributorLaneProwOkToTestOncePerHeadAcrossRestart(t *testing.T) { + fx := prowOkToTestFixture() + runProwOkToTestTicks(t, &fx, 1) + runProwOkToTestTicks(t, &fx, 1) + if fx.comments != 1 || fx.lastComment != workflowApprovalCommandBody("sha7") { + t.Fatalf("comments = %d last=%q, want the one command across a restart", fx.comments, fx.lastComment) + } +} + +// Prow answered the App's command with "Cannot trigger testing until a +// trusted user…": the lane leaves one needs-human note, posts no further +// command (not even for a new head), and a restarted hive stays quiet. +func TestContributorLaneStopsProwOkToTestAfterRejection(t *testing.T) { + fx := prowOkToTestFixture() + fx.prComments = []map[string]any{ + appComment(2, workflowApprovalCommandBody("oldhead")), + prowComment(3, "@"+testHiveAppBotLogin+": Cannot trigger testing until a trusted user reviews the PR and leaves an `/ok-to-test` message."), + } + runProwOkToTestTicks(t, &fx, 3) + runProwOkToTestTicks(t, &fx, 2) + if fx.comments != 1 { + t.Fatalf("comments = %d %q, want only the one needs-human note", fx.comments, fx.allComments) + } + note := fx.allComments[0] + if !strings.HasPrefix(note, workflowApprovalRejectedMarker) || !strings.Contains(note, "needs-human") || !strings.Contains(note, prowOkToTestRejection) || !strings.Contains(note, testHiveAppBotLogin) { + t.Fatalf("note = %q, want the rejected marker, a needs-human note naming the App and Prow's reply", note) + } + for _, line := range strings.Split(note, "\n") { + if strings.TrimSpace(line) == workflowApprovalCommand { + t.Fatalf("note = %q carries a bare %s line Prow would act on", note, workflowApprovalCommand) + } + } +} + +// The merge-request relay evaluates the lane read-only and posts nothing. +func TestContributorLaneRelayEvaluationDoesNotPostProwOkToTest(t *testing.T) { + fx := prowOkToTestFixture() + api := newContributorLaneAPI(t, &fx) + defer api.Close() + policy := defaultContributorLanePolicy() + clock := &contributorLaneClock{at: time.Date(2026, 11, 9, 12, 0, 0, 0, time.UTC)} + engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock)}) + if _, _, err := engine.evaluateContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy, true); err != nil { + t.Fatal(err) + } + if fx.comments != 0 { + t.Fatalf("comments = %d %q, want none from a relay evaluation", fx.comments, fx.allComments) + } +} diff --git a/src/pkg/github/automerge/automerge_held_runs.go b/src/pkg/github/automerge/automerge_held_runs.go index aa0752a4cd..42363bca74 100644 --- a/src/pkg/github/automerge/automerge_held_runs.go +++ b/src/pkg/github/automerge/automerge_held_runs.go @@ -218,7 +218,7 @@ func (c *Engine) workflowApprovalAttention(ctx context.Context, displayRepo, own // hand the command to a person once. c.markWorkflowApprovalUntrusted(owner, repo, number) if !state.rejectionNoted { - c.postWorkflowApprovalUntrustedNote(ctx, displayRepo, owner, repo, number, headSHA, state.rejected) + c.postWorkflowApprovalUntrustedNote(ctx, displayRepo, owner, repo, number, headSHA, workflowApprovalUntrustedNote(strings.TrimSpace(c.transport.AppBotLogin()), state.rejected)) } c.warn("automerge workflow approval cannot be requested by the App; merge bot trusts only its own users", "repo", displayRepo, "pr", number, "sha", headSHA, "held", held, "context", contextName, "rejected", state.rejected, "prow", state.prowManaged) @@ -459,12 +459,10 @@ func workflowApprovalUntrustedNote(appLogin string, rejected bool) string { return b.String() } -func (c *Engine) postWorkflowApprovalUntrustedNote(ctx context.Context, displayRepo, owner, repo string, number int, headSHA string, rejected bool) { - appLogin := "" - if c.transport != nil { - appLogin = strings.TrimSpace(c.transport.AppBotLogin()) - } - body := workflowApprovalUntrustedNote(appLogin, rejected) +// postWorkflowApprovalUntrustedNote posts body, a needs-human note opening +// with workflowApprovalRejectedMarker, once per PR through the mutation +// boundary. +func (c *Engine) postWorkflowApprovalUntrustedNote(ctx context.Context, displayRepo, owner, repo string, number int, headSHA, body string) { _, err := effects.Execute(ctx, c.mutation, effects.Claim{ Repo: owner + "/" + repo, Kind: effects.KindIssueComment, @@ -483,7 +481,7 @@ func (c *Engine) postWorkflowApprovalUntrustedNote(ctx context.Context, displayR c.warn("automerge failed to post ok-to-test needs-human note", "repo", displayRepo, "pr", number, "sha", headSHA, "error", err) return } - c.info("automerge posted ok-to-test needs-human note", "repo", displayRepo, "pr", number, "sha", headSHA, "rejected", rejected) + c.info("automerge posted ok-to-test needs-human note", "repo", displayRepo, "pr", number, "sha", headSHA) } // detectTrustedRegistryClankerWorkflowApprovalRequired surfaces held runs for diff --git a/src/pkg/github/pr_decision_operator.go b/src/pkg/github/pr_decision_operator.go index b239777715..c701f52f1d 100644 --- a/src/pkg/github/pr_decision_operator.go +++ b/src/pkg/github/pr_decision_operator.go @@ -386,7 +386,7 @@ func (c *Client) RecordOperatorPullRequestApprovalWith(ctx context.Context, repo } } full := owner + "/" + name - event := PullRequestApprovalEvent{Repo: full, Number: number, HeadSHA: head, Actor: actor, ProwManaged: prowManagedLabels(labels)} + event := PullRequestApprovalEvent{Repo: full, Number: number, HeadSHA: head, Actor: actor, ProwManaged: ProwManagedLabels(labels)} if opts.HumanChangeRequests != nil { if head == "" { return event, ErrPullRequestHeadUnknown @@ -477,10 +477,10 @@ func (c *Client) reportOperatorPullRequestApproval(ctx context.Context, owner, n return ctx.Err() } -// prowManagedLabels reports whether labels carry Prow's plugin markers: +// ProwManagedLabels reports whether labels carry Prow's plugin markers: // the approve plugin's `approved`, size's `size/*`, the `do-not-merge/*` // family and trigger's `ok-to-test` / `needs-ok-to-test`. -func prowManagedLabels(labels []string) bool { +func ProwManagedLabels(labels []string) bool { for _, l := range labels { l = strings.ToLower(strings.TrimSpace(l)) switch { diff --git a/src/pkg/github/pr_decision_operator_test.go b/src/pkg/github/pr_decision_operator_test.go index e13726f50e..ef7c3aa5c3 100644 --- a/src/pkg/github/pr_decision_operator_test.go +++ b/src/pkg/github/pr_decision_operator_test.go @@ -315,8 +315,8 @@ func TestProwManagedLabels(t *testing.T) { {[]string{"lgtm", "role/trusted", PRNeedsDecisionStageLabel}, false}, {nil, false}, } { - if got := prowManagedLabels(tc.labels); got != tc.want { - t.Errorf("prowManagedLabels(%v) = %v, want %v", tc.labels, got, tc.want) + if got := ProwManagedLabels(tc.labels); got != tc.want { + t.Errorf("ProwManagedLabels(%v) = %v, want %v", tc.labels, got, tc.want) } } } From 6c803e6bc341cd25fb581932dff9cf423c84f43f Mon Sep 17 00:00:00 2001 From: Karibhou Date: Mon, 9 Nov 2026 23:56:01 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix(automerge):=20rename=20o?= =?UTF-8?q?k-to-test=20source=20so=20Go=20builds=20it=20outside=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit automerge_contributor_prow_ok_to_test.go ended in _test.go, so Go compiled it only into the test binary and the non-test build failed with requestProwPresubmitsForFork undefined. Hive-Run: hivecommons/hive#17474 Hive-Plan: hivecommons/hive#17451 child 1 (prow /ok-to-test on fork PRs) Hive-Spec: hivecommons/hive#17474#scope Signed-off-by: Karibhou --- ..._prow_ok_to_test.go => automerge_contributor_prow_oktotest.go} | 0 ...o_test_test.go => automerge_contributor_prow_oktotest_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/pkg/github/automerge/{automerge_contributor_prow_ok_to_test.go => automerge_contributor_prow_oktotest.go} (100%) rename src/pkg/github/automerge/{automerge_contributor_prow_ok_to_test_test.go => automerge_contributor_prow_oktotest_test.go} (100%) diff --git a/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go b/src/pkg/github/automerge/automerge_contributor_prow_oktotest.go similarity index 100% rename from src/pkg/github/automerge/automerge_contributor_prow_ok_to_test.go rename to src/pkg/github/automerge/automerge_contributor_prow_oktotest.go diff --git a/src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go b/src/pkg/github/automerge/automerge_contributor_prow_oktotest_test.go similarity index 100% rename from src/pkg/github/automerge/automerge_contributor_prow_ok_to_test_test.go rename to src/pkg/github/automerge/automerge_contributor_prow_oktotest_test.go