Skip to content

Commit 0246bfe

Browse files
committed
feat: add suggestions-limit input
Teams can use this to avoid PRs with many, many suggestion comments dumped when opened which is a bad experience. Next we'll implement an output for known when suggestions were skipped, so teams can take some other action, such as opening a sibling PR.
1 parent 045e27e commit 0246bfe

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: run/action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
suggestions:
1414
description: "Add suggestion comments of restyled changes"
1515
default: false
16+
suggestion-limit:
17+
description: "Limit the number of suggestion comments left"
18+
required: false
1619
show-patch:
1720
description: "Log the patch produced by Restyled with git format-patch"
1821
default: true

Diff for: run/src/inputs.ts

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type Inputs = {
2020
paths: string[];
2121
githubToken: string;
2222
suggestions: boolean;
23+
suggestionsLimit: number | null;
2324
showPatch: boolean;
2425
showPatchCommand: boolean;
2526
committerEmail: string;
@@ -44,12 +45,20 @@ export function getInputs(): Inputs {
4445
}
4546
}
4647

48+
const rawSuggestionLimit = core.getInput("suggestion-limit", {
49+
required: false,
50+
});
51+
4752
return {
4853
paths,
4954
githubToken: core.getInput("github-token", { required: true }),
5055
suggestions: core.getBooleanInput("suggestions", {
5156
required: true,
5257
}),
58+
suggestionsLimit:
59+
rawSuggestionLimit && rawSuggestionLimit !== ""
60+
? parseInt(rawSuggestionLimit, 10)
61+
: null,
5362
showPatch: core.getBooleanInput("show-patch", {
5463
required: true,
5564
}),

Diff for: run/src/main.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,20 @@ async function run() {
106106

107107
let n = 0;
108108
const ps = suggestions.map((s) => {
109-
if (s.skipReason) {
109+
const limitSkipReason =
110+
inputs.suggestionsLimit && n >= inputs.suggestionsLimit
111+
? "limit reached"
112+
: null;
113+
114+
const skipReason = s.skipReason ?? limitSkipReason;
115+
116+
if (skipReason) {
110117
const line =
111118
s.startLine !== s.endLine
112119
? `${s.startLine}-${s.endLine}`
113120
: `${s.startLine}`;
114121
const location = `${s.path}:${line}`;
115-
core.warning(`[${location}]: Skipping suggestion: ${s.skipReason}`);
122+
core.warning(`[${location}]: Skipping suggestion: ${skipReason}`);
116123
return Promise.resolve();
117124
} else {
118125
n += 1;

0 commit comments

Comments
 (0)