Skip to content

Commit

Permalink
add comment deduplication feature
Browse files Browse the repository at this point in the history
This feature will allow to create a comment and perform a deduplication
of previous comments that match a deduplication key
  • Loading branch information
rodmatos committed Jan 28, 2022
1 parent 2d45440 commit 6865320
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ async function run(): Promise<void> {
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);

Expand All @@ -18,6 +19,23 @@ async function run(): Promise<void> {
? 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,
Expand Down

0 comments on commit 6865320

Please sign in to comment.