diff --git a/changelog.d/fixed-one-unblock-notice.md b/changelog.d/fixed-one-unblock-notice.md new file mode 100644 index 0000000000..5c9a02c2ae --- /dev/null +++ b/changelog.d/fixed-one-unblock-notice.md @@ -0,0 +1 @@ +- A lifted block gets one "Unblocked" note, and it no longer calls an un-admitted issue actionable. On projectbluefin/website#987 the review-backlog reconciler posted "Unblocked: …#986 merged … This item is actionable now" and, 8 seconds later, the blocked sweep posted "Unblocked: …#986 is no longer open; re-triaging." The issue had no `triage/accepted`, so neither was true. Whichever path runs second now sees the first one's note for the same PR and stays quiet. On an issue `project.issue_filter` does not admit, the note says "Unblocked — waiting for a maintainer to admit it" and names the label that admits it. diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index f09c582fe3..d18325ae53 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -349,7 +349,13 @@ blocked sweep that follows each stage-label sync lifts the label and posts one `` note once the tracked PR is merged or closed, and strips `help wanted` again should the org workflow re-add it while the PR is open. The review backlog applies the same parking itself when it files -a finding whose file does not exist on the reviewed PR's base branch. +a finding whose file does not exist on the reviewed PR's base branch. The +review-backlog reconciler and the blocked sweep can both lift the same block; +whichever runs second sees the first one's note for that PR (newer than the +last blocked-on marker) and posts nothing. On an issue `project.issue_filter` +does not admit (for example no `triage/accepted`), the note says +"Unblocked — waiting for a maintainer to admit it" and names the label that +admits it, instead of "actionable now" or "re-triaging". A posted comment is the agent's **start signal** on that issue only when it says work is starting. The hub records a 2h agent claim the first time the diff --git a/src/docs/labels-and-control-signals/reference.md b/src/docs/labels-and-control-signals/reference.md index d7137adb08..ab6fa53150 100644 --- a/src/docs/labels-and-control-signals/reference.md +++ b/src/docs/labels-and-control-signals/reference.md @@ -306,7 +306,7 @@ With the marker, the activity monitor's pill reads `blocked on #N`, links the PR **Checked by:** Enumeration, stage derivation, claim gate, review backlog, blocked sweep. **When:** Review backlog filing; blocked-on comment relay. -**Release or override.** The blocked sweep after each stage-label sync removes it, with one `` note, once the tracked PR is merged or closed, or once a recheck-after deadline passes (`deadline passed; re-triaging`) unless the body also carries ``. An ops-tracking issue on the hive's own project keeps `blocked` once its deadline passes and instead gets soak triage: the hub's `/api/hub/hives` (or, with no hub, the spoke's own `/api/version`) is probed for every `stable`-channel hive (fresh heartbeat, no restart loop, running the candidate `sha256:` digest or `v5 ` named in the body), ONE `` comment is posted, only the checklist lines that evidence proves are ticked, and `` is appended to the body so the sweep does not repeat ([#13311](https://github.com/hivecommons/hive/issues/13311)); a human may remove it at any time. +**Release or override.** The blocked sweep after each stage-label sync removes it, with one `` note (none when the review-backlog reconciler already noted the lift for the same PR; "waiting for a maintainer to admit it" on an issue `project.issue_filter` does not admit), once the tracked PR is merged or closed, or once a recheck-after deadline passes (`deadline passed; re-triaging`) unless the body also carries ``. An ops-tracking issue on the hive's own project keeps `blocked` once its deadline passes and instead gets soak triage: the hub's `/api/hub/hives` (or, with no hub, the spoke's own `/api/version`) is probed for every `stable`-channel hive (fresh heartbeat, no restart loop, running the candidate `sha256:` digest or `v5 ` named in the body), ONE `` comment is posted, only the checklist lines that evidence proves are ticked, and `` is appended to the body so the sweep does not repeat ([#13311](https://github.com/hivecommons/hive/issues/13311)); a human may remove it at any time. The hard-suppress reconcile (#12002) can also lift a Hive-applied `blocked` after a referencing PR merges, but only when the newest label event was by the App bot; human-applied or re-applied labels are not lifted. It posts ``. diff --git a/src/pkg/github/issue_blocked.go b/src/pkg/github/issue_blocked.go index 2b43929c0e..9e72e87870 100644 --- a/src/pkg/github/issue_blocked.go +++ b/src/pkg/github/issue_blocked.go @@ -498,7 +498,7 @@ func (c *Client) reconcileBlockedTargets(ctx context.Context, targets []blockedI logger.Warn("blocked sweep: unblock failed", "repo", t.repo, "issue", t.number, "error", err) continue } - note := blockedUnblockedMarker + fmt.Sprintf("\nUnblocked: %s#%d (superseding #%d) is no longer open. This issue is actionable again.", prRepo, supersededBy, prNumber) + note := blockedSupersededSettledNote(prRepo, supersededBy, prNumber, c.unblockAdmission(t.labels)) c.postUnblockedNote(ctx, t.repo, t.number, note, logger) res.Unblocked++ logger.Info("blocked sweep: issue unblocked", "repo", t.repo, "issue", t.number, "pr", prRepo+"#"+strconv.Itoa(supersededBy), "superseded", prNumber) @@ -542,7 +542,7 @@ func (c *Client) reconcileBlockedTargets(ctx context.Context, targets []blockedI logger.Warn("blocked sweep: unblock failed", "repo", t.repo, "issue", t.number, "error", err) continue } - note := blockedPRSettledNote(prRepo + "#" + strconv.Itoa(prNumber)) + note := blockedPRSettledNote(prRepo+"#"+strconv.Itoa(prNumber), c.unblockAdmission(t.labels)) c.postUnblockedNote(ctx, t.repo, t.number, note, logger) res.Unblocked++ logger.Info("blocked sweep: issue unblocked", "repo", t.repo, "issue", t.number, "pr", prRepo+"#"+strconv.Itoa(prNumber)) @@ -622,10 +622,90 @@ const blockedMarkerlessNote = blockedUnblockedMarker + "\nUnblocked: the `blocke // blockedPRSettledNote is the note posted when the PR a blocked issue // waited on (pr, "owner/repo#N") has merged or closed. -func blockedPRSettledNote(pr string) string { +func blockedPRSettledNote(pr, admission string) string { + if admission != "" { + return blockedUnblockedMarker + "\nUnblocked: " + pr + " is no longer open. Unblocked — waiting for a maintainer to admit it: " + admission + } return blockedUnblockedMarker + "\nUnblocked: " + pr + " is no longer open; re-triaging." } +// blockedSupersededSettledNote is the note posted when the PR that superseded +// an issue's blocker is no longer open either. +func blockedSupersededSettledNote(prRepo string, supersededBy, prNumber int, admission string) string { + lead := blockedUnblockedMarker + fmt.Sprintf("\nUnblocked: %s#%d (superseding #%d) is no longer open.", prRepo, supersededBy, prNumber) + if admission != "" { + return lead + " Unblocked — waiting for a maintainer to admit it: " + admission + } + return lead + " This issue is actionable again." +} + +// unblockAdmission is "" when project.issue_filter admits an issue with +// these labels once `blocked` is gone; otherwise the sentence an unblock note +// ends with instead of "actionable": nothing works an un-admitted issue +// until a maintainer admits it (projectbluefin/website#987 had no +// triage/accepted and was told it was actionable). +func (c *Client) unblockAdmission(labels []string) string { + after := make([]string, 0, len(labels)) + for _, l := range labels { + if !strings.EqualFold(strings.TrimSpace(l), BlockedLabel) { + after = append(after, l) + } + } + filter := c.getIssueFilter() + if filter.Admits(after) { + return "" + } + var required []string + if notice, ok := filter.(IssueFilterNoticeConfig); ok { + required = notice.RequireLabelsForNotice() + } + const lead = "`project.issue_filter` admits " + switch len(required) { + case 0: + return lead + "only issues carrying one of its required labels, and a maintainer adding one admits this one." + case 1: + return lead + "only issues labelled " + quoteLabels(required) + ", and a maintainer adding it admits this one." + default: + return lead + "only issues carrying one of " + quoteLabels(required) + ", and a maintainer adding one admits this one." + } +} + +// unblockNoteRefRE reads the PR an unblock note is about: "Unblocked: +// owner/repo#N …" or "Unblocked: source PR owner/repo#N …". +var unblockNoteRefRE = regexp.MustCompile(`Unblocked: (?:source PR )?([\w.-]+/[\w.-]+)#(\d+)\b`) + +// unblockAlreadyNoted reports whether an unblock note about the same PR as +// note is already on the issue, newer than the newest blocked-on marker +// comment: the block on that PR was lifted already, by the other sweep or an +// earlier pass. projectbluefin/website#987 got the review-backlog sweep's +// "merged … actionable now" and, 8s later, the blocked sweep's "no longer +// open; re-triaging" for the same #986. A note naming no PR (deadline, +// marker-less) is never matched here. +func unblockAlreadyNoted(comments []*gh.IssueComment, note string) bool { + m := unblockNoteRefRE.FindStringSubmatch(note) + if m == nil { + return false + } + short := m[1] + if i := strings.LastIndex(short, "/"); i >= 0 { + short = short[i+1:] + } + same := regexp.MustCompile(`(?i)Unblocked: (?:source PR )?(?:[\w.-]+/)?` + regexp.QuoteMeta(short) + `#` + m[2] + `\b`) + for i := len(comments) - 1; i >= 0; i-- { + body := comments[i].GetBody() + if strings.Contains(body, blockedUnblockedMarker) { + if same.MatchString(body) { + return true + } + continue + } + if _, _, ok := ParseBlockedOnMarker(body); ok { + return false + } + } + return false +} + // blockedLabelActor returns the login that most recently applied `blocked` // to the issue, per its timeline; found is false when no labeled event // names the label. @@ -717,6 +797,11 @@ func (c *Client) postUnblockedNote(ctx context.Context, repo string, number int, return } } + if unblockAlreadyNoted(comments, note) { + logger.Info("blocked sweep: the block on this PR was already lifted with a note; not posting a second", "repo", repo, "issue", number) + c.noteCommentSuppressed() + return + } // The attention pilot folds dependency progress into the issue's // status card whatever github.notifications.mode says. if c.notificationsQuiet() || c.attentionPilot() { diff --git a/src/pkg/github/issue_unblock_once_test.go b/src/pkg/github/issue_unblock_once_test.go new file mode 100644 index 0000000000..6af8201990 --- /dev/null +++ b/src/pkg/github/issue_unblock_once_test.go @@ -0,0 +1,309 @@ +package github + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/config" +) + +// projectbluefin/website#987 (11-03): the review-backlog sweep posted +// "Unblocked: projectbluefin/website#986 merged … actionable now" at +// 23:11:13Z and the blocked sweep "Unblocked: projectbluefin/website#986 is +// no longer open; re-triaging." at 23:11:21Z. The issue had no +// triage/accepted, so neither could be worked. + +func commentsOf(bodies ...string) []*gh.IssueComment { + out := make([]*gh.IssueComment, 0, len(bodies)) + for _, b := range bodies { + out = append(out, &gh.IssueComment{Body: gh.Ptr(b)}) + } + return out +} + +func TestUnblockAlreadyNoted(t *testing.T) { + lift := reviewBacklogLiftNote("projectbluefin/website", 986, "") + settled := blockedPRSettledNote("projectbluefin/website#986", "") + retriage := reviewBacklogRetriageNote("projectbluefin/website", 986, "") + reblock := BlockedOnMarker("projectbluefin/website", 986) + "\nBlocked on #986 again." + for _, tc := range []struct { + name string + comments []*gh.IssueComment + note string + want bool + }{ + {name: "website#987: the sweep after the review-backlog lift", comments: commentsOf("triage", lift), note: settled, want: true}, + {name: "the review-backlog lift after the sweep", comments: commentsOf(settled), note: lift, want: true}, + {name: "retriage note names the PR too", comments: commentsOf(retriage), note: settled, want: true}, + {name: "short repo name in one, full in the other", comments: commentsOf(blockedPRSettledNote("website#986", "")), note: lift, want: true}, + {name: "a different PR", comments: commentsOf(lift), note: blockedPRSettledNote("projectbluefin/website#98", ""), want: false}, + {name: "blocked again after the lift", comments: commentsOf(lift, reblock), note: settled, want: false}, + {name: "first lift", comments: commentsOf(reblock), note: settled, want: false}, + {name: "a note naming no PR is never matched", comments: commentsOf(blockedDeadlineNote("2026-11-01T00:00:00Z")), note: blockedDeadlineNote("2026-11-02T00:00:00Z"), want: false}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := unblockAlreadyNoted(tc.comments, tc.note); got != tc.want { + t.Fatalf("unblockAlreadyNoted = %v, want %v", got, tc.want) + } + }) + } +} + +// unblockServer serves issue comments and records label deletes and posted +// comments. +type unblockServer struct { + mu sync.Mutex + comments map[string]string + deleted []string + posted map[string]string +} + +func (u *unblockServer) handler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + u.mu.Lock() + defer u.mu.Unlock() + switch { + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/website/pulls/986": + _, _ = io.WriteString(w, `{"number":986,"state":"closed","merged":true,"base":{"ref":"main"}}`) + case r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/comments"): + _, _ = io.WriteString(w, u.comments[r.URL.Path]) + case r.Method == http.MethodGet && strings.HasPrefix(r.URL.Path, "/repos/o/website/issues/"): + _, _ = io.WriteString(w, `{"number":1,"labels":[{"name":"blocked"},{"name":"agent/reviewer"}]}`) + case r.Method == http.MethodDelete: + u.deleted = append(u.deleted, r.URL.Path) + _, _ = io.WriteString(w, `[]`) + case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/comments"): + var body struct { + Body string `json:"body"` + } + _ = json.NewDecoder(r.Body).Decode(&body) + u.posted[r.URL.Path] = body.Body + _, _ = io.WriteString(w, `{"id":9}`) + default: + w.WriteHeader(http.StatusNotFound) + } +} + +func jsonComments(t *testing.T, bodies ...string) string { + t.Helper() + out := make([]map[string]any, 0, len(bodies)) + for i, b := range bodies { + out = append(out, map[string]any{"id": i + 1, "body": b}) + } + data, err := json.Marshal(out) + if err != nil { + t.Fatal(err) + } + return string(data) +} + +// Both lift paths on one item post one notice: the blocked sweep stays quiet +// on #987 (the review-backlog lift is there) and speaks on #988 (it is not). +func TestBlockedSweepQuietAfterReviewBacklogLift(t *testing.T) { + u := &unblockServer{posted: map[string]string{}, comments: map[string]string{ + "/repos/o/website/issues/987/comments": jsonComments(t, reviewBacklogLiftNote("o/website", 986, "")), + "/repos/o/website/issues/988/comments": jsonComments(t, BlockedOnMarker("o/website", 986)+"\nBlocked on #986"), + }} + srv := httptest.NewServer(http.HandlerFunc(u.handler)) + defer srv.Close() + c := testClient(t, srv.URL) + res := c.reconcileBlockedTargets(context.Background(), []blockedIssueTarget{ + {repo: "o/website", number: 987, labels: []string{"blocked"}, reason: "blocked on o/website#986"}, + {repo: "o/website", number: 988, labels: []string{"blocked"}, reason: "blocked on o/website#986"}, + }, nil) + if res.Unblocked != 2 { + t.Fatalf("result = %+v, want both labels lifted", res) + } + u.mu.Lock() + defer u.mu.Unlock() + if _, ok := u.posted["/repos/o/website/issues/987/comments"]; ok { + t.Fatalf("#987 got a second unblock note: %q", u.posted["/repos/o/website/issues/987/comments"]) + } + if !strings.Contains(u.posted["/repos/o/website/issues/988/comments"], "Unblocked: o/website#986 is no longer open") { + t.Fatalf("#988 note = %q, want the sweep's note", u.posted["/repos/o/website/issues/988/comments"]) + } +} + +// The other order: the review-backlog lift stays quiet when the blocked +// sweep already noted the same PR. +func TestReviewBacklogLiftQuietAfterSweepNote(t *testing.T) { + u := &unblockServer{posted: map[string]string{}, comments: map[string]string{ + "/repos/o/website/issues/987/comments": jsonComments(t, blockedPRSettledNote("o/website#986", "")), + "/repos/o/website/issues/988/comments": jsonComments(t, "triage"), + }} + srv := httptest.NewServer(http.HandlerFunc(u.handler)) + defer srv.Close() + c := testClient(t, srv.URL) + sink := githubIssueBacklogSink{c: c} + for _, n := range []int{987, 988} { + if err := sink.LiftBlock(context.Background(), "o/website", ReviewBacklogRef{Number: n}, reviewBacklogLiftNote("o/website", 986, "")); err != nil { + t.Fatalf("LiftBlock #%d: %v", n, err) + } + } + u.mu.Lock() + defer u.mu.Unlock() + if len(u.deleted) != 2 { + t.Fatalf("label deletes = %v, want both", u.deleted) + } + if _, ok := u.posted["/repos/o/website/issues/987/comments"]; ok { + t.Fatal("#987 got a second unblock note") + } + if _, ok := u.posted["/repos/o/website/issues/988/comments"]; !ok { + t.Fatal("#988 got no unblock note") + } +} + +// An un-admitted issue is told it waits for a maintainer, not that it is +// actionable; an admitted one keeps today's wording. +func TestUnblockNotesAdmissionAware(t *testing.T) { + c := &Client{} + c.SetIssueFilter(config.IssueFilterConfig{RequireLabels: []string{"triage/accepted"}}) + unadmitted := []string{"blocked", "agent/reviewer"} + admitted := []string{"blocked", "triage/accepted"} + + if got := c.unblockAdmission(admitted); got != "" { + t.Fatalf("admitted issue got an admission sentence: %q", got) + } + adm := c.unblockAdmission(unadmitted) + if !strings.Contains(adm, "`triage/accepted`") || !strings.Contains(adm, "a maintainer adding it admits this one") { + t.Fatalf("admission sentence = %q", adm) + } + for name, note := range map[string]string{ + "review-backlog lift": reviewBacklogLiftNote("o/website", 986, adm), + "review-backlog retriage": reviewBacklogRetriageNote("o/website", 986, adm), + "blocked sweep settled": blockedPRSettledNote("o/website#986", adm), + "blocked sweep superseded": blockedSupersededSettledNote("o/website", 990, 986, adm), + } { + if !strings.Contains(note, "Unblocked — waiting for a maintainer to admit it") || strings.Contains(note, "actionable") || strings.Contains(note, "re-triag") { + t.Errorf("%s note for an un-admitted issue = %q", name, note) + } + if !unblockNoteRefRE.MatchString(note) { + t.Errorf("%s note no longer names its PR for the dedupe: %q", name, note) + } + } + for name, note := range map[string]string{ + "review-backlog lift": reviewBacklogLiftNote("o/website", 986, ""), + "blocked sweep superseded": blockedSupersededSettledNote("o/website", 990, 986, ""), + } { + if !strings.Contains(note, "actionable") { + t.Errorf("%s note for an admitted issue lost its wording: %q", name, note) + } + } +} + +// The review-backlog sweep reads the item's labels for the wording: on a +// GitHub issue without triage/accepted the lift says it waits for a +// maintainer. +func TestReviewBacklogAdmissionReadsTheIssue(t *testing.T) { + u := &unblockServer{posted: map[string]string{}, comments: map[string]string{}} + srv := httptest.NewServer(http.HandlerFunc(u.handler)) + defer srv.Close() + c := testClient(t, srv.URL) + c.SetIssueFilter(config.IssueFilterConfig{RequireLabels: []string{"triage/accepted"}}) + if got := c.reviewBacklogAdmission(context.Background(), githubIssueBacklogSink{c: c}, "o/website", ReviewBacklogRef{Number: 987}); !strings.Contains(got, "`triage/accepted`") { + t.Fatalf("admission = %q, want the triage/accepted sentence", got) + } + if got := c.reviewBacklogAdmission(context.Background(), githubIssueBacklogSink{c: c}, "o/website", ReviewBacklogRef{}); got != "" { + t.Fatalf("no issue number: admission = %q, want \"\"", got) + } +} + +// The blocked sweep words its note from the issue's labels: #989 has no +// triage/accepted, #990 has it. +func TestBlockedSweepNoteNamesAdmission(t *testing.T) { + u := &unblockServer{posted: map[string]string{}, comments: map[string]string{ + "/repos/o/website/issues/989/comments": jsonComments(t, BlockedOnMarker("o/website", 986)+"\nBlocked on #986"), + "/repos/o/website/issues/990/comments": jsonComments(t, BlockedOnMarker("o/website", 986)+"\nBlocked on #986"), + }} + srv := httptest.NewServer(http.HandlerFunc(u.handler)) + defer srv.Close() + c := testClient(t, srv.URL) + c.SetIssueFilter(config.IssueFilterConfig{RequireLabels: []string{"triage/accepted"}}) + c.reconcileBlockedTargets(context.Background(), []blockedIssueTarget{ + {repo: "o/website", number: 989, labels: []string{"blocked", "agent/reviewer"}, reason: "blocked on o/website#986"}, + {repo: "o/website", number: 990, labels: []string{"blocked", "triage/accepted"}, reason: "blocked on o/website#986"}, + }, nil) + u.mu.Lock() + defer u.mu.Unlock() + if n := u.posted["/repos/o/website/issues/989/comments"]; !strings.Contains(n, "waiting for a maintainer to admit it") || strings.Contains(n, "re-triaging") { + t.Fatalf("#989 note = %q, want the admission wording", n) + } + if n := u.posted["/repos/o/website/issues/990/comments"]; !strings.Contains(n, "re-triaging") { + t.Fatalf("#990 note = %q, want today's wording", n) + } +} + +// rejectBlocked admits any issue not labelled `blocked`: the admission check +// must ask about the issue as it is once the block is gone. +type rejectBlocked struct{} + +func (rejectBlocked) Admits(labels []string) bool { return !hasBlockedLabel(labels) } + +func TestUnblockAdmissionIgnoresTheBlockedLabel(t *testing.T) { + c := &Client{} + c.SetIssueFilter(rejectBlocked{}) + if got := c.unblockAdmission([]string{"blocked", "bug"}); got != "" { + t.Fatalf("admission = %q, want \"\": `blocked` is coming off", got) + } +} + +// End to end through the review-backlog sweep on a GitHub-issue item: the +// lift note says the item waits for a maintainer when it is not admitted. +func TestReviewBacklogReconcileLiftNamesAdmission(t *testing.T) { + withReviewBacklogState(t) + var mu sync.Mutex + var posted string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch { + case r.URL.Path == "/repos/o/r/pulls/5": + _, _ = io.WriteString(w, `{"number":5,"state":"closed","merged":true,"base":{"ref":"main"}}`) + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/issues/7": + _, _ = io.WriteString(w, `{"number":7,"labels":[{"name":"blocked"},{"name":"agent/reviewer"}]}`) + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/issues/7/comments": + _, _ = io.WriteString(w, `[]`) + case r.Method == http.MethodDelete: + _, _ = io.WriteString(w, `[]`) + case r.Method == http.MethodPost && r.URL.Path == "/repos/o/r/issues/7/comments": + var body struct { + Body string `json:"body"` + } + _ = json.NewDecoder(r.Body).Decode(&body) + mu.Lock() + posted = body.Body + mu.Unlock() + _, _ = io.WriteString(w, `{"id":9}`) + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer srv.Close() + c := reviewTestClient(t, srv.URL) + c.SetIssueFilter(config.IssueFilterConfig{RequireLabels: []string{"triage/accepted"}}) + sink := githubIssueBacklogSink{c: c} + c.SetReviewBacklogRouting(func() ReviewBacklogRouting { + return ReviewBacklogRouting{Backlog: config.ReviewBacklogConfig{Destination: config.ReviewBacklogGitHubIssue}, Sink: sink} + }) + ledger := newReviewBacklogLedger() + ledger.setFingerprint("o/r", "fp-legacy", reviewBacklogFingerprintRecord{Destination: config.ReviewBacklogGitHubIssue, ItemNumber: 7, ItemKey: "o/r#7", BlockedOnPR: 5, BlockState: reviewBacklogBlockBlocked}) + if err := ledger.save("", time.Now().UTC()); err != nil { + t.Fatal(err) + } + if res := ReconcileReviewBacklogBlocks(context.Background(), c, nil); res.Lifted != 1 || res.Errors != 0 { + t.Fatalf("result = %+v, want one lift", res) + } + mu.Lock() + defer mu.Unlock() + if !strings.Contains(posted, "Unblocked: o/r#5 merged") || !strings.Contains(posted, "waiting for a maintainer to admit it") || strings.Contains(posted, "actionable now") { + t.Fatalf("lift note = %q", posted) + } +} diff --git a/src/pkg/github/review_backlog_blocks.go b/src/pkg/github/review_backlog_blocks.go index 4dec0df216..cc607bb4e1 100644 --- a/src/pkg/github/review_backlog_blocks.go +++ b/src/pkg/github/review_backlog_blocks.go @@ -73,15 +73,42 @@ func blockedOnReviewedPRNote(repo string, pr int) string { return b.String() } -func reviewBacklogLiftNote(repo string, pr int) string { +// reviewBacklogLiftNote is the note on an item whose PR merged with the +// finding's file still on the base. admission is unblockAdmission's +// sentence ("" when the item is admitted): an un-admitted item is not +// "actionable now". +func reviewBacklogLiftNote(repo string, pr int, admission string) string { + if admission != "" { + return fmt.Sprintf("%s\nUnblocked: %s#%d merged and the finding's file is still on the base branch. Unblocked — waiting for a maintainer to admit it: %s Once it is admitted, check the finding still applies first, and close it without a PR if it is already fixed.", blockedUnblockedMarker, repo, pr, admission) + } return fmt.Sprintf("%s\nUnblocked: %s#%d merged and the finding's file is still on the base branch. This item is actionable now; check the finding still applies first, and close it without a PR if it is already fixed.", blockedUnblockedMarker, repo, pr) } -func reviewBacklogRetriageNote(repo string, pr int) string { +func reviewBacklogRetriageNote(repo string, pr int, admission string) string { + if admission != "" { + return fmt.Sprintf("%s\n%s\nUnblocked: source PR %s#%d closed unmerged. Unblocked — waiting for a maintainer to admit it: %s A superseding PR often lands the same lines, so the finding may still apply; close this item only if it no longer does.", blockedUnblockedMarker, reviewBacklogRetriageMarker, repo, pr, admission) + } return fmt.Sprintf("%s\n%s\nUnblocked: source PR %s#%d closed unmerged — re-triage against current base. A superseding PR often lands the same lines, so the finding may still apply; close this item only if it no longer does.", blockedUnblockedMarker, reviewBacklogRetriageMarker, repo, pr) } -// LiftBlock removes `blocked` from the GitHub issue and posts note. +// reviewBacklogAdmission is unblockAdmission for a review-backlog item filed +// as a GitHub issue; "" for other destinations (no issue filter applies) +// and when the issue cannot be read. +func (c *Client) reviewBacklogAdmission(ctx context.Context, sink ReviewBacklogSink, repo string, ref ReviewBacklogRef) string { + if _, ok := sink.(githubIssueBacklogSink); !ok || ref.Number <= 0 { + return "" + } + owner, name := c.splitRepo(repo) + issue, _, err := c.client.Issues.Get(ctx, owner, name, ref.Number) + if err != nil { + return "" + } + return c.unblockAdmission(issueLabelNames(issue.Labels)) +} + +// LiftBlock removes `blocked` from the GitHub issue and posts note, unless +// the blocked sweep already noted the lift for the same PR +// (unblockAlreadyNoted). func (s githubIssueBacklogSink) LiftBlock(ctx context.Context, repo string, ref ReviewBacklogRef, note string) error { if ref.Number <= 0 { return fmt.Errorf("review backlog: GitHub item %q has no issue number", ref.ID) @@ -89,6 +116,11 @@ func (s githubIssueBacklogSink) LiftBlock(ctx context.Context, repo string, ref if err := s.c.unblockIssue(ctx, repo, ref.Number); err != nil { return err } + owner, name := s.c.splitRepo(repo) + if comments, err := s.c.listIssueComments(ctx, owner, name, ref.Number); err == nil && unblockAlreadyNoted(comments, note) { + s.c.noteCommentSuppressed() + return nil + } return s.c.CreateIssueCommentBudgeted(ctx, repo, ref.Number, note) } @@ -222,7 +254,7 @@ func ReconcileReviewBacklogBlocks(ctx context.Context, c *Client, logger *slog.L if actErr != nil { break } - note := reviewBacklogLiftNote(repo, rec.BlockedOnPR) + note := reviewBacklogLiftNote(repo, rec.BlockedOnPR, c.reviewBacklogAdmission(ctx, sink, repo, ref)) if canResolve { actErr = resolver.LiftBlock(ctx, repo, ref, note) } else { @@ -249,7 +281,7 @@ func ReconcileReviewBacklogBlocks(ctx context.Context, c *Client, logger *slog.L if actErr != nil { break } - note := reviewBacklogLiftNote(repo, supersededBy) + note := reviewBacklogLiftNote(repo, supersededBy, c.reviewBacklogAdmission(ctx, sink, repo, ref)) if canResolve { actErr = resolver.LiftBlock(ctx, repo, ref, note) } else { @@ -260,7 +292,7 @@ func ReconcileReviewBacklogBlocks(ctx context.Context, c *Client, logger *slog.L res.Lifted++ } case reviewBacklogPRClosed: - note := reviewBacklogRetriageNote(repo, supersededBy) + note := reviewBacklogRetriageNote(repo, supersededBy, c.reviewBacklogAdmission(ctx, sink, repo, ref)) if canResolve { actErr = resolver.LiftBlock(ctx, repo, ref, note) } else { @@ -291,7 +323,7 @@ func ReconcileReviewBacklogBlocks(ctx context.Context, c *Client, logger *slog.L } // Never auto-close: unblock, comment, and leave the item to // normal triage (maintainer decision on #13849). - note := reviewBacklogRetriageNote(repo, rec.BlockedOnPR) + note := reviewBacklogRetriageNote(repo, rec.BlockedOnPR, c.reviewBacklogAdmission(ctx, sink, repo, ref)) if canResolve { actErr = resolver.LiftBlock(ctx, repo, ref, note) } else { diff --git a/src/pkg/github/review_backlog_heads_test.go b/src/pkg/github/review_backlog_heads_test.go index 6cd6fa2dfa..1788d4dcc5 100644 --- a/src/pkg/github/review_backlog_heads_test.go +++ b/src/pkg/github/review_backlog_heads_test.go @@ -287,7 +287,7 @@ func TestReconcileReviewBacklogBlocks(t *testing.T) { // A closed-unmerged source PR never closes the item: the note unblocks it // and asks for re-triage (maintainer decision on #13849). func TestReviewBacklogRetriageNote(t *testing.T) { - note := reviewBacklogRetriageNote("o/r", 6) + note := reviewBacklogRetriageNote("o/r", 6, "") for _, want := range []string{blockedUnblockedMarker, reviewBacklogRetriageMarker, "source PR o/r#6 closed unmerged — re-triage against current base"} { if !strings.Contains(note, want) { t.Errorf("note missing %q: %q", want, note)