peter-evans/create-or-update-comment
Create a new comment, or append to / replace an existing one, on an issue or pull request.
What it does
peter-evans/create-or-update-comment creates a comment on an issue or PR when given issue-number, or updates an existing comment when given comment-id.
Updates default to appending; set edit-mode: replace to overwrite the body. It can also add reactions to the comment.
Usage
workflow (.yml)
on: pull_request
permissions:
pull-requests: write
jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/create-or-update-comment@v5
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Build finished. :rocket:Inputs
| Input | Description | Default | Required |
|---|---|---|---|
token | GITHUB_TOKEN or a repo scoped PAT. | ${{ github.token }} | No |
repository | The full name of the repository in which to create or update a comment. | ${{ github.repository }} | No |
issue-number | The number of the issue or pull request in which to create a comment. | - | No |
comment-id | The id of the comment to update. | - | No |
body | The comment body. Cannot be used in conjunction with body-path. | - | No |
body-path | The path to a file containing the comment body. Cannot be used in conjunction with body. | - | No |
edit-mode | The mode when updating a comment, "replace" or "append". | append | No |
reactions | A comma or newline separated list of reactions to add to the comment. | - | No |
Outputs
| Output | Description |
|---|---|
comment-id | The id of the created comment. |
Notes
PR comments are issue comments under the hood, so issue-number takes the pull request number.
To find an existing bot comment to update, pair with peter-evans/find-comment and pass its output as comment-id.
Common errors
Resource not accessible by integrationmeans the workflow token lacks write permission; addpull-requests: write(PRs) orissues: write(issues) to the job permissions.- Commenting on PRs from forks fails with the default token on
pull_requestevents because the token is read-only there; use thepull_request_targetevent or a separate privileged workflow instead.
Security and pinning
- Grant only
pull-requests: write/issues: write; the action does not needcontentsaccess. Pin to a commit SHA. - Be careful interpolating untrusted PR titles or bodies into
body; preferbody-pathwith content you generated yourself.
Alternatives and related
actions/github-scriptRun inline JavaScript with a preauthenticated GitHub API client, no separate action needed.
peter-evans/create-pull-requestCommit changes made during a workflow and open (or update) a pull request with them.
Frequently asked questions
How do I keep one sticky bot comment per PR instead of adding a new one each run?
Locate the previous comment (e.g. with peter-evans/find-comment), pass its id as
comment-id, and set edit-mode: replace so each run overwrites the same comment.