Skip to content

Commit 216f4ea

Browse files
committed
ci(danger): adjust large commit threshold
1 parent 521c706 commit 216f4ea

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ jobs:
2626
container:
2727
image: ubuntu:24.04
2828
name: Generate Test Matrix
29-
# Permissions allow Danger to read PR context and post comments.
30-
permissions:
31-
contents: read
32-
pull-requests: write
3329
outputs:
3430
matrix: ${{ steps.cpp-matrix.outputs.matrix }}
3531
llvm-matrix: ${{ steps.llvm-matrix.outputs.llvm-matrix }}

util/danger/format.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("renderDangerReport", () => {
1919
]);
2020
const result: DangerResult = {
2121
warnings: ["First issue", "Second issue"],
22+
infos: [],
2223
summary,
2324
};
2425

@@ -33,12 +34,23 @@ describe("renderDangerReport", () => {
3334
expect(output).toContain("## 🔝 Top Files");
3435
});
3536

37+
it("renders informational notes separately from warnings", () => {
38+
const summary = summarizeScopes([{ filename: "src/lib/example.cpp", additions: 1, deletions: 0 }]);
39+
const result: DangerResult = { warnings: [], infos: ["Large commit"], summary };
40+
41+
const output = renderDangerReport(result);
42+
43+
expect(output).toContain("## ℹ️ Info");
44+
expect(output).toContain("[!NOTE]");
45+
expect(output).toContain("Large commit");
46+
});
47+
3648
it("formats scope totals with bold metrics and consistent churn", () => {
3749
const summary = summarizeScopes([
3850
{ filename: "src/lib/example.cpp", additions: 3, deletions: 1 },
3951
{ filename: "src/test/example_test.cpp", additions: 2, deletions: 0 },
4052
]);
41-
const result: DangerResult = { warnings: [], summary };
53+
const result: DangerResult = { warnings: [], infos: [], summary };
4254

4355
const output = renderDangerReport(result);
4456

@@ -53,7 +65,7 @@ describe("renderDangerReport", () => {
5365
const summary = summarizeScopes([
5466
{ filename: "src/lib/old.cpp", additions: 0, deletions: 5, status: "removed" },
5567
]);
56-
const result: DangerResult = { warnings: [], summary };
68+
const result: DangerResult = { warnings: [], infos: [], summary };
5769

5870
const output = renderDangerReport(result);
5971
const sourceRow = output.split("\n").find((line) => line.startsWith("| Source"));

util/danger/format.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ function renderWarnings(warnings: string[]): string {
8080
return ["## ⚠️ Warnings", blocks.join("\n\n")].join("\n");
8181
}
8282

83+
function renderInfos(infos: string[]): string {
84+
if (infos.length === 0) {
85+
return "";
86+
}
87+
const blocks = infos.map((message) => ["> [!NOTE]", `> ${message}`].join("\n"));
88+
return ["## ℹ️ Info", blocks.join("\n\n")].join("\n");
89+
}
90+
8391
function countFileChanges(status: ScopeTotals["status"]): number {
8492
return status.added + status.modified + status.renamed + status.removed + status.other;
8593
}
@@ -207,6 +215,7 @@ export function renderDangerReport(result: DangerResult): string {
207215
const sections = [
208216
notice,
209217
renderWarnings(result.warnings),
218+
renderInfos(result.infos),
210219
renderHighlights(result.summary.highlights),
211220
renderChangeTable(result.summary),
212221
renderTopChanges(result.summary),

util/danger/logic.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
import { describe, expect, it } from "vitest";
1111
import {
12-
commitSizeWarnings,
12+
commitSizeInfos,
1313
parseCommitSummary,
1414
basicChecks,
1515
summarizeScopes,
@@ -51,21 +51,21 @@ describe("summarizeScopes", () => {
5151
});
5252
});
5353

54-
describe("commitSizeWarnings", () => {
55-
// Confirms that large non-test churn triggers a warning while ignoring test fixtures.
54+
describe("commitSizeInfos", () => {
55+
// Confirms that large non-test churn emits an informational note while ignoring test fixtures.
5656
it("flags large non-test commits", () => {
5757
const commits: CommitInfo[] = [
5858
{
5959
sha: "abc",
6060
message: "feat: huge change",
6161
files: [
62-
{ filename: "src/lib/large.cpp", additions: 900, deletions: 200 },
62+
{ filename: "src/lib/large.cpp", additions: 1800, deletions: 400 },
6363
{ filename: "test-files/golden-tests/out.xml", additions: 1000, deletions: 0 },
6464
],
6565
},
6666
];
67-
const warnings = commitSizeWarnings(commits);
68-
expect(warnings.length).toBe(1);
67+
const infos = commitSizeInfos(commits);
68+
expect(infos.length).toBe(1);
6969
});
7070
});
7171

util/danger/logic.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface DangerInputs {
103103
*/
104104
export interface DangerResult {
105105
warnings: string[];
106+
infos: string[];
106107
summary: ScopeReport;
107108
}
108109

@@ -137,7 +138,7 @@ const scopeFormat = /^[a-z0-9._/-]+$/i;
137138
const typeSet = new Set(allowedTypes);
138139
const skipTestLabels = new Set(["no-tests-needed", "skip-tests", "tests-not-required"]);
139140
const skipTestMarkers = ["[skip danger tests]", "[danger skip tests]"];
140-
const nonTestCommitLimit = 800;
141+
const nonTestCommitLimit = 2000;
141142

142143
/**
143144
* Format churn as a + / - pair with explicit signs.
@@ -443,7 +444,7 @@ export function validateCommits(commits: CommitInfo[]): { warnings: string[]; pa
443444
* @param commits commits with per-file stats.
444445
* @returns warning messages for commits that exceed the threshold.
445446
*/
446-
export function commitSizeWarnings(commits: CommitInfo[]): string[] {
447+
export function commitSizeInfos(commits: CommitInfo[]): string[] {
447448
const messages: string[] = [];
448449
for (const commit of commits) {
449450
if (!commit.files || commit.files.length === 0) {
@@ -464,9 +465,9 @@ export function commitSizeWarnings(commits: CommitInfo[]): string[] {
464465

465466
if (churn > nonTestCommitLimit && parsedType !== "refactor") {
466467
const shortSha = commit.sha.substring(0, 7);
467-
// === Commit size warnings (non-test churn) ===
468+
// === Commit size informational notes (non-test churn) ===
468469
messages.push(
469-
`Commit \`${shortSha}\` (${summary}) changes ${churn} source lines. Consider splitting it into smaller, reviewable chunks.`,
470+
`Commit \`${shortSha}\` (${summary}) touches ${churn} source lines (non-test). Large change; add reviewer context if needed.`,
470471
);
471472
}
472473
}
@@ -555,11 +556,12 @@ export function evaluateDanger(input: DangerInputs): DangerResult {
555556
const summary = summarizeScopes(input.files);
556557
const commitValidation = validateCommits(input.commits);
557558

559+
const infos = commitSizeInfos(input.commits);
560+
558561
const warnings = [
559562
...commitValidation.warnings,
560-
...commitSizeWarnings(input.commits),
561563
...basicChecks(input, summary, commitValidation.parsed),
562564
];
563565

564-
return { warnings, summary };
566+
return { warnings, infos, summary };
565567
}

util/danger/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function runDanger(): Promise<void> {
116116
});
117117

118118
const warnings = [...fetchWarnings, ...evaluation.warnings];
119-
const report = renderDangerReport({ ...evaluation, warnings });
119+
const report = renderDangerReport({ warnings, infos: evaluation.infos, summary: evaluation.summary });
120120

121121
markdown(report);
122122
}

0 commit comments

Comments
 (0)