Skip to content

Commit

Permalink
SCAN-5585 : Adding error for checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
steviemul committed Jul 30, 2024
1 parent d0f7682 commit 4b016f3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
38 changes: 25 additions & 13 deletions src/checks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const github = require("@actions/github");
const core = require("@actions/core");
const buildReport = require("./report");
const { title, token } = require("./config");

Expand All @@ -12,20 +13,26 @@ async function startCheck() {
const pullRequest = github.context.payload.pull_request;
const sha = (pullRequest && pullRequest.head.sha) || github.context.sha;

const response = await octokit.rest.checks.create({
owner,
repo,
name: title,
head_sha: sha,
status: "in_progress",
output: {
title,
summary: "",
text: "",
},
});
try {

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 @@ -39,6 +46,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
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const github = require("@actions/github");
const DEFAULT_BRANCH_NAME = github.context.payload?.repository?.default_branch;

const thisBranchName = () => {
core.info('Checking branch name');
core.info(JSON.stringify(github.context.payload, null, 2));

const refParts = github.context.payload.ref.split('/');

return refParts[refParts.length-1];
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ async function runScan() {
async function runScanWithChecks() {
let scanDetails;

try {
await startCheck();
await startCheck();

try {
scanDetails = await runScan();

core.debug(JSON.stringify(scanDetails, null, 2));
Expand Down

0 comments on commit 4b016f3

Please sign in to comment.