From e23f620c583dc1f0b0676f64c3c6cc506e81c9e9 Mon Sep 17 00:00:00 2001 From: Stephen Mulrennan Date: Wed, 15 May 2024 12:34:19 +0100 Subject: [PATCH] Adding error for checks. --- src/checks.js | 39 ++++++++++++++++++++++++--------------- src/index.js | 9 +-------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/checks.js b/src/checks.js index 073bf50..7ddab1b 100644 --- a/src/checks.js +++ b/src/checks.js @@ -15,22 +15,26 @@ async function startCheck() { core.info("About to create check"); - const response = await octokit.rest.checks.create({ - owner, - repo, - name: title, - head_sha: sha, - status: "in_progress", - output: { - title, - summary: "", - text: "", - }, - }); + try { - core.info(response); - - CHECK_ID = response.data.id; + const response = await octokit.rest.checks.create({ + owner, + repo, + name: title, + head_sha: sha, + status: "in_progress", + output: { + title, + summary: "", + text: "", + }, + }); + + CHECK_ID = response.data.id; + } + catch (error) { + throw new Error("Error creating check. Ensure your workflow has the 'checks:write' permissions - https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs") + } } function getOutputModel(details) { @@ -44,6 +48,11 @@ async function finishCheck(details) { const { owner, repo } = github.context.repo; const { conclusion, report } = getOutputModel(details); + if (!CHECK_ID) { + core.warning("No active check to finish."); + return; + } + await octokit.rest.checks.update({ owner, repo, diff --git a/src/index.js b/src/index.js index 8dbcca9..a43ecb5 100644 --- a/src/index.js +++ b/src/index.js @@ -25,14 +25,7 @@ async function runScan() { async function runScanWithChecks() { let scanDetails; - try { - core.info("Calling start check"); - - await startCheck(); - } - catch (error) { - core.info(error); - } + await startCheck(); try { scanDetails = await runScan();