Skip to content

Commit bfe8b63

Browse files
committed
Add comment-id output
1 parent f15dbd9 commit bfe8b63

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

.github/workflows/create-comment.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717

1818
- name: Create comment
1919
uses: ./
20+
id: couc
2021
with:
2122
issue-number: 1
2223
body: |
@@ -26,3 +27,7 @@ jobs:
2627
2728
[1]: https://github.com/peter-evans/create-or-update-comment
2829
reaction-type: '+1'
30+
31+
- name: Check outputs
32+
run: |
33+
echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
5757
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
5858
| `reaction-type` | The reaction to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
5959

60+
#### Outputs
61+
62+
The ID of the created comment will be output for use in later steps.
63+
Note that in order to read the step output the action step must have an id.
64+
65+
```yml
66+
- name: Create comment
67+
uses: peter-evans/create-or-update-comment@v1
68+
id: couc
69+
with:
70+
issue-number: 1
71+
body: |
72+
My comment
73+
- name: Check outputs
74+
run: |
75+
echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"
76+
```
77+
6078
### Where to find the id of a comment
6179

6280
How to find the id of a comment will depend a lot on the use case.

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inputs:
1616
description: 'The mode when updating a comment, "replace" or "append".'
1717
reaction-type:
1818
description: 'The reaction to add to the comment.'
19+
outputs:
20+
comment-id:
21+
description: 'The id of the created comment'
1922
runs:
2023
using: 'node12'
2124
main: 'dist/index.js'

dist/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ function wrappy (fn, cb) {
302302
/***/ }),
303303

304304
/***/ 18:
305-
/***/ (function() {
305+
/***/ (function(module) {
306306

307-
eval("require")("encoding");
307+
module.exports = eval("require")("encoding");
308308

309309

310310
/***/ }),
@@ -580,11 +580,13 @@ async function run() {
580580
body: commentBody
581581
});
582582
core.info(`Updated comment id '${inputs.commentId}'.`);
583+
core.setOutput('comment-id', inputs.commentId);
583584
}
584585

585586
// Set a comment reaction
586587
if (inputs.reactionType) {
587588
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
589+
core.info(`Added reaction '${inputs.reactionType}' to comment id '${inputs.commentId}'.`);
588590
}
589591
} else if (inputs.issueNumber) {
590592
// Create a comment
@@ -598,11 +600,13 @@ async function run() {
598600
issue_number: inputs.issueNumber,
599601
body: inputs.body
600602
});
601-
core.info(`Created comment on issue '${inputs.issueNumber}'.`);
603+
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
604+
core.setOutput('comment-id', comment.id);
602605

603606
// Set a comment reaction
604607
if (inputs.reactionType) {
605608
await addReaction(octokit, repo, comment.id, inputs.reactionType);
609+
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
606610
}
607611
} else {
608612
core.setFailed("Missing either 'issue-number' or 'comment-id'.");

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ async function run() {
8484
body: commentBody
8585
});
8686
core.info(`Updated comment id '${inputs.commentId}'.`);
87+
core.setOutput('comment-id', inputs.commentId);
8788
}
8889

8990
// Set a comment reaction
9091
if (inputs.reactionType) {
9192
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
93+
core.info(`Added reaction '${inputs.reactionType}' to comment id '${inputs.commentId}'.`);
9294
}
9395
} else if (inputs.issueNumber) {
9496
// Create a comment
@@ -102,11 +104,13 @@ async function run() {
102104
issue_number: inputs.issueNumber,
103105
body: inputs.body
104106
});
105-
core.info(`Created comment on issue '${inputs.issueNumber}'.`);
107+
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
108+
core.setOutput('comment-id', comment.id);
106109

107110
// Set a comment reaction
108111
if (inputs.reactionType) {
109112
await addReaction(octokit, repo, comment.id, inputs.reactionType);
113+
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
110114
}
111115
} else {
112116
core.setFailed("Missing either 'issue-number' or 'comment-id'.");

0 commit comments

Comments
 (0)