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();