diff --git a/changelog.d/fixed-16246-stale-draft-wip-label.md b/changelog.d/fixed-16246-stale-draft-wip-label.md new file mode 100644 index 0000000000..3e153debde --- /dev/null +++ b/changelog.d/fixed-16246-stale-draft-wip-label.md @@ -0,0 +1 @@ +- Hive-authored draft PRs carrying only prow's `do-not-merge/work-in-progress` mirror label are no longer filtered as "Exempt label" before the stale-draft rule runs, so deferred drafts surface in the scanner's "YOUR STALE DRAFT PRs" section instead of deadlocking with their `covered_by_open_pr` issue (#16246). diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index 7f436f54ec..3dd2f95a60 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:5017-5027`, descending `AgeMinutes` within each tier). + (`RankActionableIssues`, `src/pkg/github/client.go:5040-5050`, descending `AgeMinutes` within each tier). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests). diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index afa694b2af..0251f312fd 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -1437,6 +1437,12 @@ var HoldLabels = []string{"hold", "on-hold", "hold/review"} var PermanentExemptLabels = []string{"do-not-merge"} +// wipMirrorLabel is the label prow's `wip` plugin applies to every draft PR +// as a mirror of the draft bit. It carries no information beyond "this is a +// draft", so it must not shield a hive-authored draft from the stale-draft +// rule the way a deliberate do-not-merge/hold does (#16246). +const wipMirrorLabel = "do-not-merge/work-in-progress" + // AutoMergeQueuedLabel is the fallback label a merger/owner queue action // applies when a hive has not configured `governor.labels.automerge`. Prefer // Client.AutoMergeLabel(), which honours that configuration; this constant @@ -2236,7 +2242,7 @@ func (c *Client) fetchPRsWithDetails(ctx context.Context, repo string, clankerBu continue } - if c.isExempt(labels) { + if c.isExempt(labels) && !c.isDraftExemptOnlyByWIPMirror(pr.GetDraft(), labels) { breakdown.Filtered++ sidelined = append(sidelined, c.repoWorkPR(repo, pr, labels, hasAttr, workBucketPRFiltered, "Exempt label")) continue @@ -3861,6 +3867,23 @@ func (c *Client) isExempt(labels []string) bool { return HasExemptLabel(labels, c.exemptLabels) } +// isDraftExemptOnlyByWIPMirror reports whether a draft PR's exemption comes +// solely from prow's do-not-merge/work-in-progress mirror label. Such a draft +// must fall through to the draft branch so the stale-draft rule can still +// surface it; any other exempt label keeps the PR filtered (#16246). +func (c *Client) isDraftExemptOnlyByWIPMirror(draft bool, labels []string) bool { + if !draft { + return false + } + rest := make([]string, 0, len(labels)) + for _, l := range labels { + if !strings.EqualFold(l, wipMirrorLabel) { + rest = append(rest, l) + } + } + return len(rest) != len(labels) && !c.isExempt(rest) +} + func HasExemptLabel(labels, exemptLabels []string) bool { for _, label := range labels { for _, perm := range PermanentExemptLabels { diff --git a/src/pkg/github/stale_draft_test.go b/src/pkg/github/stale_draft_test.go index 41656c5557..f366e7389d 100644 --- a/src/pkg/github/stale_draft_test.go +++ b/src/pkg/github/stale_draft_test.go @@ -124,3 +124,76 @@ func TestFetchPRs_HumanStaleDraftNotSurfaced(t *testing.T) { t.Errorf("staleDrafts = %v, want empty for a human-authored draft", staleDrafts) } } + +// TestFetchPRs_StaleAppDraftWithWIPMirrorLabelIsSurfaced: prow's wip plugin +// adds do-not-merge/work-in-progress to every draft. Because that prefix is in +// PermanentExemptLabels and the exempt check ran before the draft check, every +// hive-authored draft was filtered as "Exempt label" and never reached the +// stale-draft rule (#16246). The WIP mirror alone must not shield a draft. +func TestFetchPRs_StaleAppDraftWithWIPMirrorLabelIsSurfaced(t *testing.T) { + mux := http.NewServeMux() + mux.HandleFunc("/repos/acme/widget/pulls", prsHandler(t, []wirePR{ + { + Number: 43, + Title: "fix: deferred, stacked on another PR", + User: wireUser{Login: "acme-bot[bot]"}, + Labels: []wireLabel{{Name: "do-not-merge/work-in-progress"}, {Name: "size/L"}}, + Draft: true, + CreatedAt: hoursAgo(72), + HTMLURL: "https://github.com/acme/widget/pull/43", + }, + })) + server := httptest.NewServer(mux) + defer server.Close() + + c := newTestClient(t, server, "acme", []string{"widget"}) + c.appBotLogin = "acme-bot[bot]" + + actionable, _, _, staleDrafts, _, _, breakdown, err := c.fetchPRs(t.Context(), "widget", nil) + if err != nil { + t.Fatalf("fetchPRs: %v", err) + } + if len(actionable) != 0 { + t.Errorf("actionable = %v, want empty", actionable) + } + if len(staleDrafts) != 1 || staleDrafts[0].Number != 43 { + t.Fatalf("staleDrafts = %+v, want exactly PR 43", staleDrafts) + } + if breakdown.Filtered != 0 || breakdown.Draft != 1 { + t.Errorf("breakdown filtered=%d draft=%d, want 0/1", breakdown.Filtered, breakdown.Draft) + } +} + +// TestFetchPRs_StaleAppDraftWithOtherExemptLabelStaysExempt: a deliberate +// do-not-merge/* label other than the WIP mirror (hold is handled earlier as a +// held draft) still exempts a draft from the stale-draft nag. +func TestFetchPRs_StaleAppDraftWithOtherExemptLabelStaysExempt(t *testing.T) { + mux := http.NewServeMux() + mux.HandleFunc("/repos/acme/widget/pulls", prsHandler(t, []wirePR{ + { + Number: 44, + Title: "fix: blocked on purpose", + User: wireUser{Login: "acme-bot[bot]"}, + Labels: []wireLabel{{Name: "do-not-merge/work-in-progress"}, {Name: "do-not-merge/blocked-paths"}}, + Draft: true, + CreatedAt: hoursAgo(72), + HTMLURL: "https://github.com/acme/widget/pull/44", + }, + })) + server := httptest.NewServer(mux) + defer server.Close() + + c := newTestClient(t, server, "acme", []string{"widget"}) + c.appBotLogin = "acme-bot[bot]" + + _, _, _, staleDrafts, _, _, breakdown, err := c.fetchPRs(t.Context(), "widget", nil) + if err != nil { + t.Fatalf("fetchPRs: %v", err) + } + if len(staleDrafts) != 0 { + t.Errorf("staleDrafts = %+v, want empty — a non-WIP do-not-merge label must still exempt", staleDrafts) + } + if breakdown.Filtered != 1 { + t.Errorf("breakdown.Filtered = %d, want 1", breakdown.Filtered) + } +}