Skip to content

Commit 630516f

Browse files
authored
fix: delete should remove all comments with pattern (not only one) (#266)
1 parent 2af827f commit 630516f

2 files changed

Lines changed: 16 additions & 27 deletions

File tree

lib/cleanup/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9561,22 +9561,18 @@ async function run() {
95619561
}
95629562
const comment_tag_pattern = `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`;
95639563
if (comment_tag_pattern) {
9564-
let comment;
95659564
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
95669565
...context.repo,
95679566
issue_number,
95689567
})) {
9569-
comment = comments.find((comment) => comment?.body?.includes(comment_tag_pattern));
9570-
if (comment)
9571-
break;
9572-
}
9573-
if (comment) {
9574-
core.info(`Deleting comment ${comment.id}.`);
9575-
await octokit.rest.issues.deleteComment({
9576-
...context.repo,
9577-
comment_id: comment.id,
9578-
});
9579-
return;
9568+
const commentsToDelete = comments.filter((comment) => comment?.body?.includes(comment_tag_pattern));
9569+
for (const commentToDelete of commentsToDelete) {
9570+
core.info(`Deleting comment ${commentToDelete.id}.`);
9571+
await octokit.rest.issues.deleteComment({
9572+
...context.repo,
9573+
comment_id: commentToDelete.id,
9574+
});
9575+
}
95809576
}
95819577
}
95829578
return;

src/cleanup.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,18 @@ async function run() {
3232
const comment_tag_pattern = `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`;
3333

3434
if (comment_tag_pattern) {
35-
type ListCommentsResponseDataType = GetResponseDataTypeFromEndpointMethod<
36-
typeof octokit.rest.issues.listComments
37-
>;
38-
let comment: ListCommentsResponseDataType[0] | undefined;
3935
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
4036
...context.repo,
4137
issue_number,
4238
})) {
43-
comment = comments.find((comment) => comment?.body?.includes(comment_tag_pattern));
44-
if (comment) break;
45-
}
46-
47-
if (comment) {
48-
core.info(`Deleting comment ${comment.id}.`);
49-
await octokit.rest.issues.deleteComment({
50-
...context.repo,
51-
comment_id: comment.id,
52-
});
53-
return;
39+
const commentsToDelete = comments.filter((comment) => comment?.body?.includes(comment_tag_pattern));
40+
for (const commentToDelete of commentsToDelete) {
41+
core.info(`Deleting comment ${commentToDelete.id}.`);
42+
await octokit.rest.issues.deleteComment({
43+
...context.repo,
44+
comment_id: commentToDelete.id,
45+
});
46+
}
5447
}
5548
}
5649
return;

0 commit comments

Comments
 (0)