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

View file

@ -6,7 +6,10 @@ import {
deleteOldComment,
githubToken,
header,
hideAndRecreate,
hideClassify,
hideDetails,
hideOldComment,
pullRequestNumber,
recreate,
repo
@ -16,6 +19,7 @@ import {
deleteComment,
findPreviousComment,
getBodyOf,
minimizeComment,
updateComment
} from "./comment"
@ -26,7 +30,7 @@ async function run(): Promise<undefined> {
}
try {
if (!deleteOldComment && !body) {
if (!deleteOldComment && !hideOldComment && !body) {
throw new Error("Either message or path input is required")
}
@ -34,6 +38,10 @@ async function run(): Promise<undefined> {
throw new Error("delete and recreate cannot be both set to true")
}
if (hideOldComment && hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true")
}
const octokit = github.getOctokit(githubToken)
const previous = await findPreviousComment(
octokit,
@ -51,6 +59,10 @@ async function run(): Promise<undefined> {
await deleteComment(octokit, previous.id)
return
}
if (hideOldComment) {
await minimizeComment(octokit, previous.id, hideClassify)
return
}
const previousBody = getBodyOf(previous, append, hideDetails)
if (recreate) {
@ -66,6 +78,12 @@ async function run(): Promise<undefined> {
return
}
if (hideAndRecreate) {
await minimizeComment(octokit, previous.id, hideClassify)
await createComment(octokit, repo, pullRequestNumber, body, header)
return
}
await updateComment(octokit, previous.id, body, header, previousBody)
} catch (error) {
if (error instanceof Error) {