mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-13 12:11:14 +00:00
68 lines
3.1 KiB
JavaScript
68 lines
3.1 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
result["default"] = mod;
|
|
return result;
|
|
};
|
|
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* () {
|
|
const number = ((_b = (_a = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.number) ||
|
|
+core.getInput("number", { required: false });
|
|
if (isNaN(number) || number < 1) {
|
|
core.info("no numbers given: skip step");
|
|
return;
|
|
}
|
|
try {
|
|
const repo = github_1.context.repo;
|
|
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);
|
|
}
|
|
else {
|
|
yield comment_1.updateComment(octokit, repo, previous.id, body, header);
|
|
}
|
|
}
|
|
else {
|
|
yield comment_1.createComment(octokit, repo, number, body, header);
|
|
}
|
|
}
|
|
catch ({ message }) {
|
|
core.setFailed(message);
|
|
}
|
|
});
|
|
}
|
|
run();
|