Read body from file

This commit is contained in:
Umang Galaiya 2022-06-01 20:33:14 +05:30
parent 26f0786864
commit 9d950b6220
2 changed files with 28 additions and 14 deletions

21
dist/index.js vendored
View File

@ -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. // 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 { inspect } = __nccwpck_require__(3837);
const { readFileSync } = __nccwpck_require__(7147);
const core = __nccwpck_require__(2186); const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438); const github = __nccwpck_require__(5438);
@ -8645,6 +8646,7 @@ async function run() {
issueNumber: core.getInput("issue-number"), issueNumber: core.getInput("issue-number"),
commentId: core.getInput("comment-id"), commentId: core.getInput("comment-id"),
body: core.getInput("body"), body: core.getInput("body"),
file: core.getInput("file"),
editMode: core.getInput("edit-mode"), editMode: core.getInput("edit-mode"),
reactions: core.getInput("reactions") reactions: core.getInput("reactions")
? core.getInput("reactions") ? core.getInput("reactions")
@ -8667,14 +8669,19 @@ async function run() {
const octokit = github.getOctokit(inputs.token); const octokit = github.getOctokit(inputs.token);
let bodyToUse = inputs.body;
if (inputs.file) {
bodyToUse = readFileSync(inputs.file, "utf8");
}
if (inputs.commentId) { if (inputs.commentId) {
// Edit a comment // Edit a comment
if (!inputs.body && !inputs.reactions) { if (!inputs.body && !inputs.reactions && !inputs.file) {
core.setFailed("Missing either comment 'body' or 'reactions'."); core.setFailed("Missing either comment 'body', 'file', or 'reactions'.");
return; return;
} }
if (inputs.body) { if (bodyToUse) {
var commentBody = ""; var commentBody = "";
if (editMode == "append") { if (editMode == "append") {
// Get the comment body // Get the comment body
@ -8686,7 +8693,7 @@ async function run() {
commentBody = comment.body + "\n"; commentBody = comment.body + "\n";
} }
commentBody = commentBody + inputs.body; commentBody = commentBody + bodyToUse;
core.debug(`Comment body: ${commentBody}`); core.debug(`Comment body: ${commentBody}`);
await octokit.rest.issues.updateComment({ await octokit.rest.issues.updateComment({
owner: repo[0], owner: repo[0],
@ -8704,15 +8711,15 @@ async function run() {
} }
} else if (inputs.issueNumber) { } else if (inputs.issueNumber) {
// Create a comment // Create a comment
if (!inputs.body) { if (!inputs.body && !inputs.file) {
core.setFailed("Missing comment 'body'."); core.setFailed("Missing comment 'body' or 'file'.");
return; return;
} }
const { data: comment } = await octokit.rest.issues.createComment({ const { data: comment } = await octokit.rest.issues.createComment({
owner: repo[0], owner: repo[0],
repo: repo[1], repo: repo[1],
issue_number: inputs.issueNumber, issue_number: inputs.issueNumber,
body: inputs.body, body: bodyToUse,
}); });
core.info( core.info(
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.` `Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`

View File

@ -1,4 +1,5 @@
const { inspect } = require("util"); const { inspect } = require("util");
const { readFileSync } = require("fs");
const core = require("@actions/core"); const core = require("@actions/core");
const github = require("@actions/github"); const github = require("@actions/github");
@ -71,6 +72,7 @@ async function run() {
issueNumber: core.getInput("issue-number"), issueNumber: core.getInput("issue-number"),
commentId: core.getInput("comment-id"), commentId: core.getInput("comment-id"),
body: core.getInput("body"), body: core.getInput("body"),
file: core.getInput("file"),
editMode: core.getInput("edit-mode"), editMode: core.getInput("edit-mode"),
reactions: core.getInput("reactions") reactions: core.getInput("reactions")
? core.getInput("reactions") ? core.getInput("reactions")
@ -93,14 +95,19 @@ async function run() {
const octokit = github.getOctokit(inputs.token); const octokit = github.getOctokit(inputs.token);
let bodyToUse = inputs.body;
if (inputs.file) {
bodyToUse = readFileSync(inputs.file, "utf8");
}
if (inputs.commentId) { if (inputs.commentId) {
// Edit a comment // Edit a comment
if (!inputs.body && !inputs.reactions) { if (!inputs.body && !inputs.reactions && !inputs.file) {
core.setFailed("Missing either comment 'body' or 'reactions'."); core.setFailed("Missing either comment 'body', 'file', or 'reactions'.");
return; return;
} }
if (inputs.body) { if (bodyToUse) {
var commentBody = ""; var commentBody = "";
if (editMode == "append") { if (editMode == "append") {
// Get the comment body // Get the comment body
@ -112,7 +119,7 @@ async function run() {
commentBody = comment.body + "\n"; commentBody = comment.body + "\n";
} }
commentBody = commentBody + inputs.body; commentBody = commentBody + bodyToUse;
core.debug(`Comment body: ${commentBody}`); core.debug(`Comment body: ${commentBody}`);
await octokit.rest.issues.updateComment({ await octokit.rest.issues.updateComment({
owner: repo[0], owner: repo[0],
@ -130,15 +137,15 @@ async function run() {
} }
} else if (inputs.issueNumber) { } else if (inputs.issueNumber) {
// Create a comment // Create a comment
if (!inputs.body) { if (!inputs.body && !inputs.file) {
core.setFailed("Missing comment 'body'."); core.setFailed("Missing comment 'body' or 'file'.");
return; return;
} }
const { data: comment } = await octokit.rest.issues.createComment({ const { data: comment } = await octokit.rest.issues.createComment({
owner: repo[0], owner: repo[0],
repo: repo[1], repo: repo[1],
issue_number: inputs.issueNumber, issue_number: inputs.issueNumber,
body: inputs.body, body: bodyToUse,
}); });
core.info( core.info(
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.` `Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`