From 6570451d38f0eca93ff1a8954b551a9cb33b0277 Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:11:41 -0400 Subject: [PATCH] don't print pr comment if there's no detectable issue number --- dist/index.js | 49 ++++++++++++++++++++++++++++--------------------- src/index.ts | 51 +++++++++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0302ca5..0c8f1cd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24322,13 +24322,15 @@ async function main() { if (branch === void 0) { throw new Error("Unable to determine branch name"); } - await createPRComment({ - status: "building", - previewUrl: "", - sha, - issueNumber, - runId - }); + if (issueNumber !== void 0) { + await createPRComment({ + status: "building", + previewUrl: "", + sha, + issueNumber, + runId + }); + } const project = await getPagesProject(); const productionEnvironment = branch === project.production_branch && !isPR && !isWorkflowRun; let githubDeployment; @@ -24360,13 +24362,15 @@ async function main() { if (!productionEnvironment && deployment.aliases && deployment.aliases.length > 0) { alias = deployment.aliases[0]; } - await createPRComment({ - status: "success", - previewUrl: `[Visit Preview](${alias})`, - sha, - issueNumber, - runId - }); + if (issueNumber !== void 0) { + await createPRComment({ + status: "success", + previewUrl: `[Visit Preview](${alias})`, + sha, + issueNumber, + runId + }); + } (0, import_core3.setOutput)("id", deployment.id); (0, import_core3.setOutput)("url", deployment.url); (0, import_core3.setOutput)("environment", deployment.environment); @@ -24378,13 +24382,16 @@ async function main() { await main(); } catch (error) { (0, import_core3.setFailed)(error.message); - await createPRComment({ - status: "fail", - previewUrl: "", - sha: pr?.head.sha ?? import_github5.context.sha, - issueNumber: pr?.number ?? import_github5.context.issue.number, - runId: import_github5.context.payload.workflow_run.id ?? import_github5.context.runId - }); + const issueNumber = pr?.number ?? import_github5.context.issue.number; + if (issueNumber !== void 0) { + await createPRComment({ + status: "fail", + previewUrl: "", + sha: pr?.head.sha ?? import_github5.context.sha, + issueNumber: pr?.number ?? import_github5.context.issue.number, + runId: import_github5.context.payload.workflow_run.id ?? import_github5.context.runId + }); + } } })(); /*! Bundled license information: diff --git a/src/index.ts b/src/index.ts index c8bd8c9..7ddbf32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,7 @@ async function main() { pullRequests.find((p) => p.title === workflowRun?.display_title) ?? (context.payload.pull_request as PullRequest); - const issueNumber = pr?.number ?? context.issue.number; + const issueNumber = pr?.number ?? (context.issue.number as number | undefined); const runId = workflowRun?.id ?? context.runId; const sha = workflowRun?.head_sha ?? pr?.head.sha ?? context.sha; @@ -57,13 +57,15 @@ async function main() { throw new Error('Unable to determine branch name'); } - await createPRComment({ - status: 'building', - previewUrl: '', - sha, - issueNumber, - runId, - }); + if (issueNumber !== undefined) { + await createPRComment({ + status: 'building', + previewUrl: '', + sha, + issueNumber, + runId, + }); + } const project = await getPagesProject(); @@ -105,13 +107,15 @@ async function main() { alias = deployment.aliases[0]!; // we can assert that idx 0 exists } - await createPRComment({ - status: 'success', - previewUrl: `[Visit Preview](${alias})`, - sha, - issueNumber, - runId, - }); + if (issueNumber !== undefined) { + await createPRComment({ + status: 'success', + previewUrl: `[Visit Preview](${alias})`, + sha, + issueNumber, + runId, + }); + } setOutput('id', deployment.id); setOutput('url', deployment.url); @@ -128,12 +132,15 @@ async function main() { // @ts-expect-error always print the message setFailed(error.message); - await createPRComment({ - status: 'fail', - previewUrl: '', - sha: pr?.head.sha ?? context.sha, - issueNumber: pr?.number ?? context.issue.number, - runId: context.payload.workflow_run.id ?? context.runId, - }); + const issueNumber = pr?.number ?? (context.issue.number as number | undefined); + if (issueNumber !== undefined) { + await createPRComment({ + status: 'fail', + previewUrl: '', + sha: pr?.head.sha ?? context.sha, + issueNumber: pr?.number ?? context.issue.number, + runId: context.payload.workflow_run.id ?? context.runId, + }); + } } })();