diff --git a/.github/workflows/create-comment.yml b/.github/workflows/create-comment.yml index 35438f0..1b3bc41 100644 --- a/.github/workflows/create-comment.yml +++ b/.github/workflows/create-comment.yml @@ -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 }}" diff --git a/README.md b/README.md index b39122c..48a6b3e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index 4e5b0f1..de89442 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index eb21f70..f724fb7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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'."); diff --git a/index.js b/index.js index e67274b..7876357 100644 --- a/index.js +++ b/index.js @@ -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'.");