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-16246-stale-draft-wip-label.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
25 changes: 24 additions & 1 deletion src/pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
73 changes: 73 additions & 0 deletions src/pkg/github/stale_draft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading