The s-gehring/singleton-comment
action lets you write comments in pull requests as the github-user-bot. However,
instead of creating new comments for every run (ie. pull request update), it finds the older version of the comment and
edits it to keep the PR history clean.
It works similar to peter-evans/create-or-update-comment, but manages to find its older comments by appending IDs to the message body.
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
Hi there
This is a test with markdown
```java
class Example {
public static void main(String[] args) {
System.out.println("I'm example code.");
}
}
```
And I'm **bold**.
However, this comment will be overwritten/edited
once this workflow is triggered again.
Github will add a comment with the given body and update it in every subsequent run instead of creating new ones each time.
However, it will also overwrite other comments created by this action in the same workflow.
This means that the following steps lead to only one comment:
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
Pineapple on pizza is great.
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
Pineapple on pizza is horrible.
There would be a comment claiming that pineapple on pizza is great for a brief moment until it is overwritten by the next step. To define multiple comments, add an ID.
To manage multiple comments simultaneously, you have to provide the corresponding step with an identifier. This identifier should be a string and ideally not contain any whitespaces.
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
Pineapple on pizza is great.
id: some-insane-guy
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
Pineapple on pizza is horrible.
id: some-smart-guy
In this example, two comments will be added to the pull request.
If you want to post on a different thread (ie. pull request or issue), you can supply the action with issue-number
.
- uses: s-gehring/singleton-comment@v1
with:
comment-body: |
I just want to say that there's another pull request by ${{ github.actor }} for this issue.
issue-number: ${{ env.CORRESPONDING_ISSUE }}
This example assumes you somehow managed to attach a corresponding issue number to the pull request (via
a CORRESPONDING_ISSUE
environment variable)
and will create a comment on how there is a pull request for this issue available. However, each time this workflow is
ran it will update the message and therefore the included ${{ github.actor }}
.
comment-body
Required. The comment body to write. This supports the basic markdown github supports.
id
Optional. Default ${{ github.workflow }}
. Used to identify the comment in subsequent action runs.
issue-number
Optional. Default ${{ github.event.pull_request.number }}
. Used to identify the pull request or issue you want the
commit to be written at.
This action makes use of peter-evans actions create-or-update-comment and find-comment. It generates (or uses a given) ID and adds it as a suffix to the comment to identify it later.