mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-13 04:01:14 +00:00
Add output of previous and created comment ids
This commit is contained in:
parent
17db3d5bd2
commit
dadbe89de1
2 changed files with 31 additions and 8 deletions
|
|
@ -7,6 +7,10 @@ import {
|
|||
} from "@octokit/graphql-schema"
|
||||
import {GitHub} from "@actions/github/lib/utils"
|
||||
|
||||
type CreateCommentResponse = Awaited<
|
||||
ReturnType<InstanceType<typeof GitHub>["rest"]["issues"]["createComment"]>
|
||||
>
|
||||
|
||||
function headerComment(header: String): string {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`
|
||||
}
|
||||
|
|
@ -111,11 +115,13 @@ export async function createComment(
|
|||
body: string,
|
||||
header: string,
|
||||
previousBody?: string
|
||||
): Promise<void> {
|
||||
if (!body && !previousBody)
|
||||
return core.warning("Comment body cannot be blank")
|
||||
): Promise<CreateCommentResponse | undefined> {
|
||||
if (!body && !previousBody) {
|
||||
core.warning("Comment body cannot be blank")
|
||||
return
|
||||
}
|
||||
|
||||
let x = await octokit.rest.issues.createComment({
|
||||
return await octokit.rest.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: previousBody
|
||||
|
|
@ -145,7 +151,7 @@ export async function minimizeComment(
|
|||
): Promise<void> {
|
||||
await octokit.graphql(
|
||||
`
|
||||
mutation($input: MinimizeCommentInput!) {
|
||||
mutation($input: MinimizeCommentInput!) {
|
||||
minimizeComment(input: $input) {
|
||||
clientMutationId
|
||||
}
|
||||
|
|
|
|||
23
src/main.ts
23
src/main.ts
|
|
@ -64,6 +64,8 @@ async function run(): Promise<undefined> {
|
|||
header
|
||||
)
|
||||
|
||||
core.setOutput("previous_comment_id", previous?.id)
|
||||
|
||||
if (deleteOldComment) {
|
||||
if (previous) {
|
||||
await deleteComment(octokit, previous.id)
|
||||
|
|
@ -75,7 +77,14 @@ async function run(): Promise<undefined> {
|
|||
if (onlyUpdateComment) {
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +102,7 @@ async function run(): Promise<undefined> {
|
|||
const previousBody = getBodyOf(previous, append, hideDetails)
|
||||
if (recreate) {
|
||||
await deleteComment(octokit, previous.id)
|
||||
await createComment(
|
||||
const created = await createComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
|
|
@ -101,12 +110,20 @@ async function run(): Promise<undefined> {
|
|||
header,
|
||||
previousBody
|
||||
)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
}
|
||||
|
||||
if (hideAndRecreate) {
|
||||
await minimizeComment(octokit, previous.id, hideClassify)
|
||||
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…
Reference in a new issue