minimize comment (#472)

*  minimize comment

*  hide, hide_and_recreate, hide_classify option

*  update config test
This commit is contained in:
marocchino 2021-10-21 02:20:24 +09:00 committed by GitHub
parent 3c38ed8cd4
commit 39c5b5dc77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 272 additions and 16 deletions

14
lib/comment.js generated
View file

@ -28,7 +28,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(require("@actions/core"));
function headerComment(header) {
return `<!-- Sticky Pull Request Comment${header} -->`;
@ -130,6 +130,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) {

9
lib/config.js generated
View file

@ -20,7 +20,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(require("@actions/core"));
const github_1 = require("@actions/github");
const fs_1 = require("fs");
@ -33,7 +33,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() {

14
lib/main.js generated
View file

@ -39,12 +39,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) {
@ -55,12 +58,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) {