Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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,
Expand Down
20 changes: 20 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,25 @@ 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.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,
Expand Down