Skip to content

Commit 35be995

Browse files
Fix Vale style review posting duplicate comments on PRs (#699)
The Vale style review workflow was posting a new review comment every time a commit was pushed to a PR, resulting in noisy duplicate comments in Slack notifications. Now the script checks if a Vale style review has already been posted to the PR and skips posting if one exists. Co-authored-by: Rachel Lee Nabors <nearestnabors@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7a62d31 commit 35be995

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scripts/vale-style-review.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type FileWithDiff = {
8787
// Regex to identify Vale-generated comments (starts with **`Rule.Name`**:)
8888
const VALE_COMMENT_REGEX = /^\*\*`[A-Za-z]+\.[A-Za-z]+`\*\*:/;
8989

90+
// Regex to identify the Vale review summary comment
91+
const VALE_REVIEW_SUMMARY_REGEX =
92+
/^## Style Review\s+Found \d+ style suggestion/;
93+
9094
// Parse command line args
9195
function parseArgs(): { prNumber: number } {
9296
const args = process.argv.slice(2);
@@ -164,6 +168,34 @@ async function getChangedFiles(
164168
}));
165169
}
166170

171+
// Check if a Vale style review has already been posted to this PR
172+
// Returns true if we should skip posting (a review already exists)
173+
async function hasExistingValeReview(
174+
octokit: Octokit,
175+
prNumber: number
176+
): Promise<boolean> {
177+
try {
178+
// Get all reviews on the PR
179+
const reviews = await octokit.paginate(octokit.rest.pulls.listReviews, {
180+
owner: OWNER,
181+
repo: REPO,
182+
pull_number: prNumber,
183+
per_page: 100,
184+
});
185+
186+
// Check if any review body matches the Vale review summary pattern
187+
for (const review of reviews) {
188+
if (review.body && VALE_REVIEW_SUMMARY_REGEX.test(review.body.trim())) {
189+
return true;
190+
}
191+
}
192+
} catch (error) {
193+
console.warn("Warning: Could not check for existing Vale review:", error);
194+
}
195+
196+
return false;
197+
}
198+
167199
// Get existing Vale review comments on the PR to avoid duplicates
168200
// Returns a Set of "path:line" keys that already have Vale comments
169201
async function getExistingValeComments(
@@ -504,6 +536,15 @@ async function main() {
504536

505537
console.log(`Reviewing PR #${prNumber}...`);
506538

539+
// Check if a Vale review has already been posted - if so, skip to avoid noise
540+
const alreadyReviewed = await hasExistingValeReview(octokit, prNumber);
541+
if (alreadyReviewed) {
542+
console.log(
543+
"A Vale style review has already been posted to this PR. Skipping to avoid duplicate comments."
544+
);
545+
return;
546+
}
547+
507548
// Get changed files with their diff info
508549
const changedFiles = await getChangedFiles(octokit, prNumber);
509550
if (changedFiles.length === 0) {

0 commit comments

Comments
 (0)