diff --git a/changelog.d/fixed-merge-wording-auto-merge-off.md b/changelog.d/fixed-merge-wording-auto-merge-off.md new file mode 100644 index 0000000000..e17e2d117c --- /dev/null +++ b/changelog.d/fixed-merge-wording-auto-merge-off.md @@ -0,0 +1 @@ +- The 090 "Ready for a human merge" comment no longer names the author's trust role when something else is why a person merges. On a repository whose hive auto-merge is off it said "Blocked only by `role/trusted`"; it now says "Auto-merge is off for this repo, so a person merges." in the same words the dashboard's gate cell uses (the other non-trust reasons — refused merge method, branch protection, missing App permission, reviewer deferred — likewise). Its closing line asks for `/lgtm` `/approve` only when the PR wears Prow's plugin labels; elsewhere it asks the person to approve and merge on GitHub, since nothing there answers `/lgtm`. The workflow-path fence's owner-approval audit comment on an auto-merge-off repository now says a person merges the PR instead of "the hive merges this PR itself" (projectbluefin/website#1036, projectbluefin/actions#757, projectbluefin/actions#752). diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 04626254dd..78e998d801 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -477,10 +477,16 @@ conflict reason and the contributor lane's soak — and | everything above clean but a sentinel alert or hold-class label on the PR | `090-ready-for-human-merge`, held ([#17327](https://github.com/hivecommons/hive/issues/17327)): the entry comment carries the evidence and adds "Held: a sentinel alert is open on this PR. The hive never merges this head while the gate stands." The gate never changes the stage; it only stops the merge | | checks still running / unreadable, a required check (branch protection or ruleset) with nothing reported on the head (a PR opened with `GITHUB_TOKEN` triggers no workflow; projectbluefin/utah#1074), or the lane's soak not yet elapsed | `060-reviewed` (not 095: that stage means the lane has *admitted* the head, which a trust-blocked PR never is) | | everything above clean and only trust in the way | `090-ready-for-human-merge` + one entry comment: "Ready for a human merge: verdict approved @abc1234, 55/55 checks green, DCO yes, soak 1h0m0s elapsed. Blocked only by `role/newcomer` (below require_tiers)." When GitHub reports the head behind a base that requires up-to-date branches, the stage is still 090, but the comment adds "behind `main`" to the digest, says "Blocked by" instead of "Blocked only by", and says GitHub will not merge the head until `main` is merged into it ([projectbluefin/common#1619](https://github.com/projectbluefin/common/issues/1619)) | +| everything above clean and a person merges for another reason: the repo's hive auto-merge is off, the repo refuses the merge method, branch protection wants a review the hive cannot give, the App lacks the merge permission, a reviewer deferred | `090-ready-for-human-merge` + one entry comment that states that reason in the same words the dashboard's gate cell uses (`prstage.HumanMergeReasonWords`), e.g. "Auto-merge is off for this repo, so a person merges.", instead of "Blocked only by `role/…`" ([projectbluefin/website#1036](https://github.com/projectbluefin/website/pull/1036)) | The entry comments are posted once per stage visit (a flip 085 ↔ 090 is a new visit) and never as a GitHub review: the hive does not approve on a -maintainer's behalf, so prow/tide see nothing until a person acts. The +maintainer's behalf, so prow/tide see nothing until a person acts. The 090 +comment's closing line asks for `/lgtm` `/approve` only when the PR wears +one of Prow's plugin labels (`approved`, `size/*`, `do-not-merge/*`, +`ok-to-test`, `needs-ok-to-test`, `tide/*`); otherwise it asks the person to +approve and merge it on GitHub, since nothing in that repository answers +`/lgtm` ([projectbluefin/actions#757](https://github.com/projectbluefin/actions/pull/757)). The check digest costs two REST calls per head and is cached 10 minutes; it is read only for human-routed PRs. diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index ff54cf92f6..3e3ecc8355 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -639,7 +639,7 @@ advanced into the merge path. | `auto_merge.contributor_lane.auto_promotion_scope` | `hive` | Where the clean-merged-PR ratchet (`auto_merge.contributor_tier.auto_promote_after_merged`) counts an author's merges: `hive` counts across every repository the hive manages (one `search/issues` query finds the repos holding the author's merges; the PR's own repo is always walked first), `repo` counts only the PR's repository. Revert and sentinel-alert evidence blocks promotion in either scope. | | `auto_merge.contributor_tier.auto_promote_after_merged` | `5` | Clean merged PRs (no revert, no sentinel label, not undone by a later merged revert) after which the contributor lane treats an author as `trusted` without an operator grant, unless the registry marks them `revoked`. Negative disables the ratchet. | | `auto_merge.contributor_lane.approve_held_runs_for_registry_trusted` | `true` | When the registry path admitted the PR author and the lane stops at `required-check-missing:` (or at `ci-unverified` with every `pull_request` run on the head held), approve the head's `action_required` workflow runs once per hive process (`POST /repos/{owner}/{repo}/actions/runs/{id}/approve`; only fork `pull_request` runs and Actions-bot runs, the ones GitHub accepts; a 403 is not retried until the head changes or the App gains Actions write), post one `hive:contributor-held-runs-approved` audit comment and log `contributor-lane approved held runs`. Never acts for claim-marker, auto-promoted or association admissions, sentinel/exclude-labelled PRs, or diffs touching `.github/workflows/**`. Needs the App's **Actions: Read and write** permission. See [hive-merge.md](../hive-merge.md#contributor-lane-auto-merge). | -| `auto_merge.contributor_lane.owner_approval_releases_workflow_fence` | `true` | A hive owner / trusted merger's explicit approval on the **current** head — a GitHub `APPROVED` review on that commit, or a `/hive decision approve` (typed on the PR by the merger, or from the dashboard) bound to it — releases the contributor lane's `contributor-lane:workflow-path` fence (never for a head that also removes tests, which stays `contributor-lane:tests-removed`), so the lane merges a PR editing `.github/workflows/**` / `.github/actions/**` itself once CI, soak and the other gates are clear. The same approval answers a `requires_human` reviewer verdict on that head (a typed one is recorded as the decision, logging `typed approval recorded as the answer to the reviewer's requires_human question`); `/hive approve` answers the verdict but never releases the fence, so on the owner's own PR, where GitHub refuses the self-review, `/hive decision approve` is the one command for both ([Danathar/zfs-aurora-complex#254](https://github.com/Danathar/zfs-aurora-complex/pull/254)). Logs `workflow-path fence released by owner approval`, leaves one `hive:workflow-approval` audit comment per head, which says whether the verdict is answered; approval on an older head does not count, except across the hive's own base refresh: when only GitHub-verified App merges of the base branch (at most five) separate the approved head from the current one and the PR's three-dot diff is unchanged, the approval carries over and the lane logs `workflow-path fence approval carried over hive base refresh`. Any contributor push re-arms the fence. An unmarked approval binds to the PR `updated_at` pinned on the hive's first sweep of the head, not to the push, so one typed between the push and that sweep is judged stale and must be typed again ([#14754](https://github.com/hivecommons/hive/issues/14754)). Needs the App's **Workflows: Read and write**; without it the merge is refused, the PR is marked `hive:unauthorized` (`merge-workflow-path`) and parks at 090 for a person's click. `false` keeps every workflow-path PR a person's merge ([#14664](https://github.com/hivecommons/hive/issues/14664)). A head that also touches `auto_merge.human_merge_paths` is a person's merge either way: the human-merge-path rule refuses it after the approval, so the stage never asks for one and parks the reviewed, green, soaked head at 090 under the human-merge-path reason (a PR the pin-only exception might admit keeps the ask). See [hive-merge.md](../hive-merge.md#contributor-lane-auto-merge). | +| `auto_merge.contributor_lane.owner_approval_releases_workflow_fence` | `true` | A hive owner / trusted merger's explicit approval on the **current** head — a GitHub `APPROVED` review on that commit, or a `/hive decision approve` (typed on the PR by the merger, or from the dashboard) bound to it — releases the contributor lane's `contributor-lane:workflow-path` fence (never for a head that also removes tests, which stays `contributor-lane:tests-removed`), so the lane merges a PR editing `.github/workflows/**` / `.github/actions/**` itself once CI, soak and the other gates are clear. On a repository whose hive auto-merge is off the hive never merges, so the audit comment says a person merges it instead ([projectbluefin/actions#752](https://github.com/projectbluefin/actions/pull/752)). The same approval answers a `requires_human` reviewer verdict on that head (a typed one is recorded as the decision, logging `typed approval recorded as the answer to the reviewer's requires_human question`); `/hive approve` answers the verdict but never releases the fence, so on the owner's own PR, where GitHub refuses the self-review, `/hive decision approve` is the one command for both ([Danathar/zfs-aurora-complex#254](https://github.com/Danathar/zfs-aurora-complex/pull/254)). Logs `workflow-path fence released by owner approval`, leaves one `hive:workflow-approval` audit comment per head, which says whether the verdict is answered; approval on an older head does not count, except across the hive's own base refresh: when only GitHub-verified App merges of the base branch (at most five) separate the approved head from the current one and the PR's three-dot diff is unchanged, the approval carries over and the lane logs `workflow-path fence approval carried over hive base refresh`. Any contributor push re-arms the fence. An unmarked approval binds to the PR `updated_at` pinned on the hive's first sweep of the head, not to the push, so one typed between the push and that sweep is judged stale and must be typed again ([#14754](https://github.com/hivecommons/hive/issues/14754)). Needs the App's **Workflows: Read and write**; without it the merge is refused, the PR is marked `hive:unauthorized` (`merge-workflow-path`) and parks at 090 for a person's click. `false` keeps every workflow-path PR a person's merge ([#14664](https://github.com/hivecommons/hive/issues/14664)). A head that also touches `auto_merge.human_merge_paths` is a person's merge either way: the human-merge-path rule refuses it after the approval, so the stage never asks for one and parks the reviewed, green, soaked head at 090 under the human-merge-path reason (a PR the pin-only exception might admit keeps the ask). See [hive-merge.md](../hive-merge.md#contributor-lane-auto-merge). | | `auto_merge.contributor_lane.workflow_fence_scope` | `all` | Which CI workflow / action edits trip the `contributor-lane:workflow-path` fence. `all` fences every edit under `.github/workflows/**` or `.github/actions/**`. `human_merge_paths` fences only a workflow / action file that also matches the repository's `auto_merge.human_merge_paths` (the human-merge hold's matcher), so routine workflow edits go through review, CI and soak without an owner's approval. Fails closed: a repository with no `human_merge_paths` entry keeps the full fence, a renamed workflow / action file always trips it, and a head GitHub refused to merge for want of the App's **Workflows: Read and write** is marked `hive:unauthorized` (`merge-workflow-path`) and stays fenced. The tests-removed fence, Sentinel, the human-merge hold, the held-run approval guard (never for any workflow edit) and adoption's refusal to publish workflow edits upstream are unchanged. Sentinel's default `sensitive_path` list still labels such PRs `sentinel-alert`. Any other value is rejected on save and read as `all`. Owner-only through `PUT /api/config/auto-merge`; Settings → Features → Auto Merge → Contributor-lane auto-merge → **Workflow fence scope**. A repository can set its own value with `project.repo_policies[].workflow_fence_scope`. See [hive-merge.md](../hive-merge.md#contributor-lane-auto-merge). | | `auto_merge.contributor_lane.repos` | empty = all watched repos | Optional repo allow-list for the contributor-lane tier (bare name or `owner/repo`). | | `auto_merge.contributor_lane.exclude_labels` | `hold`, `do-not-merge`, `needs-human`, `blocked`, `needs-rebase` | Labels that keep a PR out of contributor-lane auto-merge (`do-not-merge/*` always excluded; `blocked` is refused by every merge lane whatever this list says, and reads `label:blocked`). | diff --git a/src/pkg/dashboard/stage_tracker_actor.go b/src/pkg/dashboard/stage_tracker_actor.go index 6bcf7c6ac8..a48b0fd8bd 100644 --- a/src/pkg/dashboard/stage_tracker_actor.go +++ b/src/pkg/dashboard/stage_tracker_actor.go @@ -7,6 +7,7 @@ import ( "strings" "time" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -256,8 +257,8 @@ func stageTrackerHumanReason(it StageTrackerItem, a *StageTrackerActor) string { return stageTrackerClipReason(clause) } case stagelabels.ReadyForHumanMerge: - if w, ok := stageTrackerHumanMergeReasonWords[it.HumanMergeReason]; ok { - return w[0] + if w, _, ok := stageengineprstage.HumanMergeReasonWords(it.HumanMergeReason); ok { + return w } case stagelabels.Fixing, stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor: if a != nil && a.Login != "" { diff --git a/src/pkg/dashboard/stage_tracker_caption.go b/src/pkg/dashboard/stage_tracker_caption.go index 653b61cef9..8116937790 100644 --- a/src/pkg/dashboard/stage_tracker_caption.go +++ b/src/pkg/dashboard/stage_tracker_caption.go @@ -534,22 +534,6 @@ func stageTrackerManualMergeReason(reason string) bool { return false } -// Gate-cell words and tooltips per prstage.HumanMergeReason* code: why a -// person, not the hive, merges a PR parked at 090 (hivecommons/hive#14658). -// Plain words, one short sentence each, no config keys (hivecommons/hive#15394). -var stageTrackerHumanMergeReasonWords = map[string][2]string{ - stageengineprstage.HumanMergeReasonWorkflowFiles: {"workflow files", "It changes GitHub workflow files, which hive never merges on its own"}, - stageengineprstage.HumanMergeReasonTestsRemoved: {"tests removed", "It removes tests, which hive never merges on its own"}, - stageengineprstage.HumanMergeReasonManualMergePolicy: {"manual-merge policy", "It touches files this repo reserves for a person to merge"}, - stageengineprstage.HumanMergeReasonBranchProtection: {"branch protection", "Branch protection wants a review hive cannot give; approve on GitHub or merge it"}, - stageengineprstage.HumanMergeReasonMergeMethod: {"merge method", "The repo does not allow the merge method this PR needs"}, - stageengineprstage.HumanMergeReasonAutoMergeOff: {"auto-merge off", "Auto-merge is off for this repo, so a person merges"}, - stageengineprstage.HumanMergeReasonUntrustedAuthor: {"untrusted author", "Hive won't merge it alone — the author isn't a trusted author yet"}, - stageengineprstage.HumanMergeReasonUnauthorized: {"hive bot lacks permission", "The hive bot's GitHub App is missing the permission to merge here; a person merges"}, - stageengineprstage.HumanMergeReasonReviewerDeferred: {"reviewer deferred", "A reviewer asked for a person to merge this one"}, - stageengineprstage.HumanMergeReasonBreakingChange: {"human merge", "Breaking change — owner merges; hive never merges a ⚠️-titled or needs-owner-merge PR"}, -} - // stageTrackerHumanMergeReason derives, from a 090 stage reason, the // compact code, the gate-cell word and the tooltip saying why a person // must merge. An unrecognised lane reason falls back to the "policy" code @@ -559,8 +543,9 @@ func stageTrackerHumanMergeReason(reason string) (code, word, tip string) { if code == "" { return "", "", "" } - if w, ok := stageTrackerHumanMergeReasonWords[code]; ok { - return code, w[0], w[1] + // The words live in prstage so the 090 entry comment says the same. + if w, why, ok := stageengineprstage.HumanMergeReasonWords(code); ok { + return code, w, why } base, _ := stagelabels.HumanApprovedReason(reason) return stageengineprstage.HumanMergeReasonPolicy, "policy", "Hive's merge rules leave this one to a person (`" + strings.TrimSpace(base) + "`)" diff --git a/src/pkg/github/automerge/automerge_contributor_workflow_approval.go b/src/pkg/github/automerge/automerge_contributor_workflow_approval.go index ac25c45e0f..7c85a42843 100644 --- a/src/pkg/github/automerge/automerge_contributor_workflow_approval.go +++ b/src/pkg/github/automerge/automerge_contributor_workflow_approval.go @@ -154,7 +154,10 @@ func (c *Engine) workflowFenceReleased(ctx context.Context, displayRepo, owner, } else { c.info("workflow-path fence released by owner approval", "repo", displayRepo, "pr", number, "login", approver, "head", headSHA) } - if err := c.commentWorkflowApproval(ctx, owner, repo, number, headSHA, approval, verdictState); err != nil { + // The merge relay's lane gate evaluates on the live engine even for + // an auto-merge-off repo, so the comment must not promise a hive + // merge there (projectbluefin/actions#752). + if err := c.commentWorkflowApproval(ctx, owner, repo, number, headSHA, approval, verdictState, !c.repoAutoMergeAllowed(displayRepo)); err != nil { c.warn("workflow-path fence: could not post audit comment", "repo", displayRepo, "pr", number, "head", headSHA, "error", err) } } @@ -481,16 +484,23 @@ func workflowApprovalMarker(headSHA string) string { // owner told only "merges once the gates clear" while the verdict still // held the PR waited hours for a merge that never came // (Danathar/zfs-aurora-complex#254). A carried approval names the head it -// was given on (from=) and says why it still stands. -func workflowApprovalComment(headSHA string, approval workflowApproval, verdictState int) string { +// was given on (from=) and says why it still stands. On a repo whose hive +// auto-merge is off (autoMergeOff) the hive never merges, so the comment +// says a person does (projectbluefin/actions#752 was told "the hive merges +// this PR itself" and sat open). +func workflowApprovalComment(headSHA string, approval workflowApproval, verdictState int, autoMergeOff bool) string { approver := approval.Login marker := workflowApprovalMarker(headSHA) + " by=" + strings.ToLower(approver) - gates := "the hive merges this PR itself once the usual gates (CI, soak, holds, review verdict) are clear." + merges, offNote := "the hive merges this PR itself", "" + if autoMergeOff { + merges, offNote = "a person merges it", " (auto-merge is off for this repository, so the hive never merges it)" + } + gates := merges + " once the usual gates (CI, soak, holds, review verdict) are clear" + offNote + "." switch verdictState { case workflowApprovalVerdictAnswered: - gates = "the same approval answers the review swarm's `requires_human` question on this head, and the hive merges this PR itself once the usual gates (CI, soak, holds) are clear." + gates = "the same approval answers the review swarm's `requires_human` question on this head, and " + merges + " once the usual gates (CI, soak, holds) are clear" + offNote + "." case workflowApprovalVerdictOpen: - gates = "the review swarm's `requires_human` verdict on this head still holds the PR. A trusted merger's `/hive decision approve` reply (or the dashboard's approval) answers it, as does a `/hive approve` reply posted after the verdict; then the hive merges this PR itself once the usual gates (CI, soak, holds) are clear." + gates = "the review swarm's `requires_human` verdict on this head still holds the PR. A trusted merger's `/hive decision approve` reply (or the dashboard's approval) answers it, as does a `/hive approve` reply posted after the verdict; then " + merges + " once the usual gates (CI, soak, holds) are clear" + offNote + "." } if approval.CarriedFrom != "" { // The approval was on an earlier head; head only merges the base in @@ -504,9 +514,9 @@ func workflowApprovalComment(headSHA string, approval workflowApproval, verdictS // commentWorkflowApproval posts the audit comment once per head: an existing // marker on the PR, or a prior effects claim, suppresses it. -func (c *Engine) commentWorkflowApproval(ctx context.Context, owner, repo string, number int, headSHA string, approval workflowApproval, verdictState int) error { +func (c *Engine) commentWorkflowApproval(ctx context.Context, owner, repo string, number int, headSHA string, approval workflowApproval, verdictState int, autoMergeOff bool) error { marker := workflowApprovalMarker(headSHA) - body := workflowApprovalComment(headSHA, approval, verdictState) + body := workflowApprovalComment(headSHA, approval, verdictState, autoMergeOff) _, err := effects.Execute(hgithub.WithRESTCaller(ctx, workflowApprovalRESTCaller), c.mutation, effects.Claim{ Repo: owner + "/" + repo, Kind: effects.KindIssueComment, diff --git a/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go b/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go index b2877ee818..aab6810259 100644 --- a/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go +++ b/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go @@ -293,7 +293,7 @@ func TestContributorLaneWorkflowFenceMarkerOncePerHead(t *testing.T) { fx := validContributorFixture() fx.files = workflowPathFiles() fx.reviews = []map[string]any{ownerApprovedReview("clubanderson", "sha7")} - fx.prComments = []map[string]any{{"id": 5, "user": map[string]string{"login": testHiveAppBotLogin}, "body": workflowApprovalComment("sha7", workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone)}} + fx.prComments = []map[string]any{{"id": 5, "user": map[string]string{"login": testHiveAppBotLogin}, "body": workflowApprovalComment("sha7", workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone, false)}} api := newContributorLaneAPI(t, &fx) defer api.Close() policy := defaultContributorLanePolicy() @@ -389,7 +389,7 @@ func TestContributorLaneWorkflowFenceApprovalCarriesOverHiveBaseRefresh(t *testi }, { name: "the hive's audit marker for the approved head carries over the base merge", - comments: []map[string]any{{"id": 5, "user": map[string]string{"login": testHiveAppBotLogin}, "body": workflowApprovalComment(approvedHead, workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone)}}, + comments: []map[string]any{{"id": 5, "user": map[string]string{"login": testHiveAppBotLogin}, "body": workflowApprovalComment(approvedHead, workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone, false)}}, headCommit: hiveBaseMerge, currentDiff: workflowDiff("blobA"), wantMarker: "", @@ -436,7 +436,7 @@ func TestContributorLaneWorkflowFenceApprovalCarriesOverHiveBaseRefresh(t *testi }, { name: "an audit marker forged by someone other than the App carries nothing", - comments: []map[string]any{{"id": 5, "user": map[string]string{"login": contributorLaneTestAuthor}, "body": workflowApprovalComment(approvedHead, workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone)}}, + comments: []map[string]any{{"id": 5, "user": map[string]string{"login": contributorLaneTestAuthor}, "body": workflowApprovalComment(approvedHead, workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone, false)}}, headCommit: hiveBaseMerge, currentDiff: workflowDiff("blobA"), wantReason: contributorLaneReasonWorkflowPath, @@ -506,11 +506,11 @@ func TestParseWorkflowApprovalMarker(t *testing.T) { head, by string wantParsed bool }{ - {body: workflowApprovalComment("ABC123", workflowApproval{Login: "ClubAnderson"}, workflowApprovalVerdictNone), head: "abc123", by: "clubanderson", wantParsed: true}, - {body: workflowApprovalComment("def456", workflowApproval{Login: "clubanderson", CarriedFrom: "abc123"}, workflowApprovalVerdictNone), head: "def456", by: "clubanderson", wantParsed: true}, + {body: workflowApprovalComment("ABC123", workflowApproval{Login: "ClubAnderson"}, workflowApprovalVerdictNone, false), head: "abc123", by: "clubanderson", wantParsed: true}, + {body: workflowApprovalComment("def456", workflowApproval{Login: "clubanderson", CarriedFrom: "abc123"}, workflowApprovalVerdictNone, false), head: "def456", by: "clubanderson", wantParsed: true}, {body: ""}, {body: ""}, - {body: "> " + workflowApprovalComment("abc123", workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone)}, + {body: "> " + workflowApprovalComment("abc123", workflowApproval{Login: "clubanderson"}, workflowApprovalVerdictNone, false)}, } { head, by, ok := parseWorkflowApprovalMarker(tc.body) if ok != tc.wantParsed || head != tc.head || by != tc.by { diff --git a/src/pkg/github/automerge/automerge_review_head_binding_test.go b/src/pkg/github/automerge/automerge_review_head_binding_test.go index c92d7799f7..1ee83800ce 100644 --- a/src/pkg/github/automerge/automerge_review_head_binding_test.go +++ b/src/pkg/github/automerge/automerge_review_head_binding_test.go @@ -164,11 +164,11 @@ func TestApprovalBindingIsMemoised(t *testing.T) { } func TestWorkflowApprovalCommentSaysCarried(t *testing.T) { - carried := workflowApprovalComment("9d8ceabe7d2a", workflowApproval{Login: "Danathar", CarriedFrom: "1234567890ab"}, workflowApprovalVerdictNone) + carried := workflowApprovalComment("9d8ceabe7d2a", workflowApproval{Login: "Danathar", CarriedFrom: "1234567890ab"}, workflowApprovalVerdictNone, false) if !strings.Contains(carried, "from=1234567890ab -->") || !strings.Contains(carried, "approved head `1234567890ab`") || !strings.Contains(carried, "diff is unchanged") || strings.Contains(carried, "approved head `9d8ceabe7d2a`") { t.Fatalf("carried comment:\n%s", carried) } - if plain := workflowApprovalComment("9d8ceabe7d2a", workflowApproval{Login: "Danathar"}, workflowApprovalVerdictNone); !strings.Contains(plain, "approved head `9d8ceabe7d2a`") || strings.Contains(plain, "from=") { + if plain := workflowApprovalComment("9d8ceabe7d2a", workflowApproval{Login: "Danathar"}, workflowApprovalVerdictNone, false); !strings.Contains(plain, "approved head `9d8ceabe7d2a`") || strings.Contains(plain, "from=") { t.Fatalf("plain comment:\n%s", plain) } } diff --git a/src/pkg/github/automerge/automerge_stage_human.go b/src/pkg/github/automerge/automerge_stage_human.go index e35c71838a..7714ded59b 100644 --- a/src/pkg/github/automerge/automerge_stage_human.go +++ b/src/pkg/github/automerge/automerge_stage_human.go @@ -726,6 +726,27 @@ func trustCause(reason string, role stagelabels.Role) string { return tier } +// readyCommentRoute adds to route the two facts only the 090 comment's +// wording needs. A 090 a person merges for a reason other than the +// author's trust (auto-merge off for the repo, a refused merge method, …) +// states that reason in the dashboard's words instead of "Blocked only by +// `role/trusted`", which named the wrong blocker +// (projectbluefin/website#1036). A repo with none of Prow's plugin labels +// on the PR is asked for a GitHub approve and merge instead of `/lgtm` +// `/approve` (projectbluefin/actions#757). Trust reasons, and reasons with +// no words of their own, keep trustCause. +func readyCommentRoute(route stagelabels.Route, obs stageObservation) stagelabels.Route { + switch code := prstage.HumanMergeReason(obs.Reason); code { + case "", prstage.HumanMergeReasonUntrustedAuthor, prstage.HumanMergeReasonPolicy: + default: + if _, why, ok := prstage.HumanMergeReasonWords(code); ok { + route.HumanMergeWhy = why + } + } + route.NoProw = !hgithub.ProwManagedLabels(obs.Labels) + return route +} + // decisionCause renders a non-trust human-only lane reason as prose for the // 085 comment ("" for reasons the labels already explain). The workflow-path // fence reads as a manual-merge rule; decisionCauseFor refines it. @@ -1021,7 +1042,7 @@ func (c *Engine) postHumanEntry(ctx context.Context, store *stagelabels.Store, k var body string switch route.Stage { case stagelabels.ReadyForHumanMerge: - body = stagelabels.ReadyComment(route, trustCause(obs.Reason, role)) + body = stagelabels.ReadyComment(readyCommentRoute(route, obs), trustCause(obs.Reason, role)) case stagelabels.NeedsDecision: if len(route.Reasons) == 0 { // The comment falls back to DecisionReasonUnnamed; name the diff --git a/src/pkg/github/automerge/automerge_stage_ready_status_test.go b/src/pkg/github/automerge/automerge_stage_ready_status_test.go index 7ce0389ec4..66f9df22e0 100644 --- a/src/pkg/github/automerge/automerge_stage_ready_status_test.go +++ b/src/pkg/github/automerge/automerge_stage_ready_status_test.go @@ -69,8 +69,10 @@ func TestReadyEntryQuietFoldsIntoStatusCard(t *testing.T) { if _, ok := prstatus.Get(card, prstatus.KeyStageStalled); !ok { t.Fatalf("existing card section lost:\n%s", card) } + // The fixture's PR wears none of Prow's labels, so the close asks for + // a GitHub approve and merge, not `/lgtm` `/approve`. section, ok := prstatus.Get(card, prstatus.KeyStageReady) - if !ok || !strings.Contains(section, "Ready for a human merge: verdict approved `sha`") || !strings.Contains(section, "Blocked only by `role/contributor`") || !strings.Contains(section, "`/lgtm` `/approve`") { + if !ok || !strings.Contains(section, "Ready for a human merge: verdict approved `sha`") || !strings.Contains(section, "Blocked only by `role/contributor`") || !strings.Contains(section, "approve and merge it on GitHub") { t.Fatalf("stage-ready section = %q (found %v)", section, ok) } if strings.Contains(card, stagelabels.ReadyCommentMarker) { diff --git a/src/pkg/github/automerge/automerge_stage_ready_wording_test.go b/src/pkg/github/automerge/automerge_stage_ready_wording_test.go new file mode 100644 index 0000000000..6488a72575 --- /dev/null +++ b/src/pkg/github/automerge/automerge_stage_ready_wording_test.go @@ -0,0 +1,90 @@ +package automerge + +import ( + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/website#1036 (11-17 1:55 PM EST): a 090 parked with +// `repo-auto-merge-disabled` in a repo with no Prow read "Blocked only by +// `role/trusted`" and offered `/lgtm` `/approve`. It now says auto-merge +// is off, in the dashboard's words, and asks for a GitHub approve and +// merge; a Prow-managed PR keeps the Prow close. +func TestReadyCommentRouteAutoMergeOffAndProw(t *testing.T) { + base := stagelabels.Route{Stage: stagelabels.ReadyForHumanMerge, Summary: "verdict approved @6cc067b, 5/5 checks green, soak 30m0s elapsed"} + _, offWords, _ := prstage.HumanMergeReasonWords(prstage.HumanMergeReasonAutoMergeOff) + + off := readyCommentRoute(base, stageObservation{Reason: "repo-auto-merge-disabled", Labels: []string{"role/trusted", "stage/090-ready-for-human-merge"}}) + if off.HumanMergeWhy != offWords || !off.NoProw { + t.Fatalf("auto-merge-off route = why %q, noProw %v", off.HumanMergeWhy, off.NoProw) + } + got := stagelabels.ReadyComment(off, trustCause("repo-auto-merge-disabled", stagelabels.RoleTrusted)) + for _, want := range []string{"Auto-merge is off for this repo, so a person merges.", "approve and merge it on GitHub if you accept it."} { + if !strings.Contains(got, want) { + t.Fatalf("comment lacks %q:\n%s", want, got) + } + } + for _, unwanted := range []string{"Blocked only by", "role/trusted", "/lgtm", "/approve", "tide"} { + if strings.Contains(got, unwanted) { + t.Fatalf("comment says %q:\n%s", unwanted, got) + } + } + + // Prow's plugin labels on the PR keep the Prow close. + prow := readyCommentRoute(base, stageObservation{Reason: "repo-auto-merge-disabled", Labels: []string{"size/M", "role/trusted"}}) + if prow.NoProw { + t.Fatal("a PR wearing size/M reads as a repo without Prow") + } + if got := stagelabels.ReadyComment(prow, ""); !strings.Contains(got, "`/lgtm` `/approve` (or merge) if you accept it.") || !strings.Contains(got, offWords+".") { + t.Fatalf("prow comment:\n%s", got) + } + + // A trust reason keeps trustCause; an unrecognised reason (policy) + // keeps it too rather than guess at words. + for _, reason := range []string{contributorLaneReasonClaimTier, "untrusted-author-role", "some-new-lane-reason", ""} { + if r := readyCommentRoute(base, stageObservation{Reason: reason}); r.HumanMergeWhy != "" { + t.Fatalf("%q: HumanMergeWhy = %q, want the trust clause kept", reason, r.HumanMergeWhy) + } + } + got = stagelabels.ReadyComment(readyCommentRoute(base, stageObservation{Reason: contributorLaneReasonClaimTier, Labels: []string{"size/S"}}), trustCause(contributorLaneReasonClaimTier, stagelabels.RoleContributor)) + if !strings.Contains(got, "Blocked only by `role/contributor` (below require_tiers).") || !strings.Contains(got, "`/lgtm` `/approve` (or merge)") { + t.Fatalf("prow trust comment changed:\n%s", got) + } + + // Every non-trust code with words says them, never a role. + for _, reason := range []string{prstage.AutoMergeReasonMergeRefusedMethod, prstage.AutoMergeReasonMergeRefusedReview} { + r := readyCommentRoute(base, stageObservation{Reason: reason}) + _, words, _ := prstage.HumanMergeReasonWords(prstage.HumanMergeReason(reason)) + if r.HumanMergeWhy != words || words == "" { + t.Fatalf("%q: HumanMergeWhy = %q, want %q", reason, r.HumanMergeWhy, words) + } + } +} + +// projectbluefin/actions#752 (11-16 6:32 PM EST): the owner's approval +// released the workflow-path fence on a repo whose hive auto-merge is off, +// and the audit comment said "the hive merges this PR itself". It now says +// a person merges it; an auto-merge-on repo reads exactly as before. +func TestWorkflowApprovalCommentAutoMergeOff(t *testing.T) { + for _, state := range []int{workflowApprovalVerdictNone, workflowApprovalVerdictAnswered, workflowApprovalVerdictOpen} { + for _, approval := range []workflowApproval{{Login: "Danathar"}, {Login: "Danathar", CarriedFrom: "1234567890ab"}} { + off := workflowApprovalComment("9fd007702e97", approval, state, true) + if strings.Contains(off, "the hive merges this PR itself") || !strings.Contains(off, "a person merges it once the usual gates") || + !strings.Contains(off, "auto-merge is off for this repository, so the hive never merges it") { + t.Fatalf("state %d, carried %q: auto-merge-off comment:\n%s", state, approval.CarriedFrom, off) + } + on := workflowApprovalComment("9fd007702e97", approval, state, false) + if !strings.Contains(on, "the hive merges this PR itself once the usual gates") || strings.Contains(on, "auto-merge is off") { + t.Fatalf("state %d, carried %q: auto-merge-on comment changed:\n%s", state, approval.CarriedFrom, on) + } + // The marker line is the same either way: the per-head dedupe + // keys on it. + if strings.SplitN(off, "\n", 2)[0] != strings.SplitN(on, "\n", 2)[0] { + t.Fatalf("marker differs:\n%s\n%s", off, on) + } + } + } +} diff --git a/src/pkg/stageengine/prstage/human_merge_words_test.go b/src/pkg/stageengine/prstage/human_merge_words_test.go new file mode 100644 index 0000000000..ec7e982daf --- /dev/null +++ b/src/pkg/stageengine/prstage/human_merge_words_test.go @@ -0,0 +1,29 @@ +package prstage + +import "testing" + +// The dashboard's gate cell and the 090 entry comment read the same words +// per HumanMergeReason code (projectbluefin/website#1036), so every code a +// 090 can carry has them; HumanMergeReasonPolicy, the catch-all, has none +// and keeps its raw-reason wording. +func TestHumanMergeReasonWordsCoverEveryCode(t *testing.T) { + for _, code := range []string{ + HumanMergeReasonWorkflowFiles, HumanMergeReasonTestsRemoved, HumanMergeReasonManualMergePolicy, + HumanMergeReasonBranchProtection, HumanMergeReasonMergeMethod, HumanMergeReasonAutoMergeOff, + HumanMergeReasonUntrustedAuthor, HumanMergeReasonUnauthorized, HumanMergeReasonReviewerDeferred, + HumanMergeReasonBreakingChange, + } { + word, sentence, ok := HumanMergeReasonWords(code) + if !ok || word == "" || sentence == "" { + t.Errorf("%s: words = %q / %q (ok %v)", code, word, sentence, ok) + } + } + for _, code := range []string{HumanMergeReasonPolicy, ""} { + if _, _, ok := HumanMergeReasonWords(code); ok { + t.Errorf("%q has words; the catch-all keeps the raw reason", code) + } + } + if _, sentence, _ := HumanMergeReasonWords(HumanMergeReason("repo-auto-merge-disabled")); sentence != "Auto-merge is off for this repo, so a person merges" { + t.Errorf("auto-merge-off sentence = %q", sentence) + } +} diff --git a/src/pkg/stageengine/prstage/reasons.go b/src/pkg/stageengine/prstage/reasons.go index aeddee5ffb..6f0355915b 100644 --- a/src/pkg/stageengine/prstage/reasons.go +++ b/src/pkg/stageengine/prstage/reasons.go @@ -297,3 +297,29 @@ func HumanMergeReason(reason string) string { } return HumanMergeReasonPolicy } + +// humanMergeReasonWords are the short word and the one-sentence why for +// each HumanMergeReason* code: why a person, not the hive, merges a PR +// parked at 090 (hivecommons/hive#14658). The dashboard's gate cell and the +// 090 entry comment both read them, so the two never disagree. Plain words, +// one short sentence each, no config keys (hivecommons/hive#15394). +var humanMergeReasonWords = map[string][2]string{ + HumanMergeReasonWorkflowFiles: {"workflow files", "It changes GitHub workflow files, which hive never merges on its own"}, + HumanMergeReasonTestsRemoved: {"tests removed", "It removes tests, which hive never merges on its own"}, + HumanMergeReasonManualMergePolicy: {"manual-merge policy", "It touches files this repo reserves for a person to merge"}, + HumanMergeReasonBranchProtection: {"branch protection", "Branch protection wants a review hive cannot give; approve on GitHub or merge it"}, + HumanMergeReasonMergeMethod: {"merge method", "The repo does not allow the merge method this PR needs"}, + HumanMergeReasonAutoMergeOff: {"auto-merge off", "Auto-merge is off for this repo, so a person merges"}, + HumanMergeReasonUntrustedAuthor: {"untrusted author", "Hive won't merge it alone — the author isn't a trusted author yet"}, + HumanMergeReasonUnauthorized: {"hive bot lacks permission", "The hive bot's GitHub App is missing the permission to merge here; a person merges"}, + HumanMergeReasonReviewerDeferred: {"reviewer deferred", "A reviewer asked for a person to merge this one"}, + HumanMergeReasonBreakingChange: {"human merge", "Breaking change — owner merges; hive never merges a ⚠️-titled or needs-owner-merge PR"}, +} + +// HumanMergeReasonWords returns code's gate-cell word and its one-sentence +// why. ok is false for a code with no words of its own +// (HumanMergeReasonPolicy, ""). +func HumanMergeReasonWords(code string) (word, sentence string, ok bool) { + w, ok := humanMergeReasonWords[code] + return w[0], w[1], ok +} diff --git a/src/pkg/stagelabels/human.go b/src/pkg/stagelabels/human.go index 911d6af579..d40f94fa97 100644 --- a/src/pkg/stagelabels/human.go +++ b/src/pkg/stagelabels/human.go @@ -365,6 +365,18 @@ type Route struct { // BehindBase is Evidence.BehindBase on a trust-blocked 090: the 090 // comment then says the branch must be brought up to date as well. BehindBase string + // HumanMergeWhy is the one-sentence reason a person merges a 090 that + // is not waiting on the author's trust — auto-merge is off for the + // repo, the repo refuses the merge method, … — in the words the + // dashboard shows (prstage.HumanMergeReasonWords). It replaces the + // "Blocked only by `role/…`" clause, which named the wrong blocker + // (projectbluefin/website#1036). Empty for a trust-blocked 090. + HumanMergeWhy string + // NoProw: the repository shows none of Prow's plugin labels, so the + // 090 comment's closing line asks for a GitHub approve and merge + // instead of `/lgtm` `/approve`, which nothing there answers + // (projectbluefin/actions#757). False keeps the Prow wording. + NoProw bool // Gates names the hard merge stops that ride the route as pills // without choosing its stage: an open sentinel alert, a hold-class // label (owner rule, hivecommons/hive#17327). The stage is the head's @@ -902,6 +914,10 @@ func EntryCommentUpdated(body string, at time.Time) string { // blockedBy is the prose for the trust cause ("" when unknown). A head // behind a base that requires up-to-date branches (r.BehindBase) reads // "Blocked by …" and names the base merge as well (readyCommentBehindTail). +// A 090 a person merges for another reason (r.HumanMergeWhy: auto-merge +// off, merge method, …) states that reason instead of a trust cause, and a +// repository without Prow (r.NoProw) is asked for a GitHub approve and +// merge rather than `/lgtm` `/approve`. // // An approved manual-merge route (r.ManualMerge) names the lane rule and // the approver instead of a trust cause, and tells the person the one step @@ -936,15 +952,23 @@ func ReadyComment(r Route, blockedBy string) string { if len(r.Gates) > 0 { held() } - b.WriteString("\n\nThe hive never merges this lane's changes itself: click **Merge** (or `/lgtm` + `/approve` for tide) to land it.") + if r.NoProw { + b.WriteString("\n\nThe hive never merges this lane's changes itself: click **Merge** to land it.") + } else { + b.WriteString("\n\nThe hive never merges this lane's changes itself: click **Merge** (or `/lgtm` + `/approve` for tide) to land it.") + } return b.String() } if len(r.Gates) > 0 { held() - b.WriteString("\n\nConfirm the intent (resolve the sentinel alert or lift the hold), then `/lgtm` `/approve` (or merge) if you accept it.") + b.WriteString("\n\nConfirm the intent (resolve the sentinel alert or lift the hold), then " + readyCommentAccept(r) + " if you accept it.") return b.String() } - if blockedBy = strings.TrimSpace(blockedBy); blockedBy != "" { + if why := strings.TrimSpace(r.HumanMergeWhy); why != "" { + b.WriteString(" ") + b.WriteString(strings.TrimSuffix(why, ".")) + b.WriteString(".") + } else if blockedBy = strings.TrimSpace(blockedBy); blockedBy != "" { b.WriteString(readyCommentBlockedLead(r)) b.WriteString(blockedBy) b.WriteString(".") @@ -971,10 +995,25 @@ func readyCommentBlockedLead(r Route) string { func readyCommentBehindTail(r Route) string { base := strings.TrimSpace(r.BehindBase) if base == "" { - return "\n\nThe hive never approves on your behalf: `/lgtm` `/approve` (or merge) if you accept it." + return "\n\nThe hive never approves on your behalf: " + readyCommentAccept(r) + " if you accept it." + } + approve := "`/lgtm` `/approve`" + if r.NoProw { + approve = "approve it on GitHub" } return " The branch is also behind `" + base + "`, which requires up-to-date branches: GitHub will not merge this head until `" + base + "` is merged into it." + - "\n\nThe hive never approves on your behalf: `/lgtm` `/approve` if you accept it; the branch still has to be brought up to date before it can merge." + "\n\nThe hive never approves on your behalf: " + approve + " if you accept it; the branch still has to be brought up to date before it can merge." +} + +// readyCommentAccept is the step the 090 comment asks of a person who +// accepts the PR: Prow's `/lgtm` `/approve` (or a merge), or, in a +// repository without Prow, a GitHub approve and merge — `/lgtm` there is a +// comment nothing answers (projectbluefin/actions#757). +func readyCommentAccept(r Route) string { + if r.NoProw { + return "approve and merge it on GitHub" + } + return "`/lgtm` `/approve` (or merge)" } // DecisionComment renders the 085 entry comment naming what is owed. A diff --git a/src/pkg/stagelabels/ready_wording_test.go b/src/pkg/stagelabels/ready_wording_test.go new file mode 100644 index 0000000000..842972c0b2 --- /dev/null +++ b/src/pkg/stagelabels/ready_wording_test.go @@ -0,0 +1,113 @@ +package stagelabels + +import ( + "strings" + "testing" +) + +// projectbluefin/website#1036 and projectbluefin/actions#757 (11-16/17): +// on a repo whose hive auto-merge is off, and which runs no Prow, the 090 +// comment said "Blocked only by `role/trusted`" and asked for `/lgtm` +// `/approve`. A 090 a person merges for another reason now states that +// reason (Route.HumanMergeWhy), and a repo without Prow (Route.NoProw) is +// asked for a GitHub approve and merge. A Prow repo's trust-blocked text +// is unchanged. +func TestReadyCommentWordingByCauseAndProw(t *testing.T) { + const trust = "`role/trusted`" + const autoMergeOff = "Auto-merge is off for this repo, so a person merges" + base := RouteHuman(Evidence{Head: "6cc067b0000000000000000000000000000000", Verdict: VerdictApproved, Cause: CauseTrust, + Checks: CheckSummary{Known: true, Total: 5, Green: 5}}) + for _, tc := range []struct { + name string + route func(Route) Route + want []string + notWant []string + }{ + { + name: "prow, trust: unchanged", + route: func(r Route) Route { return r }, + want: []string{"Blocked only by `role/trusted`.", "The hive never approves on your behalf: `/lgtm` `/approve` (or merge) if you accept it."}, + notWant: []string{"on GitHub"}, + }, + { + name: "no prow, trust", + route: func(r Route) Route { r.NoProw = true; return r }, + want: []string{"Blocked only by `role/trusted`.", "The hive never approves on your behalf: approve and merge it on GitHub if you accept it."}, + notWant: []string{"/lgtm", "/approve", "tide"}, + }, + { + name: "no prow, auto-merge off", + route: func(r Route) Route { r.NoProw = true; r.HumanMergeWhy = autoMergeOff; return r }, + want: []string{". " + autoMergeOff + ".", "approve and merge it on GitHub if you accept it."}, + notWant: []string{"Blocked", "role/", "/lgtm", "/approve", "tide"}, + }, + { + name: "prow, auto-merge off", + route: func(r Route) Route { r.HumanMergeWhy = autoMergeOff + "."; return r }, + want: []string{autoMergeOff + ".", "`/lgtm` `/approve` (or merge) if you accept it."}, + notWant: []string{"Blocked", "role/", "merges.."}, + }, + { + name: "no prow, behind base", + route: func(r Route) Route { r.NoProw = true; r.BehindBase = "main"; return r }, + want: []string{"Blocked by `role/trusted`.", "GitHub will not merge this head until `main` is merged into it.", "approve it on GitHub if you accept it; the branch still has to be brought up to date"}, + notWant: []string{"/lgtm", "/approve", "(or merge)"}, + }, + { + name: "no prow, auto-merge off and behind base", + route: func(r Route) Route { r.NoProw = true; r.HumanMergeWhy = autoMergeOff; r.BehindBase = "main"; return r }, + want: []string{autoMergeOff + ". The branch is also behind `main`", "approve it on GitHub if you accept it"}, + notWant: []string{"Blocked", "role/", "/lgtm"}, + }, + { + name: "no prow, held", + route: func(r Route) Route { + r.NoProw = true + r.Gates = []string{"a sentinel alert is open on this PR"} + return r + }, + want: []string{"Held: a sentinel alert is open on this PR.", "then approve and merge it on GitHub if you accept it."}, + notWant: []string{"/lgtm", "/approve"}, + }, + { + name: "prow, held: unchanged", + route: func(r Route) Route { r.Gates = []string{"a sentinel alert is open on this PR"}; return r }, + want: []string{"then `/lgtm` `/approve` (or merge) if you accept it."}, + notWant: []string{"on GitHub"}, + }, + { + name: "no prow, manual merge", + route: func(r Route) Route { + r.NoProw = true + r.ManualMerge = true + r.Reasons = []string{"the PR edits CI workflow / action files"} + return r + }, + want: []string{"click **Merge** to land it."}, + notWant: []string{"tide", "/lgtm"}, + }, + { + name: "prow, manual merge: unchanged", + route: func(r Route) Route { + r.ManualMerge = true + r.Reasons = []string{"the PR edits CI workflow / action files"} + return r + }, + want: []string{"click **Merge** (or `/lgtm` + `/approve` for tide) to land it."}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + got := ReadyComment(tc.route(base), trust) + for _, w := range tc.want { + if !strings.Contains(got, w) { + t.Fatalf("comment lacks %q:\n%s", w, got) + } + } + for _, nw := range tc.notWant { + if strings.Contains(got, nw) { + t.Fatalf("comment says %q:\n%s", nw, got) + } + } + }) + } +}