Skip to content

Commit

Permalink
Add update-only configuration option (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahatzz11 committed May 2, 2023
1 parent 387ece4 commit 1dff58b
Show file tree
Hide file tree
Showing 11 changed files with 5,949 additions and 13,425 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,6 +7,7 @@ node_modules/

# Editors
.vscode
.idea/**

# Logs
logs
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -82,6 +82,7 @@ jobs:
| allow-repeats | with | Boolean flag to allow identical messages to be posted each time this action is run. | no | false |
| proxy-url | with | String for your proxy service URL if you'd like this to work with fork-based PRs. | no | |
| issue | with | Optional issue number override. | no | |
| update-only | with | Only update the comment if it already exists. | no | |
| GITHUB_TOKEN | env | Valid GitHub token, can alternatively be defined in the env. | no | |

## Advanced Uses
Expand Down Expand Up @@ -197,4 +198,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
10 changes: 10 additions & 0 deletions __tests__/add-pr-comment.test.ts
Expand Up @@ -24,6 +24,7 @@ type Inputs = {
'message-failure'?: string
'message-cancelled'?: string
'message-skipped'?: string
'update-only'?: string
status?: 'success' | 'failure' | 'cancelled' | 'skipped'
}

Expand Down Expand Up @@ -175,6 +176,15 @@ describe('add-pr-comment action', () => {
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
})

it('does not create a comment when updateOnly is true and no existing comment is found', async () => {
inputs.message = simpleMessage
inputs['allow-repeats'] = 'true'
inputs['update-only'] = 'true'

await expect(run()).resolves.not.toThrow()
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'false')
})

it('creates a comment in another repo', async () => {
inputs.message = simpleMessage
inputs['repo-owner'] = 'my-owner'
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -53,6 +53,9 @@ inputs:
issue:
description: "Override the message when a run is cancelled."
required: false
update-only:
description: "Only update the comment if it already exists."
required: false
outputs:
comment-created:
description: "Whether a comment was created."
Expand Down

0 comments on commit 1dff58b

Please sign in to comment.