Skip to content

Commit 8827852

Browse files
committed
docs
1 parent 9001c49 commit 8827852

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

README.md

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,46 @@ A GitHub action to create a comment for a commit on GitHub.
88

99
## Usage
1010

11+
### Add a comment to the current context's commit SHA
12+
13+
The SHA defaults to `github.sha` OR, for `pull_request` events `github.event.pull_request.head.sha`.
14+
1115
```yml
1216
- name: Create commit comment
13-
uses: peter-evans/commit-comment@v2
17+
uses: peter-evans/commit-comment@v3
1418
with:
1519
body: |
1620
This is a multi-line test comment
1721
- With GitHub **Markdown** :sparkles:
1822
- Created by [commit-comment][1]
1923
2024
[1]: https://github.com/peter-evans/commit-comment
25+
reactions: '+1'
26+
```
27+
28+
### Update a commit comment
29+
30+
```yml
31+
- name: Update commit comment
32+
uses: peter-evans/commit-comment@v3
33+
with:
34+
comment-id: 557858210
35+
body: |
36+
**Edit:** Some additional info
37+
reactions: eyes
38+
```
39+
40+
### Add commit comment reactions
41+
42+
```yml
43+
- name: Add reactions
44+
uses: peter-evans/commit-comment@v3
45+
with:
46+
comment-id: 557858210
47+
reactions: |
48+
heart
49+
hooray
50+
laugh
2151
```
2252
2353
## Action inputs
@@ -27,51 +57,74 @@ A GitHub action to create a comment for a commit on GitHub.
2757
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
2858
| `repository` | The full name of the target repository. | `github.repository` (current repository) |
2959
| `sha` | The commit SHA. | `github.sha` OR, for `pull_request` events `github.event.pull_request.head.sha` |
30-
| `body` | (**required**) The contents of the comment. | |
3160
| `path` | Relative path of the file to comment on. | |
3261
| `position` | Line index in the diff to comment on. | |
62+
| `comment-id` | The id of the comment to update. | |
63+
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | |
64+
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
65+
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
66+
| `append-separator` | The separator to use when appending to an existing comment. (`newline`, `space`, `none`) | `newline` |
67+
| `reactions` | A comma or newline separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
68+
| `reactions-edit-mode` | The mode when updating comment reactions, `replace` or `append`. | `append` |
69+
70+
Note: In *public* repositories this action does not work in `pull_request` workflows when triggered by forks.
71+
Any attempt will be met with the error, `Resource not accessible by integration`.
72+
This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured to [enable workflows](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#enabling-workflows-for-forks-of-private-repositories) from forks to run without restriction. See [here](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#restrictions-on-repository-forks) for further explanation. Alternatively, use the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event to comment on pull request commits.
3373

34-
## Example
74+
#### Outputs
3575

36-
Here is an example setting optional input parameters.
76+
The ID of the created comment will be output for use in later steps.
77+
Note that in order to read the step output the action step must have an id.
3778

3879
```yml
3980
- name: Create commit comment
40-
uses: peter-evans/commit-comment@v2
81+
uses: peter-evans/commit-comment@v3
82+
id: cc
4183
with:
42-
sha: 843dea1cc2e721163c20a5c876b5b155f7f3aa75
4384
body: |
44-
This is a multi-line test comment
45-
- With GitHub **Markdown** :sparkles:
46-
- Created by [commit-comment][1]
47-
48-
[1]: https://github.com/peter-evans/commit-comment
49-
path: path/to/file.txt
50-
position: 1
85+
My comment
86+
- name: Check outputs
87+
run: |
88+
echo "Comment ID - ${{ steps.cc.outputs.comment-id }}"
5189
```
5290

5391
### Setting the comment body from a file
5492

55-
This example shows how file content can be read into a variable and passed to the action.
93+
```yml
94+
- name: Create commit comment
95+
uses: peter-evans/commit-comment@v3
96+
with:
97+
body-path: 'comment-body.md'
98+
```
99+
100+
### Using a markdown template
56101

102+
In this example, a markdown template file is added to the repository at `.github/comment-template.md` with the following content.
103+
```
104+
This is a test comment template
105+
Render template variables such as {{ .foo }} and {{ .bar }}.
106+
```
107+
108+
The template is rendered using the [render-template](https://github.com/chuhlomin/render-template) action and the result is used to create the comment.
57109
```yml
58-
- id: get-comment-body
59-
run: |
60-
body="$(cat comment-body.txt)"
61-
delimiter="$(openssl rand -hex 8)"
62-
echo "body<<$delimiter" >> $GITHUB_OUTPUT
63-
echo "$body" >> $GITHUB_OUTPUT
64-
echo "$delimiter" >> $GITHUB_OUTPUT
110+
- name: Render template
111+
id: template
112+
uses: chuhlomin/[email protected]
113+
with:
114+
template: .github/comment-template.md
115+
vars: |
116+
foo: this
117+
bar: that
65118
66119
- name: Create commit comment
67-
uses: peter-evans/commit-comment@v2
120+
uses: peter-evans/commit-comment@v3
68121
with:
69-
body: ${{ steps.get-comment-body.outputs.body }}
122+
body: ${{ steps.template.outputs.result }}
70123
```
71124

72-
### Accessing commits in other repositories
125+
### Accessing commits and comments in other repositories
73126

74-
You can create a commit comment in another repository by using a [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) instead of `GITHUB_TOKEN`.
127+
You can create and update commit comments in another repository by using a [PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) instead of `GITHUB_TOKEN`.
75128
The user associated with the PAT must have write access to the repository.
76129

77130
## License

action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ inputs:
1616
comment-id:
1717
description: 'The id of the comment to update.'
1818
body:
19-
description: 'The contents of the comment.'
20-
required: true
19+
description: 'The comment body. Cannot be used in conjunction with `body-path`.'
2120
body-path:
2221
description: 'The path to a file containing the comment body. Cannot be used in conjunction with `body`.'
2322
edit-mode:

0 commit comments

Comments
 (0)