diff --git a/dist/index.js b/dist/index.js index 5f991cf..a5780c1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -43,6 +43,7 @@ function run() { try { const githubToken = core.getInput('github_token', { required: true }); const body = core.getInput('body', { required: true }); + const deduplicate = core.getInput('deduplicate', { required: false }); const octokit = github.getOctokit(githubToken); let { owner, repo } = github.context.repo; if (core.getInput('repo')) { @@ -51,6 +52,22 @@ function run() { const number = core.getInput('number') === '' ? github.context.issue.number : parseInt(core.getInput('number')); + if (deduplicate) { + const comments = yield octokit.issues.listComments({ + owner, + repo, + issue_number: number + }); + const comment_ids = comments.data.filter(comment => comment.body.includes(deduplicate)).map(comment => comment.id); + for (const comment_id of comment_ids) { + yield octokit.issues.deleteComment({ + owner, + repo, + issue_number: number, + comment_id + }); + } + } yield octokit.issues.createComment({ owner, repo, diff --git a/src/main.ts b/src/main.ts index c08c019..017a97a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ async function run(): Promise { try { const githubToken = core.getInput('github_token', { required: true }); const body = core.getInput('body', { required: true }); + const deduplicate = core.getInput('deduplicate', { required: false }); const octokit = github.getOctokit(githubToken); @@ -18,6 +19,25 @@ async function run(): Promise { ? github.context.issue.number : parseInt(core.getInput('number')); + if (deduplicate) { + const comments = await octokit.issues.listComments({ + owner, + repo, + issue_number: number + }); + const comment_ids = comments.data.filter(comment => + comment.body.includes(deduplicate) + ).map(comment => comment.id); + for (const comment_id of comment_ids) { + await octokit.issues.deleteComment({ + owner, + repo, + issue_number: number, + comment_id + }); + } + } + await octokit.issues.createComment({ owner, repo,