diff --git a/changelog.d/added-16582-hive-auto-reauthor.md b/changelog.d/added-16582-hive-auto-reauthor.md new file mode 100644 index 0000000000..d4d739f27e --- /dev/null +++ b/changelog.d/added-16582-hive-auto-reauthor.md @@ -0,0 +1 @@ +- The hive re-authors its own fixer-exhausted PRs by itself instead of parking them for a person ([#16582](https://github.com/hivecommons/hive/issues/16582)): the exhausted hive PR is closed as superseded with a note, the issue is labelled `hive/re-authored` and requeued so the next kick opens a fresh PR from the current base (the kick asks for `Supersedes #`). One automatic re-author per issue; a second exhaustion parks at 085 with Give direction / Hand it to a person / Close as not planned. The Activity Monitor words the issue `Re-authoring · superseding #N` (remediation evidence `kick`) and the fresh PR's chip `re-authored from #N`. `decide:re-author` is gone from the decision vocabulary: a person's rewrite of a contributor PR (unsigned DCO, exhausted) is `decide:adopt` — "Adopt as hive PR"; historical `re-author` ledger entries still read. diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index 8e5297c1b4..efe9cbee22 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -555,6 +555,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto stageTrackerApplyRemediation(&activityItem, dispatchState, status, stageTrackerFixerAgent(cfg), now) it.CodeActivity, it.Remediation, it.ReviewActivity, it.DisplayColumn, it.Caption = activityItem.CodeActivity, activityItem.Remediation, activityItem.ReviewActivity, activityItem.DisplayColumn, activityItem.Caption } + stageTrackerApplyReauthor(resp.Items, store, status.GitHubBaseURL, now) resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items) resp.WaitingOnHuman = stageTrackerWaitingOnHuman(resp.Items) resp.IntegrationQueues = s.stageTrackerNativeQueues(now) diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go index d0b265a974..9d3d30513f 100644 --- a/src/pkg/dashboard/stage_tracker_decision.go +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -90,7 +90,6 @@ const ( decisionActionCloseWontfix = "decide:close-wontfix" decisionActionMergeNow = "decide:merge-now" decisionActionQueueMerge = "decide:queue-merge" - decisionActionReauthor = "decide:re-author" decisionActionAcceptTriage = "accept-triage" decisionActionHold = "hold" decisionActionRelease = "release" diff --git a/src/pkg/dashboard/stage_tracker_decision_human_merge.go b/src/pkg/dashboard/stage_tracker_decision_human_merge.go index 9c710a2d10..de31729acd 100644 --- a/src/pkg/dashboard/stage_tracker_decision_human_merge.go +++ b/src/pkg/dashboard/stage_tracker_decision_human_merge.go @@ -91,7 +91,7 @@ func decisionForHumanMerge(it StageTrackerItem, held bool) *StageTrackerDecision delegate := decisionDelegateOption(held, "Hive explains and recommends; merges nothing") d.Options = decisionHumanMergeLeadOptions(mergeNow, queue) if it.DCOUnsigned > 0 { - d.Options = append(d.Options, decisionReauthorOption(it, ref, held)) + d.Options = append(d.Options, decisionAdoptSignedOption(it, ref, held)) } d.Options = append(d.Options, delegate, direction, closeSup, closeWontfix, decisionHoldOption(held)) return d @@ -182,7 +182,7 @@ func decisionDCOBlocker(it StageTrackerItem) string { if it.DCOUnsigned <= 0 { return "" } - return fmt.Sprintf("%d of %s no Signed-off-by, so a required DCO check refuses the merge. Re-author as hive PR is the separate choice for that; an Approve never re-authors by itself.", + return fmt.Sprintf("%d of %s no Signed-off-by, so a required DCO check refuses the merge. Adopt as hive PR is the separate choice for that; an Approve never re-authors by itself.", it.DCOUnsigned, pluralCommitsHave(it.DCOTotal)) } @@ -203,19 +203,19 @@ func pluralCommitsHave(total int) string { return "its commits have" } -// decisionReauthorOption is the operator's explicit "re-author as hive PR" +// decisionAdoptSignedOption is the operator's explicit "adopt as hive PR" // choice (hivecommons/hive#15136): the hive re-homes the commits on a // hive-owned, signed-off branch and opens a superseding PR. A person's PR -// is never re-authored by the hive, so for a human author the option is +// is never adopted by the hive, so for a human author the option is // shown disabled with the step that does unblock it. -func decisionReauthorOption(it StageTrackerItem, ref string, held bool) StageTrackerDecisionOption { - o := decisionOption(decisionActionReauthor, "Re-author as hive PR", !held && it.AuthorKind != authorKindHuman, "Release the hold first") +func decisionAdoptSignedOption(it StageTrackerItem, ref string, held bool) StageTrackerDecisionOption { + o := decisionOption(decisionActionAdopt, "Adopt as hive PR", !held && it.AuthorKind != authorKindHuman, "Release the hold first") if it.AuthorKind == authorKindHuman { who := "the author" if it.Author != "" { who = "@" + it.Author } - o.ReasonIfDisabled = "Hive does not re-author a person's PR; ask " + who + " to sign off and push" + o.ReasonIfDisabled = "Hive does not adopt a person's PR; ask " + who + " to sign off and push" } o.Consequence = "Hive reopens " + ref + " as a signed-off hive PR; nothing is merged as-is" return o diff --git a/src/pkg/dashboard/stage_tracker_decision_pr.go b/src/pkg/dashboard/stage_tracker_decision_pr.go index 438c0e3639..0ee6c76d32 100644 --- a/src/pkg/dashboard/stage_tracker_decision_pr.go +++ b/src/pkg/dashboard/stage_tracker_decision_pr.go @@ -91,7 +91,7 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel if finding := decisionFixerExhaustedFinding(it, verdict); finding != "" { d.Question += ": " + finding } - d.Question += ". Re-author it from scratch, hand it to a person, or close it as not planned?" + d.Question += ". Give direction, hand it to a person, or close it as not planned?" case verdict != nil && decisionFirstNonEmpty(verdict.HumanSummaries) != "": d.AskedBy = decisionAskedByReviewer d.Question = "A reviewer handed this to a person: " + decisionFirstNonEmpty(verdict.HumanSummaries) @@ -190,7 +190,7 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel d.Options = slices.Insert(d.Options, 0, decisionOption(decisionActionAdopt, rebasemerge.OptionAdoptFreshLabel, true, "")) } if fixerExhausted { - d.Options = decisionLeadWithReauthor(d.Options) + d.Options = decisionLeadFixerExhausted(d.Options, it) } if selfHold != nil { // Release leads: it is the one action that answers the question. @@ -269,25 +269,29 @@ func decisionLeadWithCloseSuperseded(opts []StageTrackerDecisionOption, redundan return out } -// decisionLeadWithReauthor puts "Re-author" at the front of opts (the lead -// action for a fixer-exhausted PR, hivecommons/hive#15744) and relabels the -// won't-fix close as "Close as not planned" so it stays in the Decide… -// submenu rather than leading a destructive answer. -func decisionLeadWithReauthor(opts []StageTrackerDecisionOption) []StageTrackerDecisionOption { - lead := decisionOption(decisionActionReauthor, "Re-author", true, "") - lead.Consequence = "The hive opens a fresh PR for the same issue from the current base and closes this one as superseded." +// decisionLeadFixerExhausted shapes the options for a fixer-exhausted PR. +// The hive re-authors its own exhausted PR by itself (once per issue; see +// automerge's reauthorExhaustedHivePR), so no "re-author" answer is +// offered here: a person gives direction (the lead), hands it to someone, +// or closes it as not planned. A contributor's PR may instead be adopted. +func decisionLeadFixerExhausted(opts []StageTrackerDecisionOption, it StageTrackerItem) []StageTrackerDecisionOption { + lead := decisionOption(decisionActionDirection, "Give direction", true, "") + lead.Consequence = "Tell the hive what to change; its next attempt starts from your words instead of the reviewer's." lead.Lead = true - out := make([]StageTrackerDecisionOption, 0, len(opts)+1) + out := make([]StageTrackerDecisionOption, 0, len(opts)+2) out = append(out, lead) + if it.AuthorKind != authorKindHive && it.AuthorKind != authorKindHuman { + adopt := decisionOption(decisionActionAdopt, "Adopt as hive PR", true, "") + adopt.Consequence = "The hive opens a fresh PR for the same issue from the current base and closes this one as superseded." + out = append(out, adopt) + } for _, o := range opts { switch o.Action { - case decisionActionReauthor: + case decisionActionDirection, decisionActionAdopt: continue case decisionActionCloseWontfix: o.Label = "Close as not planned" o.Consequence = "Closes this PR as not planned; the issue stays open for someone else." - case decisionActionDirection: - o.Consequence = "Hands the PR to a person: say who takes it or what to change; the hive steps back." } out = append(out, o) } diff --git a/src/pkg/dashboard/stage_tracker_decision_test.go b/src/pkg/dashboard/stage_tracker_decision_test.go index db4d3db391..4f0dc42650 100644 --- a/src/pkg/dashboard/stage_tracker_decision_test.go +++ b/src/pkg/dashboard/stage_tracker_decision_test.go @@ -372,15 +372,15 @@ func TestStageTrackerDecisionForHumanMerge(t *testing.T) { // presses Approve and offers re-authoring as its own choice; once a // person approved, the row says who admitted the head and the second // Approve is no longer offered. - t.Run("unsigned commits warn before acting and offer re-author", func(t *testing.T) { + t.Run("unsigned commits warn before acting and offer adopt", func(t *testing.T) { agent := it agent.Author, agent.AuthorKind, agent.DCOUnsigned, agent.DCOTotal = "hive[bot]", "hive", 2, 3 d := stageTrackerDecisionNeeded(agent, nil, "") - if !strings.Contains(d.Detail, "2 of 3 commits have no Signed-off-by") || !strings.Contains(d.Detail, "Re-author as hive PR is the separate choice") { + if !strings.Contains(d.Detail, "2 of 3 commits have no Signed-off-by") || !strings.Contains(d.Detail, "Adopt as hive PR is the separate choice") { t.Fatalf("details lack the DCO warning: %q", d.Detail) } - if got := []string{d.Options[0].Action, d.Options[1].Action, d.Options[2].Action}; got[2] != decisionActionReauthor || got[0] != decisionActionQueueMerge || got[1] != decisionActionMergeNow { - t.Fatalf("options = %v, want queue-merge, merge-now, re-author", got) + if got := []string{d.Options[0].Action, d.Options[1].Action, d.Options[2].Action}; got[2] != decisionActionAdopt || got[0] != decisionActionQueueMerge || got[1] != decisionActionMergeNow { + t.Fatalf("options = %v, want queue-merge, merge-now, adopt", got) } for _, a := range []string{decisionActionMergeNow, decisionActionQueueMerge} { if o := decisionOptionByAction(t, d, a); !o.Enabled || !strings.Contains(o.Consequence, "no Signed-off-by") { @@ -388,17 +388,17 @@ func TestStageTrackerDecisionForHumanMerge(t *testing.T) { } } re := d.Options[2] - if !re.Enabled || re.Label != "Re-author as hive PR" || !strings.Contains(re.Consequence, "nothing is merged as-is") { + if !re.Enabled || re.Label != "Adopt as hive PR" || !strings.Contains(re.Consequence, "nothing is merged as-is") { t.Fatalf("re-author = %+v", re) } human := it human.DCOUnsigned, human.DCOTotal = 1, 1 d = stageTrackerDecisionNeeded(human, nil, "") - if o := decisionOptionByAction(t, d, decisionActionReauthor); o.Enabled || !strings.Contains(o.ReasonIfDisabled, "@Karibhou to sign off") { + if o := decisionOptionByAction(t, d, decisionActionAdopt); o.Enabled || !strings.Contains(o.ReasonIfDisabled, "@Karibhou to sign off") { t.Fatalf("re-author on a person's PR = %+v", o) } - if d := stageTrackerDecisionNeeded(it, nil, ""); decisionHasAction(d, decisionActionReauthor) { - t.Fatalf("re-author offered without unsigned commits: %+v", d.Options) + if d := stageTrackerDecisionNeeded(it, nil, ""); decisionHasAction(d, decisionActionAdopt) { + t.Fatalf("adopt offered without unsigned commits: %+v", d.Options) } }) diff --git a/src/pkg/dashboard/stage_tracker_fixer_test.go b/src/pkg/dashboard/stage_tracker_fixer_test.go index d5be8979ea..c1baecb5e2 100644 --- a/src/pkg/dashboard/stage_tracker_fixer_test.go +++ b/src/pkg/dashboard/stage_tracker_fixer_test.go @@ -64,32 +64,44 @@ func TestStageTrackerFixerExhaustedCaption(t *testing.T) { } } -func TestDecisionForPRFixerExhaustedLeadsWithReauthor(t *testing.T) { +// The hive re-authors its own exhausted PR by itself, so the 085 card on a +// hive-authored PR never offers "re-author": Give direction leads, close +// reads "not planned". A contributor clanker's PR gets Adopt instead. +func TestDecisionForPRFixerExhaustedNoReauthorOnHivePR(t *testing.T) { it := StageTrackerItem{ Repo: "hivecommons/hive", Number: 15308, Kind: "pr", Stage: trackerNumberNeedsDecision, AuthorKind: authorKindHive, Reason: stagelabels.FixerExhaustedReason(6), } d := decisionForPR(it, &review.Aggregate{HumanSummaries: []string{"tests fail on arm64"}}, "", false) - if d == nil || !strings.Contains(d.Question, "6 attempts") || !strings.Contains(d.Question, "tests fail on arm64") { + if d == nil || !strings.Contains(d.Question, "6 attempts") || !strings.Contains(d.Question, "tests fail on arm64") || strings.Contains(d.Question, "Re-author") { t.Fatalf("decision = %+v", d) } - if len(d.Options) == 0 || d.Options[0].Action != decisionActionReauthor || !d.Options[0].Lead || !d.Options[0].Enabled { + if len(d.Options) == 0 || d.Options[0].Action != decisionActionDirection || !d.Options[0].Lead || !d.Options[0].Enabled { t.Fatalf("lead option = %+v", d.Options) } var sawClose bool for i, o := range d.Options { + if o.Action == "decide:re-author" || o.Action == decisionActionAdopt { + t.Fatalf("hive-authored PR offered %q at %d: %+v", o.Action, i, d.Options) + } + if o.Action == decisionActionDirection && i != 0 { + t.Fatalf("duplicate direction option at %d: %+v", i, d.Options) + } if o.Action == decisionActionCloseWontfix { sawClose = true if i == 0 || o.Lead || o.Label != "Close as not planned" { t.Fatalf("close option = %+v at %d", o, i) } } - if o.Action == decisionActionReauthor && i != 0 { - t.Fatalf("duplicate re-author option at %d: %+v", i, d.Options) - } } if !sawClose { t.Fatalf("no close-as-not-planned option: %+v", d.Options) } + agent := it + agent.AuthorKind, agent.Author = authorKindClanker, "thatguywob" + d = decisionForPR(agent, nil, "", false) + if len(d.Options) < 2 || d.Options[0].Action != decisionActionDirection || d.Options[1].Action != decisionActionAdopt || d.Options[1].Label != "Adopt as hive PR" { + t.Fatalf("contributor options = %+v", d.Options) + } } diff --git a/src/pkg/dashboard/stage_tracker_lead_action_test.go b/src/pkg/dashboard/stage_tracker_lead_action_test.go index aec72941eb..de9a82eb87 100644 --- a/src/pkg/dashboard/stage_tracker_lead_action_test.go +++ b/src/pkg/dashboard/stage_tracker_lead_action_test.go @@ -91,24 +91,26 @@ assert.strictEqual(leads[1].target, human, 'delegate carries the decide target') assert.strictEqual(leads[1].enabled, true); // The parked issue whose lead already is delegate: one pill, never two. assert.strictEqual(stageTrackerLeadActionsOnRow(parked, ctx).length, 1); -// A Re-author lead (the #16456 row): both pills, delegate disabled with its -// reason for a reader. -const reauthor = { ...human, number: 16456, decision_needed: { question: 'Changes requested', options: [{ action: 'decide:re-author', label: 'Re-author', enabled: true, lead: true }, { action: 'decide:delegate', label: 'Let hive decide', enabled: true }] } }; +// A Give-direction lead (the #16456 row, a hive-authored PR whose fixer +// gave up — the hive re-authors those itself, so no re-author pill is +// offered): both pills, delegate disabled with its reason for a reader. +const reauthor = { ...human, number: 16456, decision_needed: { question: 'Changes requested', options: [{ action: 'decide:direction', label: 'Give direction', enabled: true, lead: true, consequence: 'Tell the hive what to change; its next attempt starts from your words.' }, { action: 'decide:delegate', label: 'Let hive decide', enabled: true }] } }; h = stageTrackerLeadActionHtml(reauthor, ctx); assert.strictEqual(buttons(h), 2, h); -assert.strictEqual(labelOf(h), 'Re-author', h); +assert.strictEqual(labelOf(h), 'Give direction', h); +assert.ok(!h.includes('re-author'), 'no re-author pill on a hive-authored row: ' + h); assert.ok(h.includes('data-ham-act="decide:delegate"'), h); -// Owner on that row: "Re-author" read as a record of what happened — the +// Owner on that row: the lead read as a record of what happened — the // action pills and the record pills ("adopted from #N", the base branch) // wore the same outline. Inline actions are