Skip to content

Commit

Permalink
Update existing comment if found
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Apr 1, 2023
1 parent 1fc8581 commit c5ff82a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions index.js
Expand Up @@ -98,11 +98,28 @@ function tmpl(t, o) {

async function exitWithError(exitType, octokit, shouldAddComment, message) {
if (shouldAddComment) {
await octokit.rest.issues.createComment({
const matchToken = `<!-- reqlabelmessage -->`;
// Is there an existing comment?
const { data: existing } = await octokit.rest.issues.listComments({
...github.context.repo,
issue_number: github.context.issue.number,
body: message,
});

const generatedComment = existing.find((c) => c.body.includes(matchToken));

const params = {
...github.context.repo,
issue_number: github.context.issue.number,
body: `${matchToken} ${message}`,
};

// If so, update it
let method = "createComment";
if (generatedComment) {
method = "updateComment";
params.comment_id = generatedComment.id;
}
await octokit.rest.issues[method](params);
}

core.setOutput("status", "failure");
Expand Down

0 comments on commit c5ff82a

Please sign in to comment.