Skip to content

Commit fbfddd2

Browse files
authored
Prevent AddComment action from adding redundant comments (#12611)
1 parent d7bfae6 commit fbfddd2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.github/actions/AddComment/AddComment.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/AddComment/AddComment.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { daysAgoToHumanReadbleDate, daysAgoToTimestamp, safeLog } from '../commo
1010
export class AddComment extends ActionBase {
1111
constructor(
1212
private github: GitHub,
13-
private createdAfter: string,
13+
private createdAfter: string | undefined,
1414
private afterDays: number,
1515
labels: string,
1616
private addComment: string,
@@ -45,6 +45,23 @@ export class AddComment extends ActionBase {
4545
if (hydrated.open && this.validateIssue(hydrated)
4646
// TODO: Verify updated timestamp
4747
) {
48+
// Don't add a comment if already commented on by an action.
49+
let foundActionComment = false;
50+
for await (const commentBatch of issue.getComments()) {
51+
for (const comment of commentBatch) {
52+
if (comment.author.isGitHubApp) {
53+
foundActionComment = true;
54+
break;
55+
}
56+
}
57+
if (foundActionComment)
58+
break;
59+
}
60+
if (foundActionComment) {
61+
safeLog(`Issue ${hydrated.number} already commented on by an action. Ignoring.`);
62+
continue;
63+
}
64+
4865
if (this.addComment) {
4966
safeLog(`Posting comment on issue ${hydrated.number}`);
5067
await issue.postComment(this.addComment);

0 commit comments

Comments
 (0)