Skip to content

Commit

Permalink
feat: add delete
Browse files Browse the repository at this point in the history
  • Loading branch information
xrkffgg committed Aug 1, 2022
1 parent 6ef8e78 commit de04bd2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
`2022.08.01`

- refactor: add default `body-include`.
- feat: add `delete`.

## v2.0.2

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ inputs:
description: Comment auth filter.
body-include:
description: Comment body filter.
delete:
description: Will delete all comments

outputs:
comment-id:
Expand Down
20 changes: 19 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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({
Expand All @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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({
Expand All @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit de04bd2

Please sign in to comment.