Skip to content

Commit 5a6f828

Browse files
authored
v3 (#115)
* wip * test update body * update action.yml * fix main * test reactions * test body-path * node20 * docs
1 parent 07efeb6 commit 5a6f828

20 files changed

+5956
-5329
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

.eslintrc.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
2-
"env": {
3-
"commonjs": true,
4-
"es6": true,
5-
"node": true
6-
},
7-
"extends": "eslint:recommended",
8-
"globals": {
9-
"Atomics": "readonly",
10-
"SharedArrayBuffer": "readonly"
11-
},
12-
"parserOptions": {
13-
"ecmaVersion": 2018
14-
},
15-
"rules": {
16-
}
17-
}
2+
"env": { "node": true, "jest": true },
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:import/errors",
10+
"plugin:import/warnings",
11+
"plugin:import/typescript",
12+
"plugin:prettier/recommended"
13+
],
14+
"plugins": ["@typescript-eslint"],
15+
"rules": {
16+
"@typescript-eslint/camelcase": "off"
17+
}
18+
}

.github/comment-body-addition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is still the second line.

.github/comment-body.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a multi-line test comment read from a file.
2+
This is the second line.

.github/workflows/ci.yml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ permissions:
1818
jobs:
1919
build:
2020
runs-on: ubuntu-latest
21-
outputs:
22-
sha: ${{ steps.vars.outputs.sha }}
2321
steps:
2422
- uses: actions/checkout@v4
2523
- uses: actions/setup-node@v3
2624
with:
27-
node-version: 16.x
25+
node-version: 20.x
2826
cache: npm
2927
- run: npm ci
28+
- run: npm run build
29+
- run: npm run format-check
30+
- run: npm run lint
3031
- run: npm run test
31-
- run: npm run package
3232
- uses: actions/upload-artifact@v3
3333
with:
3434
name: dist
@@ -60,13 +60,50 @@ jobs:
6060

6161
- name: Test create commit comment
6262
uses: ./
63+
id: cc
6364
with:
6465
body: |
6566
This is a multi-line test comment
6667
- With GitHub **Markdown** :sparkles:
6768
- Created by [commit-comment][1]
6869
6970
[1]: https://github.com/peter-evans/commit-comment
71+
reactions: '+1'
72+
73+
- name: Test update commit comment
74+
uses: ./
75+
with:
76+
comment-id: ${{ steps.cc.outputs.comment-id }}
77+
body: |
78+
**Edit:** Some additional info
79+
reactions: eyes
80+
reactions-edit-mode: replace
81+
82+
- name: Test add reactions
83+
uses: ./
84+
with:
85+
comment-id: ${{ steps.cc.outputs.comment-id }}
86+
reactions: |
87+
heart
88+
hooray
89+
laugh
90+
91+
- name: Test create commit comment from file
92+
uses: ./
93+
id: cc2
94+
with:
95+
body-path: .github/comment-body.md
96+
reactions: |
97+
+1
98+
99+
- name: Test update commit comment from file
100+
uses: ./
101+
with:
102+
comment-id: ${{ steps.cc2.outputs.comment-id }}
103+
body-path: .github/comment-body-addition.md
104+
append-separator: space
105+
reactions: eyes, rocket
106+
reactions-edit-mode: replace
70107

71108
package:
72109
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Update Major Version
2+
run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
target:
8+
description: The target tag or reference
9+
required: true
10+
main_version:
11+
type: choice
12+
description: The major version tag to update
13+
options:
14+
- v3
15+
16+
jobs:
17+
tag:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
23+
fetch-depth: 0
24+
- name: Git config
25+
run: |
26+
git config user.name actions-bot
27+
git config user.email [email protected]
28+
- name: Tag new target
29+
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
30+
- name: Push new tag
31+
run: git push origin ${{ github.event.inputs.main_version }} --force

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
lib/
2+
node_modules/

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid",
10+
"parser": "typescript"
11+
}

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

0 commit comments

Comments
 (0)