Add option to read message from path

This commit is contained in:
Buck Doyle 2020-05-12 10:13:40 -05:00
parent b687a2750c
commit 834b325ec2
4 changed files with 42 additions and 3 deletions

View file

@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const github_1 = require("@actions/github");
const comment_1 = require("./comment");
const fs_1 = require("fs");
function run() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
@ -30,12 +31,23 @@ function run() {
}
try {
const repo = github_1.context.repo;
const body = core.getInput("message", { required: true });
const message = core.getInput("message", { required: false });
const path = core.getInput("path", { required: false });
const header = core.getInput("header", { required: false }) || "";
const append = core.getInput("append", { required: false }) || false;
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
const octokit = new github_1.GitHub(githubToken);
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
if (!message && !path) {
throw { message: 'Either message or path input is required' };
}
let body;
if (path) {
body = fs_1.readFileSync(path);
}
else {
body = message;
}
if (previous) {
if (append) {
yield comment_1.updateComment(octokit, repo, previous.id, body, header, previous.body);