diff --git a/dist/index.js b/dist/index.js index fb6b823..3dfb657 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8573,6 +8573,7 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { const { inspect } = __nccwpck_require__(3837); +const { readFileSync } = __nccwpck_require__(7147); const core = __nccwpck_require__(2186); const github = __nccwpck_require__(5438); @@ -8645,6 +8646,7 @@ async function run() { issueNumber: core.getInput("issue-number"), commentId: core.getInput("comment-id"), body: core.getInput("body"), + file: core.getInput("file"), editMode: core.getInput("edit-mode"), reactions: core.getInput("reactions") ? core.getInput("reactions") @@ -8667,14 +8669,19 @@ async function run() { const octokit = github.getOctokit(inputs.token); + let bodyToUse = inputs.body; + if (inputs.file) { + bodyToUse = readFileSync(inputs.file, "utf8"); + } + if (inputs.commentId) { // Edit a comment - if (!inputs.body && !inputs.reactions) { - core.setFailed("Missing either comment 'body' or 'reactions'."); + if (!inputs.body && !inputs.reactions && !inputs.file) { + core.setFailed("Missing either comment 'body', 'file', or 'reactions'."); return; } - if (inputs.body) { + if (bodyToUse) { var commentBody = ""; if (editMode == "append") { // Get the comment body @@ -8686,7 +8693,7 @@ async function run() { commentBody = comment.body + "\n"; } - commentBody = commentBody + inputs.body; + commentBody = commentBody + bodyToUse; core.debug(`Comment body: ${commentBody}`); await octokit.rest.issues.updateComment({ owner: repo[0], @@ -8704,15 +8711,15 @@ async function run() { } } else if (inputs.issueNumber) { // Create a comment - if (!inputs.body) { - core.setFailed("Missing comment 'body'."); + if (!inputs.body && !inputs.file) { + core.setFailed("Missing comment 'body' or 'file'."); return; } const { data: comment } = await octokit.rest.issues.createComment({ owner: repo[0], repo: repo[1], issue_number: inputs.issueNumber, - body: inputs.body, + body: bodyToUse, }); core.info( `Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.` diff --git a/index.js b/index.js index ce6c3a8..0f17f97 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const { inspect } = require("util"); +const { readFileSync } = require("fs"); const core = require("@actions/core"); const github = require("@actions/github"); @@ -71,6 +72,7 @@ async function run() { issueNumber: core.getInput("issue-number"), commentId: core.getInput("comment-id"), body: core.getInput("body"), + file: core.getInput("file"), editMode: core.getInput("edit-mode"), reactions: core.getInput("reactions") ? core.getInput("reactions") @@ -93,14 +95,19 @@ async function run() { const octokit = github.getOctokit(inputs.token); + let bodyToUse = inputs.body; + if (inputs.file) { + bodyToUse = readFileSync(inputs.file, "utf8"); + } + if (inputs.commentId) { // Edit a comment - if (!inputs.body && !inputs.reactions) { - core.setFailed("Missing either comment 'body' or 'reactions'."); + if (!inputs.body && !inputs.reactions && !inputs.file) { + core.setFailed("Missing either comment 'body', 'file', or 'reactions'."); return; } - if (inputs.body) { + if (bodyToUse) { var commentBody = ""; if (editMode == "append") { // Get the comment body @@ -112,7 +119,7 @@ async function run() { commentBody = comment.body + "\n"; } - commentBody = commentBody + inputs.body; + commentBody = commentBody + bodyToUse; core.debug(`Comment body: ${commentBody}`); await octokit.rest.issues.updateComment({ owner: repo[0], @@ -130,15 +137,15 @@ async function run() { } } else if (inputs.issueNumber) { // Create a comment - if (!inputs.body) { - core.setFailed("Missing comment 'body'."); + if (!inputs.body && !inputs.file) { + core.setFailed("Missing comment 'body' or 'file'."); return; } const { data: comment } = await octokit.rest.issues.createComment({ owner: repo[0], repo: repo[1], issue_number: inputs.issueNumber, - body: inputs.body, + body: bodyToUse, }); core.info( `Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`