Skip to content

Commit

Permalink
Showing 3 changed files with 25 additions and 18 deletions.
13 changes: 9 additions & 4 deletions lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map
28 changes: 15 additions & 13 deletions src/actions-util.ts
@@ -556,12 +556,22 @@ export async function createStatusReportBase(

interface HTTPError {
status: number;
message?: string;
}

function isHTTPError(arg: any): arg is HTTPError {
return arg?.status !== undefined && Number.isInteger(arg.status);
}

const GENERIC_403_MSG =
"The repo on which this action is running is not opted-in to CodeQL code scanning.";
const GENERIC_404_MSG =
"Not authorized to used the CodeQL code scanning feature on this repo.";
const OUT_OF_DATE_MSG =
"CodeQL Action is out-of-date. Please upgrade to the latest version of codeql-action.";
const INCOMPATIBLE_MSG =
"CodeQL Action version is incompatible with the code scanning endpoint. Please update to a compatible version of codeql-action.";

/**
* Send a status report to the code_scanning/analysis/status endpoint.
*
@@ -598,32 +608,24 @@ export async function sendStatusReport<S extends StatusReportBase>(

return true;
} catch (e) {
console.log(e);
if (isHTTPError(e)) {
switch (e.status) {
case 403:
core.setFailed(
"The repo on which this action is running is not opted-in to CodeQL code scanning."
);
core.setFailed(e.message || GENERIC_403_MSG);
return false;
case 404:
core.setFailed(
"Not authorized to used the CodeQL code scanning feature on this repo."
);
core.setFailed(GENERIC_404_MSG);
return false;
case 422:
// schema incompatibility when reporting status
// this means that this action version is no longer compatible with the API
// we still want to continue as it is likely the analysis endpoint will work
if (getRequiredEnvParam("GITHUB_SERVER_URL") !== GITHUB_DOTCOM_URL) {
core.debug(
"CodeQL Action version is incompatible with the code scanning endpoint. Please update to a compatible version of codeql-action."
);
core.debug(INCOMPATIBLE_MSG);
} else {
core.debug(
"CodeQL Action is out-of-date. Please upgrade to the latest version of codeql-action."
);
core.debug(OUT_OF_DATE_MSG);
}

return true;
}
}

0 comments on commit ffd96b3

Please sign in to comment.