Create or Update Comment
ActionsTags
(2)A GitHub action to create or update an issue or pull request comment.
-name:Create commentuses:peter-evans/create-or-update-comment@v4with:issue-number:1body:| This is a multi-line test comment - With GitHub **Markdown** :sparkles: - Created by [create-or-update-comment][1] [1]: https://github.com/peter-evans/create-or-update-commentreactions:'+1'
-name:Update commentuses:peter-evans/create-or-update-comment@v4with:comment-id:557858210body:| **Edit:** Some additional inforeactions:eyes
-name:Add reactionsuses:peter-evans/create-or-update-comment@v4with:comment-id:557858210reactions:| heart hooray laugh
Name | Description | Default |
---|---|---|
token | GITHUB_TOKEN (issues: write ,pull-requests: write ) or arepo scopedPAT. | GITHUB_TOKEN |
repository | The full name of the repository in which to create or update a comment. | Current repository |
issue-number | The number of the issue or pull request in which to create a comment. | |
comment-id | The id of the comment to update. | |
body | The comment body. Cannot be used in conjunction withbody-path . | |
body-path | The path to a file containing the comment body. Cannot be used in conjunction withbody . | |
edit-mode | The mode when updating a comment,replace orappend . | append |
append-separator | The separator to use when appending to an existing comment. (newline ,space ,none ) | newline |
reactions | A comma or newline separated list of reactions to add to the comment. (+1 ,-1 ,laugh ,confused ,heart ,hooray ,rocket ,eyes ) | |
reactions-edit-mode | The mode when updating comment reactions,replace orappend . | append |
Note: Inpublic repositories this action does not work inpull_request
workflows when triggered by forks.Any attempt will be met with the error,Resource not accessible by integration
.This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured toenable workflows from forks to run without restriction. Seehere for further explanation. Alternatively, use thepull_request_target
event to comment on pull requests.
The ID of the created comment will be output for use in later steps.Note that in order to read the step output the action step must have an id.
-name:Create commentuses:peter-evans/create-or-update-comment@v4id:coucwith:issue-number:1body:| My comment -name:Check outputsrun:| echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"
How to find the id of a comment will depend a lot on the use case.Here is one example where the id can be found in thegithub
context during anissue_comment
event.
on:issue_comment:types:[created]jobs:commentCreated:runs-on:ubuntu-lateststeps: -name:Add reactionuses:peter-evans/create-or-update-comment@v4with:comment-id:${{ github.event.comment.id }}reactions:eyes
Some use cases might find thefind-comment action useful.This will search an issue or pull request for the first comment containing a specified string, and/or by a specified author.See the repository for detailed usage.
In the following example, find-comment is used to determine if a comment has already been created on a pull request.If the find-comment action outputcomment-id
returns an empty string, a new comment will be created.If it returns a value, the comment already exists and the content is replaced.
-name:Find Commentuses:peter-evans/find-comment@v3id:fcwith:issue-number:${{ github.event.pull_request.number }}comment-author:'github-actions[bot]'body-includes:Build output -name:Create or update commentuses:peter-evans/create-or-update-comment@v4with:comment-id:${{ steps.fc.outputs.comment-id }}issue-number:${{ github.event.pull_request.number }}body:| Build output ${{ steps.build.outputs.build-log }}edit-mode:replace
If required, the create and update steps can be separated for greater control.
-name:Find Commentuses:peter-evans/find-comment@v3id:fcwith:issue-number:${{ github.event.pull_request.number }}comment-author:'github-actions[bot]'body-includes:This comment was written by a bot! -name:Create commentif:steps.fc.outputs.comment-id == ''uses:peter-evans/create-or-update-comment@v4with:issue-number:${{ github.event.pull_request.number }}body:| This comment was written by a bot!reactions:rocket -name:Update commentif:steps.fc.outputs.comment-id != ''uses:peter-evans/create-or-update-comment@v4with:comment-id:${{ steps.fc.outputs.comment-id }}body:| This comment has been updated!reactions:hooray
-name:Create commentuses:peter-evans/create-or-update-comment@v4with:issue-number:1body-path:'comment-body.md'
In this example, a markdown template file is added to the repository at.github/comment-template.md
with the following content.
This is a test comment templateRender template variables such as {{ .foo }} and {{ .bar }}.
The template is rendered using therender-template action and the result is used to create the comment.
-name:Render templateid:templateuses:chuhlomin/render-template@v1.4with:template:.github/comment-template.mdvars:| foo: this bar: that -name:Create commentuses:peter-evans/create-or-update-comment@v4with:issue-number:1body:${{ steps.template.outputs.result }}
You can create and update comments in another repository by using aPAT instead ofGITHUB_TOKEN
.The user associated with the PAT must have write access to the repository.
Create or Update Comment is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.
Tags
(2)Create or Update Comment is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.