Skip to content

Commit 6e68301

Browse files
authored
Truncate file lists in maintainer-approval comments (#4998)
## Why The maintainer-approval bot comments list every single file in each ownership group. For PRs that touch many files (e.g. codegen updates), this makes the comment extremely verbose and hard to scan. ## Changes When an ownership group has 4 or more files, the comment now shows "N files changed" instead of listing every file path. Groups with fewer than 4 files still list them individually. ## Test plan - Added test for < 4 files (individual listing preserved) - Added test for >= 4 files (count shown instead) - All 22 tests pass: `node --test .github/workflows/maintainer-approval.test.js` This pull request was AI-assisted by Isaac.
1 parent c92a5f3 commit 6e68301

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/maintainer-approval.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ async function selectRoundRobin(github, owner, repo, eligibleOwners, prAuthor) {
261261

262262
// --- Comment builders ---
263263

264+
function fmtFileList(files) {
265+
if (files.length < 4) {
266+
return `Files: ${files.map(f => `\`${f}\``).join(", ")}`;
267+
}
268+
return `${files.length} files changed`;
269+
}
270+
264271
function buildPendingPerGroupComment(groups, scores, dirScores, approvedBy, maintainers, prAuthor) {
265272
const authorLower = (prAuthor || "").toLowerCase();
266273
const lines = [MARKER, "## Approval status: pending", ""];
@@ -274,7 +281,7 @@ function buildPendingPerGroupComment(groups, scores, dirScores, approvedBy, main
274281
} else {
275282
lines.push(`### \`${pattern}\` - needs approval`);
276283
}
277-
lines.push(`Files: ${files.map(f => `\`${f}\``).join(", ")}`);
284+
lines.push(fmtFileList(files));
278285

279286
const teams = owners.filter(o => o.includes("/"));
280287
const individuals = owners.filter(o => !o.includes("/") && o.toLowerCase() !== authorLower);
@@ -301,7 +308,7 @@ function buildPendingPerGroupComment(groups, scores, dirScores, approvedBy, main
301308
const starGroup = groups.get("*");
302309
if (starGroup) {
303310
lines.push("### General files (require maintainer)");
304-
lines.push(`Files: ${starGroup.files.map(f => `\`${f}\``).join(", ")}`);
311+
lines.push(fmtFileList(starGroup.files));
305312

306313
const maintainerSet = new Set(maintainers.map(m => m.toLowerCase()));
307314
const maintainerScores = Object.entries(scores)

.github/workflows/maintainer-approval.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,47 @@ describe("maintainer-approval", () => {
515515
assert.ok(body.includes("approved by `@jefferycheng1`"));
516516
assert.ok(body.includes("needs approval"));
517517
});
518+
519+
it("lists individual files when fewer than 4 in a group", async () => {
520+
const github = makeGithub({
521+
reviews: [],
522+
files: [
523+
{ filename: "cmd/pipelines/foo.go" },
524+
{ filename: "bundle/config.go" },
525+
{ filename: "bundle/deploy.go" },
526+
],
527+
});
528+
const core = makeCore();
529+
const context = makeContext();
530+
531+
await runModule({ github, context, core });
532+
533+
assert.equal(github._comments.length, 1);
534+
const body = github._comments[0].body;
535+
assert.ok(body.includes("Files:"), "should list individual files");
536+
assert.ok(body.includes("`bundle/config.go`"));
537+
assert.ok(body.includes("`bundle/deploy.go`"));
538+
});
539+
540+
it("shows file count instead of listing when 4 or more files in a group", async () => {
541+
const github = makeGithub({
542+
reviews: [],
543+
files: [
544+
{ filename: "cmd/pipelines/foo.go" },
545+
{ filename: "bundle/a.go" },
546+
{ filename: "bundle/b.go" },
547+
{ filename: "bundle/c.go" },
548+
{ filename: "bundle/d.go" },
549+
],
550+
});
551+
const core = makeCore();
552+
const context = makeContext();
553+
554+
await runModule({ github, context, core });
555+
556+
assert.equal(github._comments.length, 1);
557+
const body = github._comments[0].body;
558+
assert.ok(body.includes("4 files changed"), "should show count for bundle group");
559+
assert.ok(!body.includes("`bundle/a.go`"), "should not list individual bundle files");
560+
});
518561
});

0 commit comments

Comments
 (0)