Skip to content

Commit

Permalink
fix: delete all comments with pattern instead of one
Browse files Browse the repository at this point in the history
  • Loading branch information
thollander committed Aug 6, 2023
1 parent 2af827f commit 8b1aa90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
20 changes: 8 additions & 12 deletions lib/cleanup/index.js
Expand Up @@ -9561,22 +9561,18 @@ async function run() {
}
const comment_tag_pattern = `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`;
if (comment_tag_pattern) {
let comment;
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
...context.repo,
issue_number,
})) {
comment = comments.find((comment) => comment?.body?.includes(comment_tag_pattern));
if (comment)
break;
}
if (comment) {
core.info(`Deleting comment ${comment.id}.`);
await octokit.rest.issues.deleteComment({
...context.repo,
comment_id: comment.id,
});
return;
const commentsToDelete = comments.filter((comment) => comment?.body?.includes(comment_tag_pattern));
for (const commentToDelete of commentsToDelete) {
core.info(`Deleting comment ${commentToDelete.id}.`);
await octokit.rest.issues.deleteComment({
...context.repo,
comment_id: commentToDelete.id,
});
}
}
}
return;
Expand Down
23 changes: 8 additions & 15 deletions src/cleanup.ts
Expand Up @@ -32,25 +32,18 @@ async function run() {
const comment_tag_pattern = `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`;

if (comment_tag_pattern) {
type ListCommentsResponseDataType = GetResponseDataTypeFromEndpointMethod<
typeof octokit.rest.issues.listComments
>;
let comment: ListCommentsResponseDataType[0] | undefined;
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
...context.repo,
issue_number,
})) {
comment = comments.find((comment) => comment?.body?.includes(comment_tag_pattern));
if (comment) break;
}

if (comment) {
core.info(`Deleting comment ${comment.id}.`);
await octokit.rest.issues.deleteComment({
...context.repo,
comment_id: comment.id,
});
return;
const commentsToDelete = comments.filter((comment) => comment?.body?.includes(comment_tag_pattern));
for (const commentToDelete of commentsToDelete) {
core.info(`Deleting comment ${commentToDelete.id}.`);
await octokit.rest.issues.deleteComment({
...context.repo,
comment_id: commentToDelete.id,
});
}
}
}
return;
Expand Down

0 comments on commit 8b1aa90

Please sign in to comment.