From 630516fc6533722c61ef2e633786b52ca3250ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9rence=20Hollander?= Date: Sun, 6 Aug 2023 12:29:29 +0200 Subject: [PATCH] fix: delete should remove all comments with pattern (not only one) (#266) --- lib/cleanup/index.js | 20 ++++++++------------ src/cleanup.ts | 23 ++++++++--------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/cleanup/index.js b/lib/cleanup/index.js index 63101dd1..c38436a9 100644 --- a/lib/cleanup/index.js +++ b/lib/cleanup/index.js @@ -9561,22 +9561,18 @@ async function run() { } const comment_tag_pattern = ``; 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; diff --git a/src/cleanup.ts b/src/cleanup.ts index 143cd4fa..9ef2bd51 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -32,25 +32,18 @@ async function run() { const comment_tag_pattern = ``; 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;