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

@ -1,5 +1,10 @@
import * as core from "@actions/core"
import {IssueComment, Repository, User} from "@octokit/graphql-schema"
import {
IssueComment,
ReportedContentClassifiers,
Repository,
User
} from "@octokit/graphql-schema"
import {GitHub} from "@actions/github/lib/utils"
function headerComment(header: String): string {
@ -14,7 +19,7 @@ export async function findPreviousComment(
},
number: number,
header: string
): Promise<{body: string; id: string} | undefined> {
): Promise<IssueComment | undefined> {
let after = null
let hasNextPage = true
const h = headerComment(header)
@ -133,6 +138,22 @@ export async function deleteComment(
{id}
)
}
export async function minimizeComment(
octokit: InstanceType<typeof GitHub>,
subjectId: string,
classifier: ReportedContentClassifiers
): Promise<void> {
await octokit.graphql(
`
mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) {
clientMutationId
}
}
`,
{input: {subjectId, classifier}}
)
}
export function getBodyOf(
previous: {body?: string},

View file

@ -1,4 +1,5 @@
import * as core from "@actions/core"
import {ReportedContentClassifiers} from "@octokit/graphql-schema"
import {context} from "@actions/github"
import {readFileSync} from "fs"
@ -13,7 +14,14 @@ export const hideDetails = core.getBooleanInput("hide_details", {
required: true
})
export const recreate = core.getBooleanInput("recreate", {required: true})
export const hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
required: true
})
export const hideClassify = core.getInput("hide_classify", {
required: true
}) as ReportedContentClassifiers
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
export const hideOldComment = core.getBooleanInput("hide", {required: true})
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
export const body = buildBody()

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) {