mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-13 09:50:04 +00:00
Migrate to biome
This commit is contained in:
parent
e24be28b0d
commit
cce8920b20
15 changed files with 433 additions and 2243 deletions
|
|
@ -1,17 +1,17 @@
|
|||
import * as core from "@actions/core"
|
||||
import {
|
||||
import type {GitHub} from "@actions/github/lib/utils"
|
||||
import type {
|
||||
IssueComment,
|
||||
ReportedContentClassifiers,
|
||||
Repository,
|
||||
User
|
||||
} from "@octokit/graphql-schema/schema.d"
|
||||
import {GitHub} from "@actions/github/lib/utils"
|
||||
|
||||
type CreateCommentResponse = Awaited<
|
||||
ReturnType<InstanceType<typeof GitHub>["rest"]["issues"]["createComment"]>
|
||||
>
|
||||
|
||||
function headerComment(header: String): string {
|
||||
function headerComment(header: string): string {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`
|
||||
}
|
||||
|
||||
|
|
@ -76,8 +76,7 @@ export async function findPreviousComment(
|
|||
return target
|
||||
}
|
||||
after = repository.pullRequest?.comments?.pageInfo?.endCursor
|
||||
hasNextPage =
|
||||
repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
|
||||
hasNextPage = repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
|
@ -89,12 +88,9 @@ export async function updateComment(
|
|||
header: string,
|
||||
previousBody?: string
|
||||
): Promise<void> {
|
||||
if (!body && !previousBody)
|
||||
return core.warning("Comment body cannot be blank")
|
||||
if (!body && !previousBody) return core.warning("Comment body cannot be blank")
|
||||
|
||||
const rawPreviousBody: String = previousBody
|
||||
? bodyWithoutHeader(previousBody, header)
|
||||
: ""
|
||||
const rawPreviousBody: string = previousBody ? bodyWithoutHeader(previousBody, header) : ""
|
||||
|
||||
await octokit.graphql(
|
||||
`
|
||||
|
|
@ -136,9 +132,7 @@ export async function createComment(
|
|||
return await octokit.rest.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: bodyWithHeader(body, header)
|
||||
body: previousBody ? `${previousBody}\n${body}` : bodyWithHeader(body, header)
|
||||
})
|
||||
}
|
||||
export async function deleteComment(
|
||||
|
|
@ -189,11 +183,7 @@ export function getBodyOf(
|
|||
return previous.body.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2")
|
||||
}
|
||||
|
||||
export function commentsEqual(
|
||||
body: string,
|
||||
previous: string | undefined,
|
||||
header: string
|
||||
): boolean {
|
||||
export function commentsEqual(body: string, previous: string | undefined, header: string): boolean {
|
||||
const newBody = bodyWithHeader(body, header)
|
||||
return newBody === previous
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import {readFileSync} from "node:fs"
|
||||
import * as core from "@actions/core"
|
||||
import {ReportedContentClassifiers} from "@octokit/graphql-schema/schema.d"
|
||||
import {context} from "@actions/github"
|
||||
import {readFileSync} from "fs"
|
||||
import {create} from "@actions/glob"
|
||||
import type {ReportedContentClassifiers} from "@octokit/graphql-schema/schema.d"
|
||||
|
||||
export const pullRequestNumber =
|
||||
context?.payload?.pull_request?.number ||
|
||||
+core.getInput("number", {required: false})
|
||||
context?.payload?.pull_request?.number || +core.getInput("number", {required: false})
|
||||
|
||||
export const repo = buildRepo()
|
||||
export const header = core.getInput("header", {required: false})
|
||||
|
|
@ -55,9 +54,7 @@ export async function getBody(): Promise<string> {
|
|||
followSymbolicLinks,
|
||||
matchDirectories: false
|
||||
})
|
||||
return (await globber.glob())
|
||||
.map(path => readFileSync(path, "utf-8"))
|
||||
.join("\n")
|
||||
return (await globber.glob()).map(path => readFileSync(path, "utf-8")).join("\n")
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
|
|
|
|||
59
src/main.ts
59
src/main.ts
|
|
@ -1,35 +1,35 @@
|
|||
import * as core from "@actions/core"
|
||||
import * as github from "@actions/github"
|
||||
import {
|
||||
commentsEqual,
|
||||
createComment,
|
||||
deleteComment,
|
||||
findPreviousComment,
|
||||
getBodyOf,
|
||||
minimizeComment,
|
||||
updateComment
|
||||
} from "./comment"
|
||||
import {
|
||||
append,
|
||||
getBody,
|
||||
deleteOldComment,
|
||||
getBody,
|
||||
githubToken,
|
||||
header,
|
||||
hideAndRecreate,
|
||||
hideClassify,
|
||||
hideDetails,
|
||||
hideOldComment,
|
||||
ignoreEmpty,
|
||||
onlyCreateComment,
|
||||
onlyUpdateComment,
|
||||
pullRequestNumber,
|
||||
recreate,
|
||||
repo,
|
||||
ignoreEmpty,
|
||||
skipUnchanged,
|
||||
onlyCreateComment,
|
||||
onlyUpdateComment
|
||||
skipUnchanged
|
||||
} from "./config"
|
||||
import {
|
||||
createComment,
|
||||
deleteComment,
|
||||
findPreviousComment,
|
||||
getBodyOf,
|
||||
minimizeComment,
|
||||
updateComment,
|
||||
commentsEqual
|
||||
} from "./comment"
|
||||
|
||||
async function run(): Promise<undefined> {
|
||||
if (isNaN(pullRequestNumber) || pullRequestNumber < 1) {
|
||||
if (Number.isNaN(pullRequestNumber) || pullRequestNumber < 1) {
|
||||
core.info("no pull request numbers given: skip step")
|
||||
return
|
||||
}
|
||||
|
|
@ -59,12 +59,7 @@ async function run(): Promise<undefined> {
|
|||
}
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
header
|
||||
)
|
||||
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
||||
|
||||
core.setOutput("previous_comment_id", previous?.id)
|
||||
|
||||
|
|
@ -79,13 +74,7 @@ async function run(): Promise<undefined> {
|
|||
if (onlyUpdateComment) {
|
||||
return
|
||||
}
|
||||
const created = await createComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
body,
|
||||
header
|
||||
)
|
||||
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
}
|
||||
|
|
@ -106,11 +95,7 @@ async function run(): Promise<undefined> {
|
|||
return
|
||||
}
|
||||
|
||||
const previousBody = getBodyOf(
|
||||
{body: previous.body || ""},
|
||||
append,
|
||||
hideDetails
|
||||
)
|
||||
const previousBody = getBodyOf({body: previous.body || ""}, append, hideDetails)
|
||||
if (recreate) {
|
||||
await deleteComment(octokit, previous.id)
|
||||
const created = await createComment(
|
||||
|
|
@ -127,13 +112,7 @@ async function run(): Promise<undefined> {
|
|||
|
||||
if (hideAndRecreate) {
|
||||
await minimizeComment(octokit, previous.id, hideClassify)
|
||||
const created = await createComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
body,
|
||||
header
|
||||
)
|
||||
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue