mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-16 02:55:44 +00:00
dist with new generator
This commit is contained in:
parent
6b16c03623
commit
831680f812
8 changed files with 6804 additions and 68 deletions
10
lib/comment.js
generated
10
lib/comment.js
generated
|
|
@ -37,7 +37,7 @@ function findPreviousComment(octokit, repo, issue_number, header) {
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
||||
const h = headerComment(header);
|
||||
return comments.find(comment => comment.body.includes(h));
|
||||
return comments.find(comment => { var _a; return (_a = comment.body) === null || _a === void 0 ? void 0 : _a.includes(h); });
|
||||
});
|
||||
}
|
||||
exports.findPreviousComment = findPreviousComment;
|
||||
|
|
@ -45,7 +45,9 @@ function updateComment(octokit, repo, comment_id, body, header, previousBody) {
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!body && !previousBody)
|
||||
return core.warning('Comment body cannot be blank');
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
}
|
||||
exports.updateComment = updateComment;
|
||||
|
|
@ -53,7 +55,9 @@ function createComment(octokit, repo, issue_number, body, header, previousBody)
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!body && !previousBody)
|
||||
return core.warning('Comment body cannot be blank');
|
||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}` }));
|
||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
}
|
||||
exports.createComment = createComment;
|
||||
|
|
|
|||
29
lib/main.js
generated
29
lib/main.js
generated
|
|
@ -36,27 +36,28 @@ function run() {
|
|||
var _a, _b, _c;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const number = ((_c = (_b = (_a = github.context) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.pull_request) === null || _c === void 0 ? void 0 : _c.number) ||
|
||||
+core.getInput("number", { required: false });
|
||||
+core.getInput('number', { required: false });
|
||||
if (isNaN(number) || number < 1) {
|
||||
core.info("no numbers given: skip step");
|
||||
core.info('no pull request numbers given: skip step');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const repo = github.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") === "true";
|
||||
const recreate = (core.getInput("recreate", { required: false }) || "false") === "true";
|
||||
const deleteOldComment = (core.getInput("delete", { required: false }) || "false") === "true";
|
||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
repo.repo = core.getInput('repo', { required: false }) || repo.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') === 'true';
|
||||
const recreate = (core.getInput('recreate', { required: false }) || 'false') === 'true';
|
||||
const deleteOldComment = (core.getInput('delete', { required: false }) || 'false') === 'true';
|
||||
const githubToken = core.getInput('GITHUB_TOKEN', { required: true });
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
|
||||
if (!deleteOldComment && !message && !path) {
|
||||
throw { message: 'Either message or path input is required' };
|
||||
throw new Error('Either message or path input is required');
|
||||
}
|
||||
if (deleteOldComment && recreate) {
|
||||
throw { message: 'delete and recreate cannot be both set to true' };
|
||||
throw new Error('delete and recreate cannot be both set to true');
|
||||
}
|
||||
let body;
|
||||
if (path) {
|
||||
|
|
@ -66,7 +67,7 @@ function run() {
|
|||
body = message;
|
||||
}
|
||||
if (previous) {
|
||||
const previousBody = append && previous.body;
|
||||
const previousBody = append ? previous.body : undefined;
|
||||
if (deleteOldComment) {
|
||||
yield comment_1.deleteComment(octokit, repo, previous.id);
|
||||
}
|
||||
|
|
@ -82,8 +83,8 @@ function run() {
|
|||
yield comment_1.createComment(octokit, repo, number, body, header);
|
||||
}
|
||||
}
|
||||
catch ({ message }) {
|
||||
core.setFailed(message);
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue