Skip to content

Commit 85a49d1

Browse files
snomiaoclaude
andauthored
refactor(backport): rename labels to no-backport-needed[-cloud|-core] (#183)
Rename backport dismissal labels for clarity: - `core-backport-not-needed` → `no-backport-needed-core` - `cloud-backport-not-needed` → `no-backport-needed-cloud` - Add general `no-backport-needed` label that dismisses all targets Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b706f85 commit 85a49d1

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

app/tasks/gh-frontend-backport-checker/index.spec.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,31 +300,39 @@ describe("GithubFrontendBackportCheckerTask", () => {
300300
});
301301

302302
describe("backport-not-needed labels", () => {
303+
const backportNotNeededLabel = "no-backport-needed";
303304
const backportNotNeededLabels: Record<string, string> = {
304-
core: "core-backport-not-needed",
305-
cloud: "cloud-backport-not-needed",
305+
core: "no-backport-needed-core",
306+
cloud: "no-backport-needed-cloud",
306307
};
307308

308309
function hasBackportNotNeededLabel(labels: string[], targetPrefix: string): boolean {
310+
if (labels.some((l) => l.toLowerCase() === backportNotNeededLabel.toLowerCase())) return true;
309311
const notNeededLabel = backportNotNeededLabels[targetPrefix];
310312
if (!notNeededLabel) return false;
311313
return labels.some((l) => l.toLowerCase() === notNeededLabel.toLowerCase());
312314
}
313315

314-
it("should detect core-backport-not-needed label", () => {
315-
const labels = ["bug", "core-backport-not-needed", "core/1.4"];
316+
it("should detect no-backport-needed-core label", () => {
317+
const labels = ["bug", "no-backport-needed-core", "core/1.4"];
316318
expect(hasBackportNotNeededLabel(labels, "core")).toBe(true);
317319
expect(hasBackportNotNeededLabel(labels, "cloud")).toBe(false);
318320
});
319321

320-
it("should detect cloud-backport-not-needed label", () => {
321-
const labels = ["bug", "cloud-backport-not-needed", "cloud/1.36"];
322+
it("should detect no-backport-needed-cloud label", () => {
323+
const labels = ["bug", "no-backport-needed-cloud", "cloud/1.36"];
322324
expect(hasBackportNotNeededLabel(labels, "cloud")).toBe(true);
323325
expect(hasBackportNotNeededLabel(labels, "core")).toBe(false);
324326
});
325327

328+
it("should detect general no-backport-needed label for all targets", () => {
329+
const labels = ["bug", "no-backport-needed"];
330+
expect(hasBackportNotNeededLabel(labels, "core")).toBe(true);
331+
expect(hasBackportNotNeededLabel(labels, "cloud")).toBe(true);
332+
});
333+
326334
it("should be case insensitive", () => {
327-
const labels = ["Core-Backport-Not-Needed"];
335+
const labels = ["No-Backport-Needed-Core"];
328336
expect(hasBackportNotNeededLabel(labels, "core")).toBe(true);
329337
});
330338

@@ -334,8 +342,8 @@ describe("GithubFrontendBackportCheckerTask", () => {
334342
expect(hasBackportNotNeededLabel(labels, "cloud")).toBe(false);
335343
});
336344

337-
it("should return false for unknown target prefix", () => {
338-
const labels = ["core-backport-not-needed"];
345+
it("should return false for unknown target prefix without general label", () => {
346+
const labels = ["no-backport-needed-core"];
339347
expect(hasBackportNotNeededLabel(labels, "unknown")).toBe(false);
340348
});
341349
});

app/tasks/gh-frontend-backport-checker/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { slackCached } from "@/lib";
6464
*
6565
* c) PER-TARGET-BRANCH STATUS — only runs when `backportStatusRaw` is
6666
* "needed". For each labeled target branch:
67-
* - Checks for `*-backport-not-needed` labels (e.g. `core-backport-not-needed`)
67+
* - Checks for `no-backport-needed[-core|-cloud]` labels
6868
* → marks that target as "not-needed"
6969
* - Uses `compareCommits(target_branch, commit_sha)` to check if the
7070
* commit already exists on that branch:
@@ -126,10 +126,11 @@ import { slackCached } from "@/lib";
126126
* from bots (username ending in `bot` or `[bot]`) are excluded to avoid
127127
* false positives from automated messages.
128128
*
129-
* • BACKPORT-NOT-NEEDED LABELS — per-target dismissal labels like
130-
* `core-backport-not-needed` override the per-branch status to "not-needed",
131-
* even if the commit hasn't been cherry-picked. When ALL targets are
132-
* dismissed this way, the overall status becomes "not-needed".
129+
* • BACKPORT-NOT-NEEDED LABELS — `no-backport-needed` dismisses all targets;
130+
* per-target labels `no-backport-needed-core` / `no-backport-needed-cloud`
131+
* override individual branch status to "not-needed", even if the commit
132+
* hasn't been cherry-picked. When ALL targets are dismissed, the overall
133+
* status becomes "not-needed".
133134
*
134135
* • DIVERGED BRANCH (backport PR detection) — when the target branch has
135136
* diverged from the commit (common for long-lived stable branches), the
@@ -183,10 +184,11 @@ const config = {
183184
// 3. backport labels on PRs
184185
backportLabels: ["needs-backport"],
185186

186-
// labels that dismiss backport requirements per target
187+
// labels that dismiss backport requirements per target (or all targets)
188+
backportNotNeededLabel: "no-backport-needed",
187189
backportNotNeededLabels: {
188-
core: "core-backport-not-needed",
189-
cloud: "cloud-backport-not-needed",
190+
core: "no-backport-needed-core",
191+
cloud: "no-backport-needed-cloud",
190192
} as Record<string, string>,
191193

192194
// 5. detect backport mentions
@@ -463,6 +465,10 @@ async function resolveSlackTagForAuthor(githubUsername?: string): Promise<string
463465

464466
/** Check if a PR has a backport-not-needed label for a given target prefix (e.g. "core" or "cloud") */
465467
function hasBackportNotNeededLabel(labels: string[], targetPrefix: string): boolean {
468+
// General label dismisses all targets
469+
if (labels.some((l) => l.toLowerCase() === config.backportNotNeededLabel.toLowerCase()))
470+
return true;
471+
// Per-target label
466472
const notNeededLabel = config.backportNotNeededLabels[targetPrefix];
467473
if (!notNeededLabel) return false;
468474
return labels.some((l) => l.toLowerCase() === notNeededLabel.toLowerCase());
@@ -593,7 +599,7 @@ async function processTask(
593599

594600
const backportTargetStatus = await sflow(targetBranches)
595601
.map(async (branchName) => {
596-
// Check for *-backport-not-needed labels first (e.g. "core/1.4" → prefix "core")
602+
// Check for no-backport-needed[-core|-cloud] labels first (e.g. "core/1.4" → prefix "core")
597603
const targetPrefix = branchName.split("/")[0];
598604
if (hasBackportNotNeededLabel(labels, targetPrefix)) {
599605
logger.debug(

0 commit comments

Comments
 (0)