Skip to content

Commit

Permalink
Proposal police structured response follow-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ikevin127 committed Jan 15, 2025
1 parent 5133090 commit 8b3b966
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .github/actions/javascript/proposalPoliceComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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...');
Expand Down

0 comments on commit 8b3b966

Please sign in to comment.