Ensure error correct error message on 403 error

This commit is contained in:
Andrew Eisenberg
2021-03-16 19:55:55 -07:00
committed by Andrew Eisenberg
parent 0f834639e4
commit ffd96b38fb
3 changed files with 25 additions and 18 deletions

13
lib/actions-util.js generated
View File

@@ -434,6 +434,10 @@ function isHTTPError(arg) {
var _a;
return ((_a = arg) === null || _a === void 0 ? void 0 : _a.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.
*
@@ -462,23 +466,24 @@ async function sendStatusReport(statusReport) {
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") !== util_1.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;
}