Skip to content

Commit

Permalink
Add comment-id output
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Evans committed Apr 9, 2020
1 parent f15dbd9 commit bfe8b63
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/create-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:

- name: Create comment
uses: ./
id: couc
with:
issue-number: 1
body: |
Expand All @@ -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 }}"
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ function wrappy (fn, cb) {
/***/ }),

/***/ 18:
/***/ (function() {
/***/ (function(module) {

eval("require")("encoding");
module.exports = eval("require")("encoding");


/***/ }),
Expand Down Expand Up @@ -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
Expand All @@ -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'.");
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'.");
Expand Down

0 comments on commit bfe8b63

Please sign in to comment.