Add output of previous and created comment ids

This commit is contained in:
Alex Burgel 2023-05-04 22:50:41 -04:00
parent 17db3d5bd2
commit dadbe89de1
2 changed files with 31 additions and 8 deletions

View file

@ -7,6 +7,10 @@ import {
} from "@octokit/graphql-schema" } from "@octokit/graphql-schema"
import {GitHub} from "@actions/github/lib/utils" 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} -->` return `<!-- Sticky Pull Request Comment${header} -->`
} }
@ -111,11 +115,13 @@ export async function createComment(
body: string, body: string,
header: string, header: string,
previousBody?: string previousBody?: string
): Promise<void> { ): Promise<CreateCommentResponse | undefined> {
if (!body && !previousBody) if (!body && !previousBody) {
return core.warning("Comment body cannot be blank") core.warning("Comment body cannot be blank")
return
}
let x = await octokit.rest.issues.createComment({ return await octokit.rest.issues.createComment({
...repo, ...repo,
issue_number, issue_number,
body: previousBody body: previousBody
@ -145,7 +151,7 @@ export async function minimizeComment(
): Promise<void> { ): Promise<void> {
await octokit.graphql( await octokit.graphql(
` `
mutation($input: MinimizeCommentInput!) { mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) { minimizeComment(input: $input) {
clientMutationId clientMutationId
} }

View file

@ -64,6 +64,8 @@ async function run(): Promise<undefined> {
header header
) )
core.setOutput("previous_comment_id", previous?.id)
if (deleteOldComment) { if (deleteOldComment) {
if (previous) { if (previous) {
await deleteComment(octokit, previous.id) await deleteComment(octokit, previous.id)
@ -75,7 +77,14 @@ async function run(): Promise<undefined> {
if (onlyUpdateComment) { if (onlyUpdateComment) {
return 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 return
} }
@ -93,7 +102,7 @@ async function run(): Promise<undefined> {
const previousBody = getBodyOf(previous, append, hideDetails) const previousBody = getBodyOf(previous, append, hideDetails)
if (recreate) { if (recreate) {
await deleteComment(octokit, previous.id) await deleteComment(octokit, previous.id)
await createComment( const created = await createComment(
octokit, octokit,
repo, repo,
pullRequestNumber, pullRequestNumber,
@ -101,12 +110,20 @@ async function run(): Promise<undefined> {
header, header,
previousBody previousBody
) )
core.setOutput("created_comment_id", created?.data.id)
return return
} }
if (hideAndRecreate) { if (hideAndRecreate) {
await minimizeComment(octokit, previous.id, hideClassify) 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 return
} }