https://github.com/edumserrano/find-create-or-update-comment
A composite GitHub action that can be used to create or update a GitHub issue/pull request comment.
https://github.com/edumserrano/find-create-or-update-comment
comment create-comment find-comment github github-action github-actions issue pull-request update-comment
Last synced: 9 months ago
JSON representation
A composite GitHub action that can be used to create or update a GitHub issue/pull request comment.
- Host: GitHub
- URL: https://github.com/edumserrano/find-create-or-update-comment
- Owner: edumserrano
- License: mit
- Created: 2022-07-09T22:59:38.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-25T23:27:52.000Z (11 months ago)
- Last Synced: 2025-07-25T09:53:58.197Z (9 months ago)
- Topics: comment, create-comment, find-comment, github, github-action, github-actions, issue, pull-request, update-comment
- Homepage:
- Size: 67.4 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Find, create or update comment GitHub action
[](https://github.com/edumserrano/find-create-or-update-comment/actions/workflows/test-action.yml)
[](https://github.com/edumserrano/find-create-or-update-comment/actions/workflows/test-action-gh-marketplace.yml)
[](https://github.com/edumserrano/find-create-or-update-comment/actions/workflows/markdown-link-check.yml)
[](https://github.com/marketplace/actions/find-create-or-update-comment)
[](./LICENSE)
[](https://github.com/sponsors/edumserrano)
[](https://www.linkedin.com/in/eduardomserrano/)
- [Description](#description)
- [Why should you use this action ?](#why-should-you-use-this-action-)
- [Usage](#usage)
- [Action inputs](#action-inputs)
- [Dev notes](#dev-notes)
## Description
A composite [GitHub action](https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions) that can be used to find a GitHub Issue or Pull Request comment by a specified value and then update the comment if found or create it if not found.
## Why should you use this action ?
This is nothing more than a combination of the awesome work done by [Peter Evans](https://github.com/peter-evans). I'm combining the [find-comment](https://github.com/peter-evans/find-comment) and the [create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) because I found that I end up using those actions together a lot of the time.
This is a implementation of what is described in [the docs for create-or-update-comment](https://github.com/peter-evans/create-or-update-comment#where-to-find-the-id-of-a-comment).
## Usage
```yml
- name: Update PR with test results
uses: edumserrano/find-create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: ''
comment-author: 'github-actions[bot]'
body: | # can be a single value or you can compose text with multi-line values
My awesome comment
edit-mode: replace
```
The above usage example is using a trick to uniquely identify a comment with some text.
The GitHub comment contains a markdown comment using the `` syntax. The markdown comment text should then be a unique identifier that we can use to search for. This way we can set unique ids for the comments but don't make them visible to the user/whoever is reading the comment on GitHub.
Also note that you can pass input from other steps into the `body` param by doing something like:
```yml
body: |
${{ steps.some-step-id.outputs.some-step-output }}
```
Alternatively to using an inline `body` you can use the `body-path` to specify a file to use.
## Action inputs
| Name | Description | Required | Default value |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | ---------------------------------------- |
| `token` | GITHUB_TOKEN or a repo scoped PAT. | yes | `github.token` (job token) |
| `repository` | The full name of the repository containing the issue or pull request where to find, create or update the comment. | yes | `github.repository` (current repository) |
| `issue-number` | The number of the issue or pull request in which to find, create or update the comment. | yes | - |
| `body-includes` | A string to search for in the body of comments. Cannot be used in conjunction with `body-regex`. | yes, unless `body-regex` is used. | - |
| `body-regex` | A regular expression to search for in the body of comments. Cannot be used in conjunction with `body-includes`. | yes, unless `body-includes` is used. | - |
| `direction` | Search direction, specified as `first` or `last` | no | `first` |
| `nth` | 0-indexed number, specifying which comment to update if multiple are found . | no | 0 |
| `comment-author` | The GitHub user name of the comment author. | false | - |
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | yes, unless `body-path` is used. | - |
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | yes, unless `body` is used. | - |
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | false | `append` |
| `append-separator` | The separator to use when appending to an existing comment. (`newline`, `space`, `none`). | false | `newline` |
| `reactions` | A comma separated list of reactions to add to the comment (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`). | false | - |
| `reactions-edit-mode` | The mode when updating comment reactions, `replace` or `append`. | false | `append` |
## Dev notes
For notes aimed at developers working on this repo or just trying to understand it go [here](/docs/dev-notes/README.md).