diff --git a/action.yml b/action.yml index aa980bd..d18a0e4 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: number: description: The number of the issue or pull request. required: false + deduplicate: + description: Value to deduplicate comment + required: false runs: using: node12 main: dist/index.js diff --git a/src/main.ts b/src/main.ts index c08c019..53ce904 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,23 @@ 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.filter(comment => comment.body.includes(deduplicate)) + for (const comment_id of comment_ids) { + await octokit.issues.deleteComment({ + owner, + repo, + issue_number: number, + comment_id, + }) + } + } + await octokit.issues.createComment({ owner, repo,