mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-04-21 20:46:43 +08:00
Compare commits
423 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
17c9563469 | ||
|
9561a839ee | ||
|
227bde71d2 | ||
|
32aab72139 | ||
|
dec9d02d7b | ||
|
fb32f438a0 | ||
|
ed31d72965 | ||
|
5a1e4b77bf | ||
|
55d35600f4 | ||
|
f1e5ccdea6 | ||
|
d5f8886d99 | ||
|
54ad810bfe | ||
|
362dbaf4a8 | ||
|
1a53cbed37 | ||
|
2ef7be1cfa | ||
|
8b3c786931 | ||
|
fdb73c443d | ||
|
853a4fc475 | ||
|
4ed2ee4606 | ||
|
861c151028 | ||
|
d7d9eb5d2f | ||
|
1abf9474b2 | ||
|
267c0605ed | ||
|
7f09200017 | ||
|
7157823c0f | ||
|
213b1f9344 | ||
|
6f2ce0ef39 | ||
|
d5aa8cd1ea | ||
|
1b442971bb | ||
|
42b16d2b6e | ||
|
3b8596da5c | ||
|
48de6373d6 | ||
|
5ddb8ea5d1 | ||
|
b30f7893c6 | ||
|
3c89b509b9 | ||
|
1efb899c24 | ||
|
00b0d20afb | ||
|
56f64a7a94 | ||
|
63d66923dc | ||
|
b91ff48c6f | ||
|
2830915767 | ||
|
0c2659f0c1 | ||
|
842a986c49 | ||
|
e5db2e44ee | ||
|
1df3398968 | ||
|
3496b394e8 | ||
|
382759f176 | ||
|
71ac479718 | ||
|
b9ec24725a | ||
|
1f5fc38003 | ||
|
86dc0e1461 | ||
|
789eec53bf | ||
|
9bb5d837b9 | ||
|
83aca4d345 | ||
|
8da4c50e71 | ||
|
34c499dfd2 | ||
|
da12db3f27 | ||
|
48bb05bd55 | ||
|
8d281ecfdf | ||
|
5e08535dbf | ||
|
5add1d7886 | ||
|
cddb6360ca | ||
|
6ed4065eb0 | ||
|
4e4c9d2bf6 | ||
|
1c8a6fbe1c | ||
|
c79b3ca374 | ||
|
aa56b1e7f9 | ||
|
16e4c42012 | ||
|
647b02623e | ||
|
804884bdc5 | ||
|
ce7ccca07c | ||
|
f25e894721 | ||
|
34e1bba2e5 | ||
|
3509deb8e3 | ||
|
4817051a87 | ||
|
71345be026 | ||
|
d41bfe36e5 | ||
|
73b4b9e4e3 | ||
|
b865fac7fa | ||
|
52b668a928 | ||
|
974f56a1c3 | ||
|
2cbfe8b17b | ||
|
761872a701 | ||
|
72c3238a49 | ||
|
07daf7bbdb | ||
|
0f44b017d1 | ||
|
76318d6ac3 | ||
|
7cc0be4396 | ||
|
6628507542 | ||
|
83d7ae329d | ||
|
79ba7bd9a4 | ||
|
8259733527 | ||
|
f9285f91a1 | ||
|
7e13ba1f24 | ||
|
89116ac2b0 | ||
|
0917427245 | ||
|
80228a8285 | ||
|
b2c2ea48c8 | ||
|
a6e9cd36f5 | ||
|
dcd5071c1f | ||
|
cf8251698e | ||
|
5a1f107ce1 | ||
|
c0693c580c | ||
|
26d9363826 | ||
|
dd628aedf4 | ||
|
05a14f4150 | ||
|
6a7a001078 | ||
|
23ff15729e | ||
|
d85800fae5 | ||
|
ebb1ca6768 | ||
|
ac8e6509d7 | ||
|
8fbd66cf81 | ||
|
8cbbe44679 | ||
|
e3645dd16d | ||
|
23ecd34cbd | ||
|
c3f58b1081 | ||
|
ddff993e3c | ||
|
0e1efacdfc | ||
|
7a2d9c5506 | ||
|
46da6c0d98 | ||
|
44ea087ed1 | ||
|
1f6c51492b | ||
|
1939f16c46 | ||
|
54de4c52d9 | ||
|
f28c1da7d4 | ||
|
4e7a85efa1 | ||
|
223779bc56 | ||
|
e9313d090a | ||
|
46846e53a3 | ||
|
94ff3426b7 | ||
|
1a48da3ac7 | ||
|
8c21c80d8b | ||
|
bb291f63cb | ||
|
1ad8e0897a | ||
|
5f22cb87da | ||
|
38217c6b94 | ||
|
716151b957 | ||
|
30a3d62664 | ||
|
02515d7c92 | ||
|
5a5a8f5c38 | ||
|
d1355c8005 | ||
|
3f97804f16 | ||
|
540f247717 | ||
|
13f4e02a8b | ||
|
df4053dc47 | ||
|
de2c32da77 | ||
|
956659e764 | ||
|
be902aea42 | ||
|
68b012302f | ||
|
c470f6fd6d | ||
|
2b5217e0a0 | ||
|
86c83e68ef | ||
|
3dd3432259 | ||
|
411d7f9b40 | ||
|
1134bfa21c | ||
|
95632dd138 | ||
|
c6c9a1a660 | ||
|
ce3fa353c4 | ||
|
5825e577e3 | ||
|
507508615a | ||
|
33041066d9 | ||
|
84d3b35097 | ||
|
542d5c2467 | ||
|
580d37cf7c | ||
|
f8a0c20f69 | ||
|
6534843181 | ||
|
a58559c2a8 | ||
|
4f5504d403 | ||
|
b1be5176ee | ||
|
c9cf0f59a7 | ||
|
d85efdb15c | ||
|
1d234bb273 | ||
|
214977fb3d | ||
|
7dfe4b0aa0 | ||
|
c1b4d08633 | ||
|
113c4bf0dc | ||
|
8c954f47be | ||
|
38e799a331 | ||
|
73fb0dc8e1 | ||
|
387a6c64a8 | ||
|
2a93c27fda | ||
|
ca08ebd5dc | ||
|
3518fea64b | ||
|
7411122a96 | ||
|
8265d23dc1 | ||
|
f2af028352 | ||
|
af66e5eb29 | ||
|
700b774756 | ||
|
969eeb04b4 | ||
|
594dca4bf4 | ||
|
cf04f35173 | ||
|
6037e73037 | ||
|
67c4b8d37d | ||
|
fb282c6efe | ||
|
e21423b3d8 | ||
|
3383acd359 | ||
|
9c6357680f | ||
|
3d6c0b9c6c | ||
|
1fcda994df | ||
|
5f728c3dae | ||
|
fd9e73cdb1 | ||
|
384c114887 | ||
|
44526e38b6 | ||
|
b1fa5d531f | ||
|
c5a7a9808b | ||
|
7b468d20c2 | ||
|
1833517388 | ||
|
300bfadd23 | ||
|
8f967413c5 | ||
|
521ce1b57b | ||
|
67dcc547d3 | ||
|
41491f71df | ||
|
b00f8b18a4 | ||
|
e0e8aa0075 | ||
|
2cabc739d5 | ||
|
66af805488 | ||
|
c32797f643 | ||
|
d26adaeeda | ||
|
b3af96add5 | ||
|
69c3c2de5d | ||
|
927fa78c9e | ||
|
1e2a7b6412 | ||
|
8b595d3c88 | ||
|
91e0a9faa1 | ||
|
7ac2ba8a42 | ||
|
c66a585f6f | ||
|
5adcb0bb0f | ||
|
deb2c8166c | ||
|
40bf395e0a | ||
|
b9257b685e | ||
|
029195c1ab | ||
|
666805d9f4 | ||
|
9ba2e633cf | ||
|
573dac35ea | ||
|
c78702ac99 | ||
|
ceb52622e3 | ||
|
659fae59ed | ||
|
72ced3ac0a | ||
|
7305482173 | ||
|
aef100f6b4 | ||
|
2b2c85d0bf | ||
|
f128ced803 | ||
|
a43e0b1f83 | ||
|
26db07d4fe | ||
|
ecf01f0a1e | ||
|
fce1b53afe | ||
|
19c6b0636a | ||
|
b0aef464a4 | ||
|
843e855544 | ||
|
6fcd282399 | ||
|
9fb283c956 | ||
|
5fdb3a60d2 | ||
|
7aef7e4136 | ||
|
0459c76fdd | ||
|
dd4db24e6f | ||
|
44485def9c | ||
|
cc3b8eee43 | ||
|
26c5518d73 | ||
|
b95e16d285 | ||
|
acea7ce9ce | ||
|
1fdf65a50f | ||
|
63c92e5e90 | ||
|
9d950b6220 | ||
|
c8abc3fd18 | ||
|
26f0786864 | ||
|
ce67f1bede | ||
|
868b10882d | ||
|
380daa7cb2 | ||
|
6d19bf1a70 | ||
|
3eb1ec0c74 | ||
|
704bc87a2d | ||
|
fb683dc186 | ||
|
d59bec4fa5 | ||
|
c9fcb64660 | ||
|
862a968b68 | ||
|
63e171afd5 | ||
|
741ee28404 | ||
|
ad0c5a2102 | ||
|
d7438411f0 | ||
|
fed340e087 | ||
|
dacf24c705 | ||
|
85a7ce6345 | ||
|
6484e4d98f | ||
|
dfd809e21f | ||
|
e592eff778 | ||
|
68bbb8a5c2 | ||
|
47f61fa9e1 | ||
|
4bed9bafac | ||
|
4bb6df92d5 | ||
|
9f28a7d0f3 | ||
|
3d88f0fef0 | ||
|
6510dffaa9 | ||
|
aec0e42814 | ||
|
1bcb47d3f5 | ||
|
ea336daedc | ||
|
514911011f | ||
|
10d0634e0d | ||
|
085dfa0630 | ||
|
87510f47bf | ||
|
6cfa7f64ae | ||
|
152106b573 | ||
|
a481189ebf | ||
|
4ef0b40d9e | ||
|
54141f84ca | ||
|
f45a0a4d45 | ||
|
02f3870897 | ||
|
2a57ba60e3 | ||
|
38214a08ee | ||
|
a35cf36e53 | ||
|
bc6652c441 | ||
|
90e17f05b7 | ||
|
ac60f19020 | ||
|
d100c275be | ||
|
18800e57aa | ||
|
b12d00d4b0 | ||
|
1def90b73b | ||
|
8cd8b942bb | ||
|
a2be0871da | ||
|
6fb74abd38 | ||
|
8449c316fe | ||
|
2435e87a9c | ||
|
f18a206884 | ||
|
76e0253a2a | ||
|
6c5abee3c4 | ||
|
9bc850ec6e | ||
|
42d0000ec4 | ||
|
5221bf4aa6 | ||
|
76e0f4abc1 | ||
|
9c83ce6081 | ||
|
d813b220d5 | ||
|
c966195fd8 | ||
|
56603d7af0 | ||
|
51c15391ae | ||
|
08f8c2cea3 | ||
|
910158d07e | ||
|
1a85b66140 | ||
|
17d20ac95f | ||
|
cc3d7861d5 | ||
|
f96c36d130 | ||
|
93b7c58cfa | ||
|
4423b7a3c7 | ||
|
bd36cdbff6 | ||
|
f34dc82462 | ||
|
de7c932a12 | ||
|
71d32469a0 | ||
|
ecddc8ec57 | ||
|
ca88ca0121 | ||
|
21f1c3f6d9 | ||
|
5ccb44d973 | ||
|
07044e08a9 | ||
|
0ce5fa62ab | ||
|
a797d011c7 | ||
|
c60de30c46 | ||
|
229435c07f | ||
|
4ca04c9051 | ||
|
6ac6b811b2 | ||
|
8c06d2d0e3 | ||
|
fef50c9801 | ||
|
507a8a6fbd | ||
|
9470f7e873 | ||
|
c3bd15efc2 | ||
|
60a6cb0a1e | ||
|
86c9b97327 | ||
|
e9a82e142f | ||
|
d6b4afe501 | ||
|
3bcb9032d6 | ||
|
41f3207a84 | ||
|
f1bebe1456 | ||
|
2a38a6ba27 | ||
|
86b5d1c799 | ||
|
d7cb4f280b | ||
|
7da2420655 | ||
|
ebe65286bb | ||
|
0dba5db293 | ||
|
86047ba3ad | ||
|
946fe8fa2a | ||
|
10cb16896f | ||
|
093836e1fd | ||
|
1839cd35e2 | ||
|
9d8ab8e752 | ||
|
d114a79b0e | ||
|
add5f413d3 | ||
|
223b941fbf | ||
|
c726fc9beb | ||
|
6d3311ee9b | ||
|
f16b0658f0 | ||
|
4c006bf942 | ||
|
5292e02eb9 | ||
|
e200e285af | ||
|
583b93b4e2 | ||
|
e14d778f32 | ||
|
dc99f6bd48 | ||
|
242194048b | ||
|
ba6e3651b7 | ||
|
d671022a12 | ||
|
44138f1f05 | ||
|
7032041582 | ||
|
1b9b9305c5 | ||
|
7543e413b4 | ||
|
657f251700 | ||
|
8c671cb2d5 | ||
|
c1e8fb2113 | ||
|
5005703541 | ||
|
4dad94677d | ||
|
0bdcad9ffc | ||
|
f93396a2a5 | ||
|
c7f363b6c7 | ||
|
a3cfeddd99 | ||
|
38027e8dbe | ||
|
9f320992d5 | ||
|
4b81c646b9 | ||
|
bfe8b63d3c | ||
|
f15dbd94b6 | ||
|
571222d37c | ||
|
73e8247142 | ||
|
3240b0bd76 | ||
|
e9eda88d56 | ||
|
da580b7831 | ||
|
bcaf92e3fd | ||
|
dc966cb0d5 | ||
|
4fa8664f0d | ||
|
b53806e7a1 | ||
|
2ec3fac455 |
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
lib/
|
||||||
|
node_modules/
|
@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"env": {
|
"env": { "node": true, "jest": true },
|
||||||
"commonjs": true,
|
"parser": "@typescript-eslint/parser",
|
||||||
"es6": true,
|
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
|
||||||
"node": true
|
"extends": [
|
||||||
},
|
"eslint:recommended",
|
||||||
"extends": "eslint:recommended",
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
"globals": {
|
"plugin:@typescript-eslint/recommended",
|
||||||
"Atomics": "readonly",
|
"plugin:import/errors",
|
||||||
"SharedArrayBuffer": "readonly"
|
"plugin:import/warnings",
|
||||||
},
|
"plugin:import/typescript",
|
||||||
"parserOptions": {
|
"plugin:prettier/recommended"
|
||||||
"ecmaVersion": 2018
|
],
|
||||||
},
|
"plugins": ["@typescript-eslint"],
|
||||||
"rules": {
|
"rules": {
|
||||||
}
|
"@typescript-eslint/camelcase": "off"
|
||||||
|
}
|
||||||
}
|
}
|
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
github: peter-evans
|
1
.github/comment-body-addition.md
vendored
Normal file
1
.github/comment-body-addition.md
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is still the second line.
|
2
.github/comment-body.md
vendored
Normal file
2
.github/comment-body.md
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
This is a multi-line test comment read from a file.
|
||||||
|
This is the second line.
|
2
.github/comment-template.md
vendored
Normal file
2
.github/comment-template.md
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
This is a test comment template
|
||||||
|
Render template variables such as {{ .foo }} and {{ .bar }}.
|
20
.github/dependabot.yml
vendored
Normal file
20
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "wednesday"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "wednesday"
|
||||||
|
ignore:
|
||||||
|
- dependency-name: "*"
|
||||||
|
update-types: ["version-update:semver-major"]
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: Auto-merge Dependabot
|
||||||
|
on: pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor == 'dependabot[bot]'
|
||||||
|
steps:
|
||||||
|
- uses: peter-evans/enable-pull-request-automerge@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
pull-request-number: ${{ github.event.pull_request.number }}
|
||||||
|
merge-method: squash
|
142
.github/workflows/ci.yml
vendored
Normal file
142
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- 'docs/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- 'docs/**'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
issue-number: ${{ steps.vars.outputs.issue-number }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20.x
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run format-check
|
||||||
|
- run: npm run lint
|
||||||
|
- run: npm run test
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: action.yml
|
||||||
|
path: action.yml
|
||||||
|
- id: vars
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then \
|
||||||
|
echo "issue-number=${{ github.event.number }}" >> $GITHUB_OUTPUT; \
|
||||||
|
else \
|
||||||
|
echo "issue-number=1" >> $GITHUB_OUTPUT; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
|
||||||
|
needs: [build]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
target: [built, committed]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist
|
||||||
|
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: action.yml
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Test create comment
|
||||||
|
uses: ./
|
||||||
|
id: couc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ needs.build.outputs.issue-number }}
|
||||||
|
body: |
|
||||||
|
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-comment
|
||||||
|
reactions: '+1'
|
||||||
|
|
||||||
|
- name: Test update comment
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
body: |
|
||||||
|
**Edit:** Some additional info
|
||||||
|
reactions: eyes
|
||||||
|
reactions-edit-mode: replace
|
||||||
|
|
||||||
|
- name: Test add reactions
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
reactions: |
|
||||||
|
heart
|
||||||
|
hooray
|
||||||
|
laugh
|
||||||
|
|
||||||
|
- name: Test create comment from file
|
||||||
|
uses: ./
|
||||||
|
id: couc2
|
||||||
|
with:
|
||||||
|
issue-number: ${{ needs.build.outputs.issue-number }}
|
||||||
|
body-path: .github/comment-body.md
|
||||||
|
reactions: |
|
||||||
|
+1
|
||||||
|
|
||||||
|
- name: Test update comment from file
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.couc2.outputs.comment-id }}
|
||||||
|
body-path: .github/comment-body-addition.md
|
||||||
|
append-separator: space
|
||||||
|
reactions: eyes, rocket
|
||||||
|
reactions-edit-mode: replace
|
||||||
|
|
||||||
|
package:
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
needs: [test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v7
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
commit-message: Update distribution
|
||||||
|
title: Update distribution
|
||||||
|
body: |
|
||||||
|
- Updates the distribution for changes on `main`
|
||||||
|
|
||||||
|
Auto-generated by [create-pull-request][1]
|
||||||
|
|
||||||
|
[1]: https://github.com/peter-evans/create-pull-request
|
||||||
|
branch: update-distribution
|
29
.github/workflows/create-comment.yml
vendored
29
.github/workflows/create-comment.yml
vendored
@ -1,29 +0,0 @@
|
|||||||
name: Create Comment
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
jobs:
|
|
||||||
createComment:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# For debugging purposes. Remove this in production.
|
|
||||||
- name: Dump GitHub context
|
|
||||||
env:
|
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
|
|
||||||
- name: Create comment
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
issue-number: 1
|
|
||||||
body: |
|
|
||||||
This is a multi-line test comment
|
|
||||||
- With GitHub **Markdown**
|
|
||||||
- Created by [create-or-update-comment][1]
|
|
||||||
|
|
||||||
[1]: https://github.com/peter-evans/create-or-update-comment
|
|
||||||
reaction-type: '+1'
|
|
26
.github/workflows/slash-command-dispatch.yml
vendored
Normal file
26
.github/workflows/slash-command-dispatch.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Slash Command Dispatch
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
jobs:
|
||||||
|
slashCommandDispatch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Slash Command Dispatch
|
||||||
|
uses: peter-evans/slash-command-dispatch@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
config: >
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"command": "rebase",
|
||||||
|
"permission": "admin",
|
||||||
|
"repository": "peter-evans/slash-command-dispatch-processor",
|
||||||
|
"issue_type": "pull-request"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "test",
|
||||||
|
"permission": "admin",
|
||||||
|
"named_args": true
|
||||||
|
}
|
||||||
|
]
|
85
.github/workflows/test-command.yml
vendored
Normal file
85
.github/workflows/test-command.yml
vendored
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
name: Test Command
|
||||||
|
on:
|
||||||
|
repository_dispatch:
|
||||||
|
types: [test-command]
|
||||||
|
jobs:
|
||||||
|
testCreateOrUpdateComment:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Get the target repository and branch
|
||||||
|
- name: Get the target repository and branch
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
repository=${{ github.event.client_payload.slash_command.repository }}
|
||||||
|
if [[ -z "$repository" ]]; then repository=${{ github.repository }}; fi
|
||||||
|
echo "repository=$repository" >> $GITHUB_OUTPUT
|
||||||
|
branch=${{ github.event.client_payload.slash_command.branch }}
|
||||||
|
if [[ -z "$branch" ]]; then branch="main"; fi
|
||||||
|
echo "branch=$branch" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# Checkout the branch to test
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ steps.vars.outputs.repository }}
|
||||||
|
ref: ${{ steps.vars.outputs.branch }}
|
||||||
|
|
||||||
|
# Test create
|
||||||
|
- name: Create comment
|
||||||
|
uses: ./
|
||||||
|
id: couc
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body: |
|
||||||
|
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-comment
|
||||||
|
reactions: '+1'
|
||||||
|
|
||||||
|
# Test update
|
||||||
|
- name: Update comment
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
body: |
|
||||||
|
**Edit:** Some additional info
|
||||||
|
reactions: eyes
|
||||||
|
reactions-edit-mode: replace
|
||||||
|
|
||||||
|
# Test add reactions
|
||||||
|
- name: Add reactions
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
reactions: heart, hooray, laugh
|
||||||
|
|
||||||
|
# Test create with body from file
|
||||||
|
- name: Create comment
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body-path: .github/comment-body.md
|
||||||
|
|
||||||
|
# Test create from template
|
||||||
|
- name: Render template
|
||||||
|
id: template
|
||||||
|
uses: chuhlomin/render-template@v1.10
|
||||||
|
with:
|
||||||
|
template: .github/comment-template.md
|
||||||
|
vars: |
|
||||||
|
foo: this
|
||||||
|
bar: that
|
||||||
|
|
||||||
|
- name: Create comment
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body: ${{ steps.template.outputs.result }}
|
||||||
|
|
||||||
|
- name: Add reaction
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
|
||||||
|
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
|
||||||
|
reactions: hooray
|
66
.github/workflows/test-v3.yml
vendored
Normal file
66
.github/workflows/test-v3.yml
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Test v3
|
||||||
|
on: workflow_dispatch
|
||||||
|
jobs:
|
||||||
|
testCreateOrUpdateComment:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Test create
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
id: couc
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
issue-number: 1
|
||||||
|
body: |
|
||||||
|
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-comment
|
||||||
|
reactions: '+1'
|
||||||
|
|
||||||
|
# Test update
|
||||||
|
- name: Update comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
body: |
|
||||||
|
**Edit:** Some additional info
|
||||||
|
reactions: eyes
|
||||||
|
reactions-edit-mode: replace
|
||||||
|
|
||||||
|
# Test add reactions
|
||||||
|
- name: Add reactions
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
comment-id: ${{ steps.couc.outputs.comment-id }}
|
||||||
|
reactions: heart, hooray, laugh
|
||||||
|
|
||||||
|
# Test create with body from file
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
issue-number: 1
|
||||||
|
body-file: .github/comment-body.md
|
||||||
|
|
||||||
|
# Test create from template
|
||||||
|
- name: Render template
|
||||||
|
id: template
|
||||||
|
uses: chuhlomin/render-template@v1.10
|
||||||
|
with:
|
||||||
|
template: .github/comment-template.md
|
||||||
|
vars: |
|
||||||
|
foo: this
|
||||||
|
bar: that
|
||||||
|
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
issue-number: 1
|
||||||
|
body: ${{ steps.template.outputs.result }}
|
33
.github/workflows/update-comment.yml
vendored
33
.github/workflows/update-comment.yml
vendored
@ -1,33 +0,0 @@
|
|||||||
name: Update Comment
|
|
||||||
on:
|
|
||||||
issue_comment:
|
|
||||||
types: [created]
|
|
||||||
jobs:
|
|
||||||
updateComment:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# For debugging purposes. Remove this in production.
|
|
||||||
- name: Dump GitHub context
|
|
||||||
env:
|
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
|
|
||||||
- name: Update comment
|
|
||||||
if: github.event.issue.number == 1
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
comment-id: ${{ github.event.comment.id }}
|
|
||||||
body: |
|
|
||||||
**Edit:** Some additional info
|
|
||||||
reaction-type: eyes
|
|
||||||
|
|
||||||
- name: Add reaction
|
|
||||||
if: github.event.issue.number == 1
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
comment-id: ${{ github.event.comment.id }}
|
|
||||||
reaction-type: heart
|
|
32
.github/workflows/update-major-version.yml
vendored
Normal file
32
.github/workflows/update-major-version.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
name: Update Major Version
|
||||||
|
run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
target:
|
||||||
|
description: The target tag or reference
|
||||||
|
required: true
|
||||||
|
main_version:
|
||||||
|
type: choice
|
||||||
|
description: The major version tag to update
|
||||||
|
options:
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Git config
|
||||||
|
run: |
|
||||||
|
git config user.name actions-bot
|
||||||
|
git config user.email actions-bot@users.noreply.github.com
|
||||||
|
- name: Tag new target
|
||||||
|
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
|
||||||
|
- name: Push new tag
|
||||||
|
run: git push origin ${{ github.event.inputs.main_version }} --force
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
node_modules
|
lib/
|
||||||
|
node_modules/
|
||||||
|
3
.prettierignore
Normal file
3
.prettierignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
lib/
|
||||||
|
node_modules/
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"parser": "typescript"
|
||||||
|
}
|
157
README.md
157
README.md
@ -1,64 +1,88 @@
|
|||||||
# Create or Update Comment
|
# Create or Update Comment
|
||||||
|
[](https://github.com/peter-evans/create-or-update-comment/actions?query=workflow%3ACI)
|
||||||
[](https://github.com/marketplace/actions/create-or-update-comment)
|
[](https://github.com/marketplace/actions/create-or-update-comment)
|
||||||
|
|
||||||
A GitHub action to create or update an issue or pull request comment.
|
A GitHub action to create or update an issue or pull request comment.
|
||||||
|
|
||||||
This action was created to help facilitate a GitHub Actions "ChatOps" solution in conjunction with [slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) action.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Add a comment to an issue or pull request
|
### Add a comment to an issue or pull request
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Create comment
|
- name: Create comment
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
issue-number: 1
|
issue-number: 1
|
||||||
body: |
|
body: |
|
||||||
This is a multi-line test comment
|
This is a multi-line test comment
|
||||||
- With GitHub **Markdown**
|
- With GitHub **Markdown** :sparkles:
|
||||||
- Created by [create-or-update-comment][1]
|
- Created by [create-or-update-comment][1]
|
||||||
|
|
||||||
[1]: https://github.com/peter-evans/create-or-update-comment
|
[1]: https://github.com/peter-evans/create-or-update-comment
|
||||||
reaction-type: '+1'
|
reactions: '+1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Update a comment
|
### Update a comment
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Update comment
|
- name: Update comment
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
comment-id: 557858210
|
comment-id: 557858210
|
||||||
body: |
|
body: |
|
||||||
**Edit:** Some additional info
|
**Edit:** Some additional info
|
||||||
reaction-type: eyes
|
reactions: eyes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add a comment reaction
|
### Add comment reactions
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Add reaction
|
- name: Add reactions
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
comment-id: 557858210
|
comment-id: 557858210
|
||||||
reaction-type: heart
|
reactions: |
|
||||||
|
heart
|
||||||
|
hooray
|
||||||
|
laugh
|
||||||
```
|
```
|
||||||
|
|
||||||
### Action inputs
|
### Action inputs
|
||||||
|
|
||||||
| Name | Description | Default |
|
| Name | Description | Default |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | |
|
| `token` | `GITHUB_TOKEN` (`issues: write`, `pull-requests: write`) or a `repo` scoped [PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). | `GITHUB_TOKEN` |
|
||||||
| `repository` | The full name of the repository in which to create or update a comment. | Current repository |
|
| `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. | |
|
| `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. | |
|
| `comment-id` | The id of the comment to update. | |
|
||||||
| `body` | The comment body. | |
|
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | |
|
||||||
|
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
|
||||||
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
|
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
|
||||||
| `reaction-type` | The reaction to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
|
| `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` or `append`. | `append` |
|
||||||
|
|
||||||
|
Note: In *public* repositories this action does not work in `pull_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 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 requests.
|
||||||
|
|
||||||
|
#### Outputs
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
id: couc
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body: |
|
||||||
|
My comment
|
||||||
|
- name: Check outputs
|
||||||
|
run: |
|
||||||
|
echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"
|
||||||
|
```
|
||||||
|
|
||||||
### Where to find the id of a comment
|
### Where to find the id of a comment
|
||||||
|
|
||||||
@ -74,16 +98,107 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Add reaction
|
- name: Add reaction
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
comment-id: ${{ github.event.comment.id }}
|
comment-id: ${{ github.event.comment.id }}
|
||||||
reaction-type: eyes
|
reactions: eyes
|
||||||
|
```
|
||||||
|
|
||||||
|
Some use cases might find the [find-comment](https://github.com/peter-evans/find-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 output `comment-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.
|
||||||
|
```yml
|
||||||
|
- name: Find Comment
|
||||||
|
uses: peter-evans/find-comment@v3
|
||||||
|
id: fc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: 'github-actions[bot]'
|
||||||
|
body-includes: Build output
|
||||||
|
|
||||||
|
- name: Create or update comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
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.
|
||||||
|
```yml
|
||||||
|
- name: Find Comment
|
||||||
|
uses: peter-evans/find-comment@v3
|
||||||
|
id: fc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: 'github-actions[bot]'
|
||||||
|
body-includes: This comment was written by a bot!
|
||||||
|
|
||||||
|
- name: Create comment
|
||||||
|
if: steps.fc.outputs.comment-id == ''
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
This comment was written by a bot!
|
||||||
|
reactions: rocket
|
||||||
|
|
||||||
|
- name: Update comment
|
||||||
|
if: steps.fc.outputs.comment-id != ''
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
body: |
|
||||||
|
This comment has been updated!
|
||||||
|
reactions: hooray
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setting the comment body from a file
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body-path: 'comment-body.md'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using a markdown template
|
||||||
|
|
||||||
|
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 template
|
||||||
|
Render template variables such as {{ .foo }} and {{ .bar }}.
|
||||||
|
```
|
||||||
|
|
||||||
|
The template is rendered using the [render-template](https://github.com/chuhlomin/render-template) action and the result is used to create the comment.
|
||||||
|
```yml
|
||||||
|
- name: Render template
|
||||||
|
id: template
|
||||||
|
uses: chuhlomin/render-template@v1.4
|
||||||
|
with:
|
||||||
|
template: .github/comment-template.md
|
||||||
|
vars: |
|
||||||
|
foo: this
|
||||||
|
bar: that
|
||||||
|
|
||||||
|
- name: Create comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
issue-number: 1
|
||||||
|
body: ${{ steps.template.outputs.result }}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Accessing issues and comments in other repositories
|
### Accessing issues and comments in other repositories
|
||||||
|
|
||||||
You can create and update comments in another repository by using a [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) instead of `GITHUB_TOKEN`.
|
You can create and update 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`.
|
||||||
The user associated with the PAT must have write access to the repository.
|
The user associated with the PAT must have write access to the repository.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
25
action.yml
25
action.yml
@ -3,21 +3,36 @@ description: 'Create or update an issue or pull request comment'
|
|||||||
inputs:
|
inputs:
|
||||||
token:
|
token:
|
||||||
description: 'GITHUB_TOKEN or a repo scoped PAT.'
|
description: 'GITHUB_TOKEN or a repo scoped PAT.'
|
||||||
required: true
|
default: ${{ github.token }}
|
||||||
repository:
|
repository:
|
||||||
description: 'The full name of the repository in which to create or update a comment.'
|
description: 'The full name of the repository in which to create or update a comment.'
|
||||||
|
default: ${{ github.repository }}
|
||||||
issue-number:
|
issue-number:
|
||||||
description: 'The number of the issue or pull request in which to create a comment.'
|
description: 'The number of the issue or pull request in which to create a comment.'
|
||||||
comment-id:
|
comment-id:
|
||||||
description: 'The id of the comment to update.'
|
description: 'The id of the comment to update.'
|
||||||
body:
|
body:
|
||||||
description: 'The comment body.'
|
description: 'The comment body. Cannot be used in conjunction with `body-path`.'
|
||||||
|
body-path:
|
||||||
|
description: 'The path to a file containing the comment body. Cannot be used in conjunction with `body`.'
|
||||||
|
body-file:
|
||||||
|
description: 'Deprecated in favour of `body-path`.'
|
||||||
edit-mode:
|
edit-mode:
|
||||||
description: 'The mode when updating a comment, "replace" or "append".'
|
description: 'The mode when updating a comment, "replace" or "append".'
|
||||||
reaction-type:
|
default: 'append'
|
||||||
description: 'The reaction to add to the comment.'
|
append-separator:
|
||||||
|
description: 'The separator to use when appending to an existing comment. (`newline`, `space`, `none`)'
|
||||||
|
default: 'newline'
|
||||||
|
reactions:
|
||||||
|
description: 'A comma or newline separated list of reactions to add to the comment.'
|
||||||
|
reactions-edit-mode:
|
||||||
|
description: 'The mode when updating comment reactions, "replace" or "append".'
|
||||||
|
default: 'append'
|
||||||
|
outputs:
|
||||||
|
comment-id:
|
||||||
|
description: 'The id of the created comment'
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'message-square'
|
icon: 'message-square'
|
||||||
|
42782
dist/index.js
vendored
42782
dist/index.js
vendored
File diff suppressed because one or more lines are too long
121
index.js
121
index.js
@ -1,121 +0,0 @@
|
|||||||
const { inspect } = require("util");
|
|
||||||
const core = require("@actions/core");
|
|
||||||
const github = require("@actions/github");
|
|
||||||
|
|
||||||
const REACTION_TYPES = [
|
|
||||||
"+1",
|
|
||||||
"-1",
|
|
||||||
"laugh",
|
|
||||||
"confused",
|
|
||||||
"heart",
|
|
||||||
"hooray",
|
|
||||||
"rocket",
|
|
||||||
"eyes"
|
|
||||||
];
|
|
||||||
|
|
||||||
async function addReaction(octokit, repo, comment_id, reactionType) {
|
|
||||||
if (REACTION_TYPES.includes(reactionType)) {
|
|
||||||
await octokit.reactions.createForIssueComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
comment_id: comment_id,
|
|
||||||
content: reactionType
|
|
||||||
});
|
|
||||||
core.info(`Set '${reactionType}' reaction on comment.`);
|
|
||||||
} else {
|
|
||||||
core.setFailed("Invalid 'reaction-type'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
try {
|
|
||||||
const inputs = {
|
|
||||||
token: core.getInput("token"),
|
|
||||||
repository: core.getInput("repository"),
|
|
||||||
issueNumber: core.getInput("issue-number"),
|
|
||||||
commentId: core.getInput("comment-id"),
|
|
||||||
body: core.getInput("body"),
|
|
||||||
editMode: core.getInput("edit-mode"),
|
|
||||||
reactionType: core.getInput("reaction-type")
|
|
||||||
};
|
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`);
|
|
||||||
|
|
||||||
const repository = inputs.repository
|
|
||||||
? inputs.repository
|
|
||||||
: process.env.GITHUB_REPOSITORY;
|
|
||||||
const repo = repository.split("/");
|
|
||||||
core.debug(`repository: ${repository}`);
|
|
||||||
|
|
||||||
const editMode = inputs.editMode ? inputs.editMode : "append";
|
|
||||||
core.debug(`editMode: ${editMode}`);
|
|
||||||
if (!["append", "replace"].includes(editMode)) {
|
|
||||||
core.setFailed(`Invalid edit-mode '${editMode}'.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const octokit = new github.GitHub(inputs.token);
|
|
||||||
|
|
||||||
if (inputs.commentId) {
|
|
||||||
// Edit a comment
|
|
||||||
if (!inputs.body && !inputs.reactionType) {
|
|
||||||
core.setFailed("Missing either comment 'body' or 'reaction-type'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputs.body) {
|
|
||||||
var commentBody = "";
|
|
||||||
if (editMode == "append") {
|
|
||||||
// Get the comment body
|
|
||||||
const { data: comment } = await octokit.issues.getComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
comment_id: inputs.commentId
|
|
||||||
});
|
|
||||||
commentBody = comment.body + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
commentBody = commentBody + inputs.body;
|
|
||||||
core.debug(`Comment body: ${commentBody}`);
|
|
||||||
await octokit.issues.updateComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
comment_id: inputs.commentId,
|
|
||||||
body: commentBody
|
|
||||||
});
|
|
||||||
core.info(`Updated comment id '${inputs.commentId}'.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a comment reaction
|
|
||||||
if (inputs.reactionType) {
|
|
||||||
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
|
|
||||||
}
|
|
||||||
} else if (inputs.issueNumber) {
|
|
||||||
// Create a comment
|
|
||||||
if (!inputs.body) {
|
|
||||||
core.setFailed("Missing comment 'body'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { data: comment } = await octokit.issues.createComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
issue_number: inputs.issueNumber,
|
|
||||||
body: inputs.body
|
|
||||||
});
|
|
||||||
core.info(`Created comment on issue '${inputs.issueNumber}'.`);
|
|
||||||
|
|
||||||
// Set a comment reaction
|
|
||||||
if (inputs.reactionType) {
|
|
||||||
await addReaction(octokit, repo, comment.id, inputs.reactionType);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
core.setFailed("Missing either 'issue-number' or 'comment-id'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
core.debug(inspect(error));
|
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
11
jest.config.js
Normal file
11
jest.config.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/*.test.ts'],
|
||||||
|
testRunner: 'jest-circus/runner',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
verbose: true
|
||||||
|
}
|
12390
package-lock.json
generated
12390
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@ -1,18 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "create-or-update-comment",
|
"name": "create-or-update-comment",
|
||||||
"version": "1.0.0",
|
"version": "4.0.0",
|
||||||
"description": "Create or update an issue or pull request comment",
|
"description": "Create or update an issue or pull request comment",
|
||||||
"main": "index.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint index.js",
|
"build": "tsc && ncc build",
|
||||||
"package": "ncc build index.js -o dist",
|
"format": "prettier --write '**/*.ts'",
|
||||||
"test": "eslint index.js && jest --passWithNoTests"
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
|
"lint": "eslint src/**/*.ts",
|
||||||
|
"test": "jest --passWithNoTests"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/peter-evans/create-or-update-comment.git"
|
"url": "git+https://github.com/peter-evans/create-or-update-comment.git"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [
|
||||||
|
"actions",
|
||||||
|
"create",
|
||||||
|
"update",
|
||||||
|
"comment"
|
||||||
|
],
|
||||||
"author": "Peter Evans",
|
"author": "Peter Evans",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@ -20,12 +27,24 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/peter-evans/create-or-update-comment#readme",
|
"homepage": "https://github.com/peter-evans/create-or-update-comment#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.1.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/github": "^2.0.0"
|
"@actions/github": "^6.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@zeit/ncc": "0.22.0",
|
"@types/jest": "^27.0.3",
|
||||||
"eslint": "6.8.0",
|
"@types/node": "^18.19.86",
|
||||||
"jest": "25.2.3"
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||||
|
"@typescript-eslint/parser": "^5.62.0",
|
||||||
|
"@vercel/ncc": "^0.38.3",
|
||||||
|
"eslint": "^8.57.1",
|
||||||
|
"eslint-plugin-github": "^4.10.2",
|
||||||
|
"eslint-plugin-jest": "^27.9.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.6",
|
||||||
|
"jest": "^27.5.1",
|
||||||
|
"jest-circus": "^27.5.1",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
|
"prettier": "^3.5.3",
|
||||||
|
"ts-jest": "^27.1.5",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"config:base"
|
|
||||||
]
|
|
||||||
}
|
|
282
src/create-or-update-comment.ts
Normal file
282
src/create-or-update-comment.ts
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
import * as github from '@actions/github'
|
||||||
|
import * as utils from './utils'
|
||||||
|
import {inspect} from 'util'
|
||||||
|
|
||||||
|
export interface Inputs {
|
||||||
|
token: string
|
||||||
|
repository: string
|
||||||
|
issueNumber: number
|
||||||
|
commentId: number
|
||||||
|
body: string
|
||||||
|
bodyPath: string
|
||||||
|
editMode: string
|
||||||
|
appendSeparator: string
|
||||||
|
reactions: string[]
|
||||||
|
reactionsEditMode: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const REACTION_TYPES = [
|
||||||
|
'+1',
|
||||||
|
'-1',
|
||||||
|
'laugh',
|
||||||
|
'confused',
|
||||||
|
'heart',
|
||||||
|
'hooray',
|
||||||
|
'rocket',
|
||||||
|
'eyes'
|
||||||
|
]
|
||||||
|
|
||||||
|
function getReactionsSet(reactions: string[]): string[] {
|
||||||
|
const reactionsSet = [
|
||||||
|
...new Set(
|
||||||
|
reactions.filter(item => {
|
||||||
|
if (!REACTION_TYPES.includes(item)) {
|
||||||
|
core.warning(`Skipping invalid reaction '${item}'.`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
)
|
||||||
|
]
|
||||||
|
if (!reactionsSet) {
|
||||||
|
throw new Error(`No valid reactions are contained in '${reactions}'.`)
|
||||||
|
}
|
||||||
|
return reactionsSet
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addReactions(
|
||||||
|
octokit,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
commentId: number,
|
||||||
|
reactions: string[]
|
||||||
|
) {
|
||||||
|
const results = await Promise.allSettled(
|
||||||
|
reactions.map(async reaction => {
|
||||||
|
await octokit.rest.reactions.createForIssueComment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
comment_id: commentId,
|
||||||
|
content: reaction
|
||||||
|
})
|
||||||
|
core.info(`Setting '${reaction}' reaction on comment.`)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
for (let i = 0, l = results.length; i < l; i++) {
|
||||||
|
if (results[i].status === 'fulfilled') {
|
||||||
|
core.info(
|
||||||
|
`Added reaction '${reactions[i]}' to comment id '${commentId}'.`
|
||||||
|
)
|
||||||
|
} else if (results[i].status === 'rejected') {
|
||||||
|
core.warning(
|
||||||
|
`Adding reaction '${reactions[i]}' to comment id '${commentId}' failed.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeReactions(
|
||||||
|
octokit,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
commentId: number,
|
||||||
|
reactions: Reaction[]
|
||||||
|
) {
|
||||||
|
const results = await Promise.allSettled(
|
||||||
|
reactions.map(async reaction => {
|
||||||
|
await octokit.rest.reactions.deleteForIssueComment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
comment_id: commentId,
|
||||||
|
reaction_id: reaction.id
|
||||||
|
})
|
||||||
|
core.info(`Removing '${reaction.content}' reaction from comment.`)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
for (let i = 0, l = results.length; i < l; i++) {
|
||||||
|
if (results[i].status === 'fulfilled') {
|
||||||
|
core.info(
|
||||||
|
`Removed reaction '${reactions[i].content}' from comment id '${commentId}'.`
|
||||||
|
)
|
||||||
|
} else if (results[i].status === 'rejected') {
|
||||||
|
core.warning(
|
||||||
|
`Removing reaction '${reactions[i].content}' from comment id '${commentId}' failed.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendSeparatorTo(body: string, separator: string): string {
|
||||||
|
switch (separator) {
|
||||||
|
case 'newline':
|
||||||
|
return body + '\n'
|
||||||
|
case 'space':
|
||||||
|
return body + ' '
|
||||||
|
default: // none
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function truncateBody(body: string) {
|
||||||
|
// 65536 characters is the maximum allowed for issue comments.
|
||||||
|
const truncateWarning = '...*[Comment body truncated]*'
|
||||||
|
if (body.length > 65536) {
|
||||||
|
core.warning(`Comment body is too long. Truncating to 65536 characters.`)
|
||||||
|
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning
|
||||||
|
}
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createComment(
|
||||||
|
octokit,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
issueNumber: number,
|
||||||
|
body: string
|
||||||
|
): Promise<number> {
|
||||||
|
body = truncateBody(body)
|
||||||
|
|
||||||
|
const {data: comment} = await octokit.rest.issues.createComment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
issue_number: issueNumber,
|
||||||
|
body
|
||||||
|
})
|
||||||
|
core.info(`Created comment id '${comment.id}' on issue '${issueNumber}'.`)
|
||||||
|
return comment.id
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateComment(
|
||||||
|
octokit,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
commentId: number,
|
||||||
|
body: string,
|
||||||
|
editMode: string,
|
||||||
|
appendSeparator: string
|
||||||
|
): Promise<number> {
|
||||||
|
if (body) {
|
||||||
|
let commentBody = ''
|
||||||
|
if (editMode == 'append') {
|
||||||
|
// Get the comment body
|
||||||
|
const {data: comment} = await octokit.rest.issues.getComment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
comment_id: commentId
|
||||||
|
})
|
||||||
|
commentBody = appendSeparatorTo(
|
||||||
|
comment.body ? comment.body : '',
|
||||||
|
appendSeparator
|
||||||
|
)
|
||||||
|
}
|
||||||
|
commentBody = truncateBody(commentBody + body)
|
||||||
|
core.debug(`Comment body: ${commentBody}`)
|
||||||
|
await octokit.rest.issues.updateComment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
comment_id: commentId,
|
||||||
|
body: commentBody
|
||||||
|
})
|
||||||
|
core.info(`Updated comment id '${commentId}'.`)
|
||||||
|
}
|
||||||
|
return commentId
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAuthenticatedUser(octokit): Promise<string> {
|
||||||
|
try {
|
||||||
|
const {data: user} = await octokit.rest.users.getAuthenticated()
|
||||||
|
return user.login
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
utils
|
||||||
|
.getErrorMessage(error)
|
||||||
|
.includes('Resource not accessible by integration')
|
||||||
|
) {
|
||||||
|
// In this case we can assume the token is the default GITHUB_TOKEN and
|
||||||
|
// therefore the user is 'github-actions[bot]'.
|
||||||
|
return 'github-actions[bot]'
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Reaction = {
|
||||||
|
id: number
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCommentReactionsForUser(
|
||||||
|
octokit,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
commentId: number,
|
||||||
|
user: string
|
||||||
|
): Promise<Reaction[]> {
|
||||||
|
const userReactions: Reaction[] = []
|
||||||
|
for await (const {data: reactions} of octokit.paginate.iterator(
|
||||||
|
octokit.rest.reactions.listForIssueComment,
|
||||||
|
{
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
comment_id: commentId,
|
||||||
|
per_page: 100
|
||||||
|
}
|
||||||
|
)) {
|
||||||
|
const filteredReactions: Reaction[] = reactions
|
||||||
|
.filter(reaction => reaction.user.login === user)
|
||||||
|
.map(reaction => {
|
||||||
|
return {id: reaction.id, content: reaction.content}
|
||||||
|
})
|
||||||
|
userReactions.push(...filteredReactions)
|
||||||
|
}
|
||||||
|
return userReactions
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createOrUpdateComment(
|
||||||
|
inputs: Inputs,
|
||||||
|
body: string
|
||||||
|
): Promise<void> {
|
||||||
|
const [owner, repo] = inputs.repository.split('/')
|
||||||
|
|
||||||
|
const octokit = github.getOctokit(inputs.token)
|
||||||
|
|
||||||
|
const commentId = inputs.commentId
|
||||||
|
? await updateComment(
|
||||||
|
octokit,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
inputs.commentId,
|
||||||
|
body,
|
||||||
|
inputs.editMode,
|
||||||
|
inputs.appendSeparator
|
||||||
|
)
|
||||||
|
: await createComment(octokit, owner, repo, inputs.issueNumber, body)
|
||||||
|
|
||||||
|
core.setOutput('comment-id', commentId)
|
||||||
|
|
||||||
|
if (inputs.reactions) {
|
||||||
|
const reactionsSet = getReactionsSet(inputs.reactions)
|
||||||
|
|
||||||
|
// Remove reactions if reactionsEditMode is 'replace'
|
||||||
|
if (inputs.commentId && inputs.reactionsEditMode === 'replace') {
|
||||||
|
const authenticatedUser = await getAuthenticatedUser(octokit)
|
||||||
|
const userReactions = await getCommentReactionsForUser(
|
||||||
|
octokit,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
commentId,
|
||||||
|
authenticatedUser
|
||||||
|
)
|
||||||
|
core.debug(inspect(userReactions))
|
||||||
|
|
||||||
|
const reactionsToRemove = userReactions.filter(
|
||||||
|
reaction => !reactionsSet.includes(reaction.content)
|
||||||
|
)
|
||||||
|
await removeReactions(octokit, owner, repo, commentId, reactionsToRemove)
|
||||||
|
}
|
||||||
|
|
||||||
|
await addReactions(octokit, owner, repo, commentId, reactionsSet)
|
||||||
|
}
|
||||||
|
}
|
82
src/main.ts
Normal file
82
src/main.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
import {Inputs, createOrUpdateComment} from './create-or-update-comment'
|
||||||
|
import {existsSync, readFileSync} from 'fs'
|
||||||
|
import {inspect} from 'util'
|
||||||
|
import * as utils from './utils'
|
||||||
|
|
||||||
|
function getBody(inputs: Inputs) {
|
||||||
|
if (inputs.body) {
|
||||||
|
return inputs.body
|
||||||
|
} else if (inputs.bodyPath) {
|
||||||
|
return readFileSync(inputs.bodyPath, 'utf-8')
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const inputs: Inputs = {
|
||||||
|
token: core.getInput('token'),
|
||||||
|
repository: core.getInput('repository'),
|
||||||
|
issueNumber: Number(core.getInput('issue-number')),
|
||||||
|
commentId: Number(core.getInput('comment-id')),
|
||||||
|
body: core.getInput('body'),
|
||||||
|
bodyPath: core.getInput('body-path') || core.getInput('body-file'),
|
||||||
|
editMode: core.getInput('edit-mode'),
|
||||||
|
appendSeparator: core.getInput('append-separator'),
|
||||||
|
reactions: utils.getInputAsArray('reactions'),
|
||||||
|
reactionsEditMode: core.getInput('reactions-edit-mode')
|
||||||
|
}
|
||||||
|
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||||
|
|
||||||
|
if (!['append', 'replace'].includes(inputs.editMode)) {
|
||||||
|
throw new Error(`Invalid edit-mode '${inputs.editMode}'.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!['append', 'replace'].includes(inputs.reactionsEditMode)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid reactions edit-mode '${inputs.reactionsEditMode}'.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!['newline', 'space', 'none'].includes(inputs.appendSeparator)) {
|
||||||
|
throw new Error(`Invalid append-separator '${inputs.appendSeparator}'.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.bodyPath && inputs.body) {
|
||||||
|
throw new Error("Only one of 'body' or 'body-path' can be set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.bodyPath) {
|
||||||
|
if (!existsSync(inputs.bodyPath)) {
|
||||||
|
throw new Error(`File '${inputs.bodyPath}' does not exist.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = getBody(inputs)
|
||||||
|
|
||||||
|
if (inputs.commentId) {
|
||||||
|
if (!body && !inputs.reactions) {
|
||||||
|
throw new Error("Missing comment 'body', 'body-path', or 'reactions'.")
|
||||||
|
}
|
||||||
|
} else if (inputs.issueNumber) {
|
||||||
|
if (!body) {
|
||||||
|
throw new Error("Missing comment 'body' or 'body-path'.")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Missing either 'issue-number' or 'comment-id'.")
|
||||||
|
}
|
||||||
|
|
||||||
|
createOrUpdateComment(inputs, body)
|
||||||
|
} catch (error) {
|
||||||
|
core.debug(inspect(error))
|
||||||
|
const errMsg = utils.getErrorMessage(error)
|
||||||
|
core.setFailed(errMsg)
|
||||||
|
if (errMsg == 'Resource not accessible by integration') {
|
||||||
|
core.error(`See this action's readme for details about this error`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
20
src/utils.ts
Normal file
20
src/utils.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
|
export function getInputAsArray(
|
||||||
|
name: string,
|
||||||
|
options?: core.InputOptions
|
||||||
|
): string[] {
|
||||||
|
return getStringAsArray(core.getInput(name, options))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStringAsArray(str: string): string[] {
|
||||||
|
return str
|
||||||
|
.split(/[\n,]+/)
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(x => x !== '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getErrorMessage(error: unknown) {
|
||||||
|
if (error instanceof Error) return error.message
|
||||||
|
return String(error)
|
||||||
|
}
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es6",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
|
"outDir": "./lib",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"declaration": true,
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"esModuleInterop": true
|
||||||
|
},
|
||||||
|
"exclude": ["__test__", "lib", "node_modules"]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user