diff --git a/.github/actions/AddComment/AddComment.js b/.github/actions/AddComment/AddComment.js index ffcf3a1343..f621a4f7dd 100644 --- a/.github/actions/AddComment/AddComment.js +++ b/.github/actions/AddComment/AddComment.js @@ -31,6 +31,22 @@ class AddComment extends ActionBase_1.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) { + (0, utils_1.safeLog)(`Issue ${hydrated.number} already commented on by an action. Ignoring.`); + continue; + } if (this.addComment) { (0, utils_1.safeLog)(`Posting comment on issue ${hydrated.number}`); await issue.postComment(this.addComment); diff --git a/.github/actions/AddComment/AddComment.ts b/.github/actions/AddComment/AddComment.ts index e21bf213a3..9dd36e1bb2 100644 --- a/.github/actions/AddComment/AddComment.ts +++ b/.github/actions/AddComment/AddComment.ts @@ -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, @@ -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);