Skip to content

Commit

Permalink
Merge pull request #1 from iFixit/add-only-delete
Browse files Browse the repository at this point in the history
actions-comment-pull-request: Add only-delete option
  • Loading branch information
mlahargou authored Apr 11, 2024
2 parents bc14ce3 + e26105f commit 4239952
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ _That is particularly interesting while committing multiple times in a PR and th

Note: the input `mode` can be used to either `upsert` (by default) or `recreate` the comment (= delete and create)

### Delete a comment

Deleting an existing comment is also possible thanks to the `comment_tag` input combined with `mode: delete`.
### Delete a comment on cleanup

This will delete the comment at the end of the job.
Deleting a comment upon job completion is possible with the `mode: delete` flag.
The comment will be created initially, and on cleanup, it will be deleted.

```yml
...
Expand All @@ -110,7 +109,29 @@ This will delete the comment at the end of the job.
```

## Inputs
### Delete a comment

Deleting a comment with a specific `comment_tag` is possible with the
`mode: only-delete` flag. If a comment with the `comment_tag` exists, it will
be deleted when ran.

```yml
...
- name: Create a comment
uses: thollander/actions-comment-pull-request@v2
with:
message: Example comment
comment_tag: to_delete
- name: Delete the comment
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: to_delete
mode: only-delete
```

## Inputs

### Action inputs

Expand Down
17 changes: 14 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9554,8 +9554,8 @@ async function run() {
const reactions = core.getInput('reactions');
const mode = core.getInput('mode');
const create_if_not_exists = core.getInput('create_if_not_exists') === 'true';
if (!message && !filePath) {
core.setFailed('Either "filePath" or "message" should be provided as input');
if (!message && !filePath && mode !== 'only-delete') {
core.setFailed('Either "filePath" or "message" should be provided as input unless running as "only-delete".');
return;
}
let content = message;
Expand Down Expand Up @@ -9651,14 +9651,25 @@ async function run() {
});
return;
}
else if (mode === 'only-delete') {
await deleteComment({
...context.repo,
comment_id: comment.id,
});
return;
}
else if (mode === 'delete') {
core.debug('Registering this comment to be deleted.');
}
else {
core.setFailed(`Mode ${mode} is unknown. Please use 'upsert', 'recreate' or 'delete'.`);
core.setFailed(`Mode ${mode} is unknown. Please use 'upsert', 'recreate', 'delete', or 'only-delete'.`);
return;
}
}
else if (mode === 'only-delete') {
core.info('No comment has been found with asked pattern. Nothing to delete.');
return;
}
else if (create_if_not_exists) {
core.info('No comment has been found with asked pattern. Creating a new comment.');
}
Expand Down
15 changes: 12 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async function run() {
const mode: string = core.getInput('mode');
const create_if_not_exists: boolean = core.getInput('create_if_not_exists') === 'true';

if (!message && !filePath) {
core.setFailed('Either "filePath" or "message" should be provided as input');
if (!message && !filePath && mode !== 'only-delete') {
core.setFailed('Either "filePath" or "message" should be provided as input unless running as "only-delete".');
return;
}

Expand Down Expand Up @@ -157,12 +157,21 @@ async function run() {
body,
});
return;
} else if (mode === 'only-delete') {
await deleteComment({
...context.repo,
comment_id: comment.id,
});
return;
} else if (mode === 'delete') {
core.debug('Registering this comment to be deleted.');
} else {
core.setFailed(`Mode ${mode} is unknown. Please use 'upsert', 'recreate' or 'delete'.`);
core.setFailed(`Mode ${mode} is unknown. Please use 'upsert', 'recreate', 'delete', or 'only-delete'.`);
return;
}
} else if (mode === 'only-delete') {
core.info('No comment has been found with asked pattern. Nothing to delete.');
return;
} else if (create_if_not_exists) {
core.info('No comment has been found with asked pattern. Creating a new comment.');
} else {
Expand Down

0 comments on commit 4239952

Please sign in to comment.