Skip to content

Commit

Permalink
fix: delete should remove all comments with pattern (not only one) (#266
Browse files Browse the repository at this point in the history
)
  • Loading branch information
thollander authored Aug 6, 2023
1 parent 2af827f commit 630516f
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 630516f

Please sign in to comment.