Add comment-id output

This commit is contained in:
Peter Evans 2020-04-09 16:03:30 +09:00
parent f15dbd94b6
commit bfe8b63d3c
5 changed files with 38 additions and 4 deletions

View File

@ -17,6 +17,7 @@ jobs:
- name: Create comment
uses: ./
id: couc
with:
issue-number: 1
body: |
@ -26,3 +27,7 @@ jobs:
[1]: https://github.com/peter-evans/create-or-update-comment
reaction-type: '+1'
- name: Check outputs
run: |
echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"

View File

@ -57,6 +57,24 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
| `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`) | |
#### 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@v1
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
How to find the id of a comment will depend a lot on the use case.

View File

@ -16,6 +16,9 @@ inputs:
description: 'The mode when updating a comment, "replace" or "append".'
reaction-type:
description: 'The reaction to add to the comment.'
outputs:
comment-id:
description: 'The id of the created comment'
runs:
using: 'node12'
main: 'dist/index.js'

10
dist/index.js vendored
View File

@ -302,9 +302,9 @@ function wrappy (fn, cb) {
/***/ }),
/***/ 18:
/***/ (function() {
/***/ (function(module) {
eval("require")("encoding");
module.exports = eval("require")("encoding");
/***/ }),
@ -580,11 +580,13 @@ async function run() {
body: commentBody
});
core.info(`Updated comment id '${inputs.commentId}'.`);
core.setOutput('comment-id', inputs.commentId);
}
// Set a comment reaction
if (inputs.reactionType) {
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${inputs.commentId}'.`);
}
} else if (inputs.issueNumber) {
// Create a comment
@ -598,11 +600,13 @@ async function run() {
issue_number: inputs.issueNumber,
body: inputs.body
});
core.info(`Created comment on issue '${inputs.issueNumber}'.`);
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
core.setOutput('comment-id', comment.id);
// Set a comment reaction
if (inputs.reactionType) {
await addReaction(octokit, repo, comment.id, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
}
} else {
core.setFailed("Missing either 'issue-number' or 'comment-id'.");

View File

@ -84,11 +84,13 @@ async function run() {
body: commentBody
});
core.info(`Updated comment id '${inputs.commentId}'.`);
core.setOutput('comment-id', inputs.commentId);
}
// Set a comment reaction
if (inputs.reactionType) {
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${inputs.commentId}'.`);
}
} else if (inputs.issueNumber) {
// Create a comment
@ -102,11 +104,13 @@ async function run() {
issue_number: inputs.issueNumber,
body: inputs.body
});
core.info(`Created comment on issue '${inputs.issueNumber}'.`);
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
core.setOutput('comment-id', comment.id);
// Set a comment reaction
if (inputs.reactionType) {
await addReaction(octokit, repo, comment.id, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
}
} else {
core.setFailed("Missing either 'issue-number' or 'comment-id'.");