Skip to content

Commit 17b0a57

Browse files
committed
ci(danger): ignore test check for refactor-only PRs
1 parent 71845c8 commit 17b0a57

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

util/danger/logic.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,21 @@ describe("starterChecks", () => {
9090
const warnings = basicChecks(inputs, summary, parsed);
9191
expect(warnings.some((message) => message.includes("Source changed"))).toBe(true);
9292
});
93+
94+
// Ensures refactor-only work does not nag for tests when the change is mechanical.
95+
it("skips test warning for refactor commits", () => {
96+
const inputs: DangerInputs = {
97+
files: [],
98+
commits: [],
99+
prBody: "Refactor clean-up.\n\nTesting: relies on existing coverage; no behavior change.",
100+
prTitle: "refactor: tidy includes",
101+
labels: [],
102+
};
103+
104+
const summary = summarizeScopes([{ filename: "src/lib/refactor.cpp", additions: 10, deletions: 2 }]);
105+
const parsed = validateCommits([{ sha: "2", message: "refactor: tidy includes" }]).parsed;
106+
const warnings = basicChecks(inputs, summary, parsed);
107+
108+
expect(warnings.some((message) => message.includes("Source changed"))).toBe(false);
109+
});
93110
});

util/danger/logic.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ function hasSkipTests(prBody: string, labels: string[]): boolean {
501501
export function basicChecks(input: DangerInputs, scopes: ScopeReport, parsedCommits: ParsedCommit[]): string[] {
502502
const warnings: string[] = [];
503503

504+
const commitTypes = new Set(parsedCommits.map((commit) => commit.type).filter(Boolean) as string[]);
505+
const refactorSignal =
506+
commitTypes.has("refactor") ||
507+
/refactor/i.test(input.prTitle || "") ||
508+
input.labels.some((label) => /refactor/i.test(label));
509+
504510
const cleanedBody = (input.prBody || "").trim();
505511
if (cleanedBody.length < 40) {
506512
// === PR description completeness warnings ===
@@ -515,14 +521,17 @@ export function basicChecks(input: DangerInputs, scopes: ScopeReport, parsedComm
515521
}
516522

517523
const skipTests = hasSkipTests(input.prBody || "", input.labels);
518-
if (!skipTests && scopes.totals.source.files > 0 && scopes.totals.tests.files === 0 && scopes.totals["golden-tests"].files === 0) {
524+
if (
525+
!skipTests &&
526+
!refactorSignal &&
527+
scopes.totals.source.files > 0 &&
528+
scopes.totals.tests.files === 0 &&
529+
scopes.totals["golden-tests"].files === 0
530+
) {
519531
// === Source changes without tests/fixtures warnings ===
520-
warnings.push(
521-
"Source changed but no tests or fixtures were updated. Add coverage or label with `no-tests-needed` / `[skip danger tests]` when appropriate.",
522-
);
532+
warnings.push("Source changed but no tests or fixtures were updated.");
523533
}
524534

525-
const commitTypes = new Set(parsedCommits.map((commit) => commit.type).filter(Boolean) as string[]);
526535
const totalFiles = Object.values(scopes.totals).reduce((sum, scope) => sum + scope.files, 0);
527536
const nonDocFiles = totalFiles - scopes.totals.docs.files;
528537
const testFiles = scopes.totals.tests.files + scopes.totals["golden-tests"].files;

0 commit comments

Comments
 (0)