From 8b3b966e256fbb858912b0ec8000c232a67d87d7 Mon Sep 17 00:00:00 2001 From: Kevin Brian Bader Date: Wed, 15 Jan 2025 15:58:24 -0800 Subject: [PATCH] Proposal police structured response follow-up --- .../javascript/proposalPoliceComment/index.js | 12 ++++++------ .../proposalPoliceComment.ts | 15 +++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/actions/javascript/proposalPoliceComment/index.js b/.github/actions/javascript/proposalPoliceComment/index.js index fa07a1063e2e..16c3f7c1b0cd 100644 --- a/.github/actions/javascript/proposalPoliceComment/index.js +++ b/.github/actions/javascript/proposalPoliceComment/index.js @@ -18007,6 +18007,11 @@ async function run() { console.log('Comment body is either empty or doesn\'t contain the keyword "Proposal": ', payload.comment?.body); return; } + // If event is `edited` and comment was already edited by the bot, return early + if (isCommentEditedEvent(payload) && payload.comment?.body.trim().includes('Edited by **proposal-police**')) { + console.log('Comment was already edited by proposal-police once.\n', payload.comment?.body); + return; + } console.log('ProposalPolice™ Action triggered for comment:', payload.comment?.body); console.log('-> GitHub Action Type: ', payload.action?.toUpperCase()); if (!isCommentCreatedEvent(payload) && !isCommentEditedEvent(payload)) { @@ -18033,12 +18038,7 @@ async function run() { if (isCommentCreatedEvent(payload) && isActionRequired) { const formattedResponse = message // replace {user} from response template with @username - .replaceAll('{user}', `@${payload.comment?.user.login}`) - // replace {proposalLink} from response template with the link to the comment - .replaceAll('{proposalLink}', payload.comment?.html_url) - // remove any double quotes from the final comment because sometimes the assistant's - // response contains double quotes / sometimes it doesn't - .replaceAll('"', ''); + .replaceAll('{user}', `@${payload.comment?.user.login}`); // Create a comment with the assistant's response console.log('ProposalPolice™ commenting on issue...'); await GithubUtils_1.default.createComment(CONST_1.default.APP_REPO, github_1.context.issue.number, formattedResponse); diff --git a/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts b/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts index afa57d7c58ef..56847eb90afe 100644 --- a/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts +++ b/.github/actions/javascript/proposalPoliceComment/proposalPoliceComment.ts @@ -41,6 +41,12 @@ async function run() { return; } + // If event is `edited` and comment was already edited by the bot, return early + if (isCommentEditedEvent(payload) && payload.comment?.body.trim().includes('Edited by **proposal-police**')) { + console.log('Comment was already edited by proposal-police once.\n', payload.comment?.body); + return; + } + console.log('ProposalPolice™ Action triggered for comment:', payload.comment?.body); console.log('-> GitHub Action Type: ', payload.action?.toUpperCase()); @@ -73,14 +79,7 @@ async function run() { if (isCommentCreatedEvent(payload) && isActionRequired) { const formattedResponse = message // replace {user} from response template with @username - .replaceAll('{user}', `@${payload.comment?.user.login}`) - - // replace {proposalLink} from response template with the link to the comment - .replaceAll('{proposalLink}', payload.comment?.html_url) - - // remove any double quotes from the final comment because sometimes the assistant's - // response contains double quotes / sometimes it doesn't - .replaceAll('"', ''); + .replaceAll('{user}', `@${payload.comment?.user.login}`); // Create a comment with the assistant's response console.log('ProposalPolice™ commenting on issue...');