Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-085-row-approved-head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The Activity monitor's 085 row no longer asks for an approval the head already has. The stage pass now records the trusted merger's approval of the head on the stage record, and the row reads it at 085 (where the stage reason carries no `:human-approved@` suffix): the decision popover skips the reviewer question that approval answered and shows the real blocker (for example a fork-guard check), and Approve is disabled with "@login already approved this head" except on a sentinel alert, where Approve still clears the label (follow-up to #18849).
83 changes: 83 additions & 0 deletions src/pkg/dashboard/stage_tracker_085_approved_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package dashboard

import (
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stagelabels"
)

// projectbluefin/utah-packages#1013 (11-18): parked at 085 on
// `fork-guard:Canary` with a head a trusted maintainer approved on GitHub.
// The row kept asking the reviewer's requires_human question that approval
// answered, and offered Approve, because the dashboard learned the
// approver only from the `:human-approved@` reason suffix, written at 090
// (the follow-up noted on hivecommons/hive#18849). With the approver on
// the row the question is the real blocker and Approve says why it is off.
func TestDecisionForPRApprovedHeadAt085(t *testing.T) {
verdict := &review.Aggregate{DecisionQuestion: "security requires human: permission-actions: write on the merge-robot token"}
it := StageTrackerItem{Repo: "acme/widget", Number: 1013, Kind: "pr", Stage: trackerNumberNeedsDecision, Head: "4b9cac9c10ec", Reason: "fork-guard:Canary"}

plain := decisionForPR(it, verdict, "", false)
if plain.AskedBy != decisionAskedByReviewer || !strings.Contains(plain.Question, "merge-robot token") || !approveEnabled(t, plain) {
t.Fatalf("no approval on record: decision = %+v", plain)
}

it.HumanApprover = "octocat"
d := decisionForPR(it, verdict, "", false)
if d.AskedBy != decisionAskedByLane || !strings.HasPrefix(d.Question, "CI will not run for this fork PR (Canary)") {
t.Fatalf("approved head re-asked the answered question: %+v", d)
}
for _, o := range d.Options {
if o.Action == decisionActionApprove && (o.Enabled || !strings.Contains(o.ReasonIfDisabled, "@octocat already approved this head")) {
t.Fatalf("approve option = %+v, want disabled naming the approver", o)
}
}

// A sentinel alert keeps Approve: on the row it also clears the label.
it.SentinelAlert = true
if s := decisionForPR(it, verdict, "sentinel-alert", false); !approveEnabled(t, s) {
t.Fatalf("sentinel row lost Approve: %+v", s.Options)
}
}

func approveEnabled(t *testing.T, d *StageTrackerDecision) bool {
t.Helper()
for _, o := range d.Options {
if o.Action == decisionActionApprove {
return o.Enabled
}
}
t.Fatal("no Approve option")
return false
}

// End to end: the approval the stage pass recorded for the head reaches the
// 085 row; a later head does not inherit it.
func TestStageTrackerApprovedHeadAt085(t *testing.T) {
now := time.Date(2026, 11, 18, 11, 40, 0, 0, time.UTC)
s, store := stageTrackerFixture(t, now)
key := stagelabels.Key("acme/console", 1013)
store.ObserveHead(key, "head-approved", stagelabels.NeedsDecision, "fork-guard:Canary")
store.NoteHeadApproval(key, "head-approved", "@octocat")
s.statusMu.Lock()
s.status.Repos[0].OpenPrs = append(s.status.Repos[0].OpenPrs,
FrontendPR{PullRequest: github.PullRequest{Number: 1013, Title: "refresh outdated daily package updates", Author: "pat", HeadSHA: "head-approved", Labels: []string{"stage/085-needs-decision"}}})
s.statusMu.Unlock()
if it := trackerItem(t, s.buildStageTracker(s.status, store, now), "pr", 1013); it.Stage != 85 || it.HumanApprover != "octocat" {
t.Fatalf("row = stage %d approver %q, want 85 octocat", it.Stage, it.HumanApprover)
}

s.statusMu.Lock()
last := len(s.status.Repos[0].OpenPrs) - 1
pr := s.status.Repos[0].OpenPrs[last].(FrontendPR)
pr.HeadSHA = "head-pushed"
s.status.Repos[0].OpenPrs[last] = pr
s.statusMu.Unlock()
if it := trackerItem(t, s.buildStageTracker(s.status, store, now), "pr", 1013); it.HumanApprover != "" {
t.Fatalf("a new head inherited the approval: %q", it.HumanApprover)
}
}
5 changes: 5 additions & 0 deletions src/pkg/dashboard/stage_tracker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
it.Caption = stageTrackerTakeoverCaption(it.Caption, it.Takeover)
}
base, approver := stagelabels.HumanApprovedReason(it.Reason)
if approver == "" && hasRec && stage == stagelabels.NeedsDecision {
// At 085 the reason carries no approver: the stage pass
// records the head's trusted approval on the record instead.
approver = rec.HeadApprover(it.Head)
}
it.HumanApprover = approver
it.ManualMerge = stageTrackerManualMergeReason(base)
if stage == stagelabels.ReadyForHumanMerge {
Expand Down
16 changes: 13 additions & 3 deletions src/pkg/dashboard/stage_tracker_decision_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
// pushed past: the reviewer re-reviews, not the author
// (projectbluefin/chairlift#799).
reReviewers, reReview := stageengineprstage.ParseReReviewRequested(base)
// A trusted merger already approved this head (hivecommons/hive#18849
// follow-up): that approval answers a reviewer's requires_human
// question, so the question is not asked again, and a second Approve
// adds nothing — what holds the PR at 085 is something else.
approvedBy := strings.TrimPrefix(strings.TrimSpace(it.HumanApprover), "@")

// WHAT it is waiting on: the question, most specific source first. A
// reviewer's own question is quoted verbatim — it is the text the
Expand All @@ -67,7 +72,7 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
// class; the caption names which stop, never "needs your decision".
d.AskedBy = decisionAskedByLane
d.Question = "The hive's superseding PR would auto-merge (owner rule), but " + stagelabels.HiveSupersederHardStopProse(hiveSupersederStop) + ". Clear that stop and the lane merges it on its next pass, or close it?"
case verdict != nil && strings.TrimSpace(verdict.DecisionQuestion) != "":
case approvedBy == "" && verdict != nil && strings.TrimSpace(verdict.DecisionQuestion) != "":
d.AskedBy = decisionAskedByReviewer
d.Question = strings.TrimSpace(verdict.DecisionQuestion)
if !verdict.RecordedAt.IsZero() {
Expand Down Expand Up @@ -113,14 +118,14 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
}
}
d.Question += ". Fix it on the base branch, merge it as is, or close it?"
case verdict != nil && decisionFirstNonEmpty(verdict.HumanSummaries) != "":
case approvedBy == "" && verdict != nil && decisionFirstNonEmpty(verdict.HumanSummaries) != "":
d.AskedBy = decisionAskedByReviewer
d.Question = "A reviewer handed this to a person: " + decisionFirstNonEmpty(verdict.HumanSummaries)
if !verdict.RecordedAt.IsZero() {
t := verdict.RecordedAt
d.Since = &t
}
case reviewerDeferred:
case approvedBy == "" && reviewerDeferred:
d.AskedBy = decisionAskedByReviewer
d.Question = "A reviewer handed this PR to a person without a specific question. Merge it as is, give direction, or close it?"
case sentinel:
Expand Down Expand Up @@ -192,6 +197,11 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel
d.Blocker = "The review found: " + strings.TrimSpace(verdict.DecisionFinding) + ". " + d.Blocker
}
}
if approvedBy != "" && approveOK && !sentinel {
// A sentinel alert keeps Approve: on this row it also clears the
// alert's label in the same click.
approveOK, approveWhy = false, "@"+approvedBy+" already approved this head on GitHub; another approval does not clear what holds it here."
}
if held && selfHold == nil {
if d.Blocker != "" {
d.Blocker += " "
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,12 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error)
// list "PRs returned to this contributor" from the store alone.
store.NoteAuthor(key, obs.Author)
store.NoteHold(key, obs.Hold)
// The head's trusted approval, for the Activity monitor's 085
// row (hivecommons/hive#18849 follow-up): the reason carries no
// approver there.
if obs.Detail.HumanApprovalHead == obs.HeadSHA {
store.NoteHeadApproval(key, obs.HeadSHA, obs.Detail.HumanApprover)
}
soakFirstGreen, _ := c.contributorSoak.FirstGreen(obs.Owner, obs.Repo, obs.Number, obs.HeadSHA)
noteSoak(store, key, obs.Reason, obs.HeadSHA, pass.Route, c.currentContributorLanePolicy().Soak, soakFirstGreen, now)
if dcoRead {
Expand Down
38 changes: 38 additions & 0 deletions src/pkg/stagelabels/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ type Record struct {
AdmittedHead string `json:"admitted_head,omitempty"`
AdmittedBy string `json:"admitted_by,omitempty"`
AdmittedAt time.Time `json:"admitted_at,omitempty"`
// ApprovedHead / ApprovedBy record the trusted merger whose GitHub
// approval the stage pass found on a head (a lane noted it, or the
// 085 route read it, hivecommons/hive#18849). It is display evidence
// only, not a trust override like AdmittedBy: the Activity monitor reads
// it at 085, where the stage reason carries no `:human-approved@`
// suffix, so the row does not ask for the approval again. A new head
// makes it stale; HeadApprover checks the head.
ApprovedHead string `json:"approved_head,omitempty"`
ApprovedBy string `json:"approved_by,omitempty"`
// AdoptForcedBy / AdoptForcedAt record an operator's "Adopt now": the
// login that forced adoption and when. The next sweep adopts by
// supersession at once, regardless of the author's presence and of
Expand Down Expand Up @@ -3010,6 +3019,35 @@ func (s *Store) NoteAuthor(key, login string) {
s.dirty = true
}

// NoteHeadApproval records that login, a trusted merger, approved head on
// an existing record (Record.ApprovedHead). An empty head or login is a
// no-op: a pass that did not read the approval says nothing about it.
func (s *Store) NoteHeadApproval(key, head, login string) {
head, login = strings.TrimSpace(head), strings.TrimPrefix(strings.TrimSpace(login), "@")
if head == "" || login == "" {
return
}
s.mu.Lock()
defer s.mu.Unlock()
r, ok := s.items[key]
if !ok || (r.ApprovedHead == head && r.ApprovedBy == login) {
return
}
r.ApprovedHead, r.ApprovedBy = head, login
s.items[key] = r
s.dirty = true
}

// HeadApprover is the trusted merger recorded as having approved head
// (NoteHeadApproval), or "" when none is recorded for that head.
func (r Record) HeadApprover(head string) string {
head = strings.TrimSpace(head)
if head == "" || !strings.EqualFold(r.ApprovedHead, head) {
return ""
}
return r.ApprovedBy
}

// NoteSoak records the soak the lane holds an existing record's head for:
// head must sit unchanged from startedAt for window. A head of "" or a
// window of 0 clears the soak (the PR is not soaking).
Expand Down
22 changes: 22 additions & 0 deletions src/pkg/stagelabels/store_head_approval_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package stagelabels

import (
"testing"
)

func TestStoreNoteHeadApproval(t *testing.T) {
s := NewStore("", nil)
key := Key("acme/widget", 7)
s.NoteHeadApproval(key, "h1", "octocat")
if _, ok := s.Get(key); ok {
t.Fatal("NoteHeadApproval created a record")
}
s.Observe(key, NeedsDecision, "fork-guard:Canary")
s.NoteHeadApproval(key, "h1", "@octocat")
s.NoteHeadApproval(key, "", "someone")
s.NoteHeadApproval(key, "h1", "")
rec, _ := s.Get(key)
if rec.HeadApprover("h1") != "octocat" || rec.HeadApprover("H1") != "octocat" || rec.HeadApprover("h2") != "" || rec.HeadApprover("") != "" {
t.Fatalf("record = %q@%q", rec.ApprovedBy, rec.ApprovedHead)
}
}
Loading