From de04bd2a3750d86b324829a3ff34d47e48e16f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Mon, 1 Aug 2022 10:50:19 +0800 Subject: [PATCH] feat: add delete --- CHANGELOG.md | 1 + README.md | 1 + action.yml | 2 ++ dist/index.js | 20 +++++++++++++++++++- src/main.js | 20 +++++++++++++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd62cf..b68dad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ `2022.08.01` - refactor: add default `body-include`. +- feat: add `delete`. ## v2.0.2 diff --git a/README.md b/README.md index 1912660..f3052ab 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ jobs: | update-mode | Comment update mode. Options: `replace` `append`. Default: `replace` | string | ✖ | | comment-auth | Filter comment auth | string | ✖ | | body-include | Filter comment body | string | ✖ | +| delete | Will delete all filter comments. Default `false` | boolean | ✖ | - `number`: When no input, it will be the issue or PR number that triggered. When input, it is the highest priority - `body`: When has 1 comment, and no body input will delete this filter comment diff --git a/action.yml b/action.yml index 4536861..d7e0fad 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,8 @@ inputs: description: Comment auth filter. body-include: description: Comment body filter. + delete: + description: Will delete all comments outputs: comment-id: diff --git a/dist/index.js b/dist/index.js index e2204fc..b33ea2c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9649,9 +9649,9 @@ async function run() { updateMode = 'replace'; } - // 筛选评论 const commentAuth = core.getInput('comment-auth'); const bodyInclude = core.getInput('body-include') || defaultBody; + const doDelete = core.getInput('delete') === 'true'; // 手动 number const inputNumber = core.getInput('number'); @@ -9700,6 +9700,7 @@ async function run() { }); core.info(`filter-comments: ${JSON.stringify(comments)}`); core.info(`filter-comments-length: ${comments.length}`); + let newCommentId; if (comments.length === 0) { const commentBody = `${body}\n${bodyInclude}`; const { data } = await octokit.issues.createComment({ @@ -9710,6 +9711,7 @@ async function run() { }); core.info(`Actions: [create-comment][${commentBody}] success!`); core.setOutput('comment-id', data.id); + newCommentId = data.id; if (emojis) { dealStringToArr(emojis).forEach(async item => { @@ -9762,6 +9764,22 @@ async function run() { let length = comments.length; core.info(`The comments length is ${length}.`); } + if (doDelete) { + for (const { id } of comments) { + await octokit.issues.deleteComment({ + owner, + repo, + comment_id: id, + }); + } + if (newCommentId) { + await octokit.issues.deleteComment({ + owner, + repo, + comment_id: newCommentId, + }); + } + } core.info(THANKS); } catch (error) { diff --git a/src/main.js b/src/main.js index 2ef48ec..bbc4584 100644 --- a/src/main.js +++ b/src/main.js @@ -24,9 +24,9 @@ async function run() { updateMode = 'replace'; } - // 筛选评论 const commentAuth = core.getInput('comment-auth'); const bodyInclude = core.getInput('body-include') || defaultBody; + const doDelete = core.getInput('delete') === 'true'; // 手动 number const inputNumber = core.getInput('number'); @@ -75,6 +75,7 @@ async function run() { }); core.info(`filter-comments: ${JSON.stringify(comments)}`); core.info(`filter-comments-length: ${comments.length}`); + let newCommentId; if (comments.length === 0) { const commentBody = `${body}\n${bodyInclude}`; const { data } = await octokit.issues.createComment({ @@ -85,6 +86,7 @@ async function run() { }); core.info(`Actions: [create-comment][${commentBody}] success!`); core.setOutput('comment-id', data.id); + newCommentId = data.id; if (emojis) { dealStringToArr(emojis).forEach(async item => { @@ -137,6 +139,22 @@ async function run() { let length = comments.length; core.info(`The comments length is ${length}.`); } + if (doDelete) { + for (const { id } of comments) { + await octokit.issues.deleteComment({ + owner, + repo, + comment_id: id, + }); + } + if (newCommentId) { + await octokit.issues.deleteComment({ + owner, + repo, + comment_id: newCommentId, + }); + } + } core.info(THANKS); } catch (error) {