Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete should remove all comments with pattern (not only one) #266

Merged
merged 1 commit into from
Aug 6, 2023
Merged
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
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