Skip to content

Commit

Permalink
Read body from file
Browse files Browse the repository at this point in the history
  • Loading branch information
Umang Galaiya committed Jun 1, 2022
1 parent 26f0786 commit 9d950b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
21 changes: 14 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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],
Expand All @@ -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}'.`
Expand Down
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { inspect } = require("util");
const { readFileSync } = require("fs");
const core = require("@actions/core");
const github = require("@actions/github");

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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],
Expand All @@ -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}'.`
Expand Down

0 comments on commit 9d950b6

Please sign in to comment.