mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-26 15:38:50 +00:00
✨ minimize comment (#472)
* ✨ minimize comment * ✨ hide, hide_and_recreate, hide_classify option * ✅ update config test
This commit is contained in:
parent
3c38ed8cd4
commit
39c5b5dc77
12 changed files with 272 additions and 16 deletions
37
dist/index.js
generated
vendored
37
dist/index.js
generated
vendored
|
|
@ -35,7 +35,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||
exports.getBodyOf = exports.minimizeComment = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||
const core = __importStar(__nccwpck_require__(186));
|
||||
function headerComment(header) {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||
|
|
@ -137,6 +137,18 @@ function deleteComment(octokit, id) {
|
|||
});
|
||||
}
|
||||
exports.deleteComment = deleteComment;
|
||||
function minimizeComment(octokit, subjectId, classifier) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield octokit.graphql(`
|
||||
mutation($input: MinimizeCommentInput!) {
|
||||
minimizeComment(input: $input) {
|
||||
clientMutationId
|
||||
}
|
||||
}
|
||||
`, { input: { subjectId, classifier } });
|
||||
});
|
||||
}
|
||||
exports.minimizeComment = minimizeComment;
|
||||
function getBodyOf(previous, append, hideDetails) {
|
||||
var _a;
|
||||
if (!append) {
|
||||
|
|
@ -178,7 +190,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
var _a, _b;
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.body = exports.githubToken = exports.deleteOldComment = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||
exports.body = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||
const core = __importStar(__nccwpck_require__(186));
|
||||
const github_1 = __nccwpck_require__(438);
|
||||
const fs_1 = __nccwpck_require__(747);
|
||||
|
|
@ -191,7 +203,14 @@ exports.hideDetails = core.getBooleanInput("hide_details", {
|
|||
required: true
|
||||
});
|
||||
exports.recreate = core.getBooleanInput("recreate", { required: true });
|
||||
exports.hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
|
||||
required: true
|
||||
});
|
||||
exports.hideClassify = core.getInput("hide_classify", {
|
||||
required: true
|
||||
});
|
||||
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
||||
exports.hideOldComment = core.getBooleanInput("hide", { required: true });
|
||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
exports.body = buildBody();
|
||||
function buildRepo() {
|
||||
|
|
@ -266,12 +285,15 @@ function run() {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
if (!config_1.deleteOldComment && !config_1.body) {
|
||||
if (!config_1.deleteOldComment && !config_1.hideOldComment && !config_1.body) {
|
||||
throw new Error("Either message or path input is required");
|
||||
}
|
||||
if (config_1.deleteOldComment && config_1.recreate) {
|
||||
throw new Error("delete and recreate cannot be both set to true");
|
||||
}
|
||||
if (config_1.hideOldComment && config_1.hideAndRecreate) {
|
||||
throw new Error("hide and hide_and_recreate cannot be both set to true");
|
||||
}
|
||||
const octokit = github.getOctokit(config_1.githubToken);
|
||||
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
if (!previous) {
|
||||
|
|
@ -282,12 +304,21 @@ function run() {
|
|||
yield (0, comment_1.deleteComment)(octokit, previous.id);
|
||||
return;
|
||||
}
|
||||
if (config_1.hideOldComment) {
|
||||
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
|
||||
return;
|
||||
}
|
||||
const previousBody = (0, comment_1.getBodyOf)(previous, config_1.append, config_1.hideDetails);
|
||||
if (config_1.recreate) {
|
||||
yield (0, comment_1.deleteComment)(octokit, previous.id);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||
return;
|
||||
}
|
||||
if (config_1.hideAndRecreate) {
|
||||
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
|
||||
return;
|
||||
}
|
||||
yield (0, comment_1.updateComment)(octokit, previous.id, config_1.body, config_1.header, previousBody);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue