Skip to content

Commit

Permalink
refactor: remove body require & delete comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xrkffgg committed Apr 13, 2021
1 parent ed4d3a5 commit 02cb739
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v2.0.0

`2021.04.13`

- refactor
- remove `body` required.
- when no `body` input will delete the filter comment.

## v1.2.1

`2021.03.19`
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![](https://img.shields.io/badge/marketplace-maintain--one--comment-blueviolet?style=flat-square)](https://github.com/marketplace/actions/maintain-one-comment)
[![](https://img.shields.io/github/v/release/actions-cool/maintain-one-comment?style=flat-square&color=orange)](https://github.com/actions-cool/maintain-one-comment/releases)

Maintain just one comment in Issue and PR.
Maintain just one comment in Issue and PR.

- This Action is only applicable to triggers related to issue and pull_request
- When the **filtered comments** do not exist, will add a comment
Expand Down Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: maintain-comment
uses: actions-cool/maintain-one-comment@v1.2.0
uses: actions-cool/maintain-one-comment@v2.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Expand All @@ -48,13 +48,14 @@ jobs:
| -- | -- | -- | -- |
| token | GitHub token | string | ✖ |
| number | Manually control the issue or PR number | string | ✖ |
| body | Create comment body | string | |
| body | Create comment body | string | |
| emojis | Add [emoji](#emoji-list) | string | ✖ |
| update-mode | Comment update mode. Options: `replace` `append`. Default: `replace` | string | ✖ |
| comment-auth | Filter comment auth | string | ✖ |
| body-include | Filter comment body | string | ✖ |

- `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

### Outputs

Expand Down
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ inputs:
required: true
body:
description: Comment content.
required: true
emojis:
description: Add emojis to comment.
number:
Expand Down
12 changes: 11 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7058,7 +7058,7 @@ async function run() {
const repo = context.repo.repo;

// 维护评论
const body = core.getInput('body', { require: true });
const body = core.getInput('body');
const emojis = core.getInput('emojis');
let updateMode = core.getInput('update-mode');
if (updateMode !== 'append') {
Expand Down Expand Up @@ -7115,6 +7115,7 @@ async function run() {
}
});
core.info(`filter-comments: ${JSON.stringify(comments)}`);
core.info(`filter-comments-length: ${comments.length}`);
if (comments.length === 0) {
const { data } = await octokit.issues.createComment({
owner,
Expand All @@ -7140,6 +7141,15 @@ async function run() {
}
} else if (comments.length === 1) {
let commentId = comments[0].id;
if (!body) {
await octokit.issues.deleteComment({
owner,
repo,
comment_id: commentId,
});
core.info(`Actions: [delete-comment][${commentId}] success!`);
return false;
}
const comment = await octokit.issues.getComment({
owner,
repo,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maintain-one-comment",
"version": "1.2.0",
"version": "2.0.0",
"private": true,
"description": "Maintain just one comment in Issue and PR.",
"main": "src/main.js",
Expand Down
12 changes: 11 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function run() {
const repo = context.repo.repo;

// 维护评论
const body = core.getInput('body', { require: true });
const body = core.getInput('body');
const emojis = core.getInput('emojis');
let updateMode = core.getInput('update-mode');
if (updateMode !== 'append') {
Expand Down Expand Up @@ -71,6 +71,7 @@ async function run() {
}
});
core.info(`filter-comments: ${JSON.stringify(comments)}`);
core.info(`filter-comments-length: ${comments.length}`);
if (comments.length === 0) {
const { data } = await octokit.issues.createComment({
owner,
Expand All @@ -96,6 +97,15 @@ async function run() {
}
} else if (comments.length === 1) {
let commentId = comments[0].id;
if (!body) {
await octokit.issues.deleteComment({
owner,
repo,
comment_id: commentId,
});
core.info(`Actions: [delete-comment][${commentId}] success!`);
return false;
}
const comment = await octokit.issues.getComment({
owner,
repo,
Expand Down

0 comments on commit 02cb739

Please sign in to comment.