Skip to content

Commit

Permalink
Prevent AddComment action from adding redundant comments (#12611)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms committed Aug 21, 2024
1 parent d7bfae6 commit fbfddd2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .github/actions/AddComment/AddComment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion .github/actions/AddComment/AddComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { daysAgoToHumanReadbleDate, daysAgoToTimestamp, safeLog } from '../commo
export class AddComment extends ActionBase {
constructor(
private github: GitHub,
private createdAfter: string,
private createdAfter: string | undefined,
private afterDays: number,
labels: string,
private addComment: string,
Expand Down Expand Up @@ -45,6 +45,23 @@ export class AddComment extends ActionBase {
if (hydrated.open && this.validateIssue(hydrated)
// TODO: Verify updated timestamp
) {
// Don't add a comment if already commented on by an action.
let foundActionComment = false;
for await (const commentBatch of issue.getComments()) {
for (const comment of commentBatch) {
if (comment.author.isGitHubApp) {
foundActionComment = true;
break;
}
}
if (foundActionComment)
break;
}
if (foundActionComment) {
safeLog(`Issue ${hydrated.number} already commented on by an action. Ignoring.`);
continue;
}

if (this.addComment) {
safeLog(`Posting comment on issue ${hydrated.number}`);
await issue.postComment(this.addComment);
Expand Down

0 comments on commit fbfddd2

Please sign in to comment.