Skip to content

Commit

Permalink
Adding error for checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
steviemul committed May 15, 2024
1 parent e1c17ca commit e23f620
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
39 changes: 24 additions & 15 deletions src/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e23f620

Please sign in to comment.