mirror of
https://github.com/github/codeql-action.git
synced 2026-05-07 22:30:44 +00:00
Handle errors during database upload
This commit is contained in:
Generated
+1
-5
@@ -448,10 +448,6 @@ async function createStatusReportBase(actionName, status, actionStartedAt, cause
|
||||
return statusReport;
|
||||
}
|
||||
exports.createStatusReportBase = createStatusReportBase;
|
||||
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.";
|
||||
@@ -481,7 +477,7 @@ async function sendStatusReport(statusReport) {
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
if (isHTTPError(e)) {
|
||||
if (util_1.isHTTPError(e)) {
|
||||
switch (e.status) {
|
||||
case 403:
|
||||
if (workflowIsTriggeredByPushEvent() && isDependabotActor()) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Generated
+26
-16
@@ -49,14 +49,23 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
|
||||
return;
|
||||
}
|
||||
const client = api_client_1.getApiClient(apiDetails);
|
||||
const optInResponse = await client.request("GET /repos/:owner/:repo/code-scanning/databases", {
|
||||
owner: repositoryNwo.owner,
|
||||
repo: repositoryNwo.repo,
|
||||
});
|
||||
if (optInResponse.status !== 204) {
|
||||
// Repository is not opted in to database uploads.
|
||||
logger.debug("Repository is not opted in to database uploads. Skipping upload.");
|
||||
return;
|
||||
try {
|
||||
await client.request("GET /repos/:owner/:repo/code-scanning/databases", {
|
||||
owner: repositoryNwo.owner,
|
||||
repo: repositoryNwo.repo,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
if (util.isHTTPError(e)) {
|
||||
if (e.status === 404) {
|
||||
logger.debug("Repository is not opted in to database uploads. Skipping upload.");
|
||||
}
|
||||
else {
|
||||
logger.debug(`Skipping database upload due to unknown error: ${e}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (const language of config.languages) {
|
||||
@@ -66,17 +75,18 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
|
||||
await codeql.databaseBundle(databasePath, databaseBundlePath);
|
||||
// Upload the database bundle
|
||||
const payload = fs.readFileSync(databaseBundlePath);
|
||||
const uploadResponse = await client.request(`PUT /repos/:owner/:repo/code-scanning/databases/${language}`, {
|
||||
owner: repositoryNwo.owner,
|
||||
repo: repositoryNwo.repo,
|
||||
data: payload,
|
||||
});
|
||||
if (uploadResponse.status === 201) {
|
||||
try {
|
||||
await client.request(`PUT /repos/:owner/:repo/code-scanning/databases/${language}`, {
|
||||
owner: repositoryNwo.owner,
|
||||
repo: repositoryNwo.repo,
|
||||
data: payload,
|
||||
});
|
||||
logger.debug(`Successfully uploaded database for ${language}`);
|
||||
}
|
||||
else {
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
// Log a warning but don't fail the workflow
|
||||
logger.warning(`Failed to upload database for ${language}. ${uploadResponse.data}`);
|
||||
logger.warning(`Failed to upload database for ${language}: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Generated
+5
@@ -408,4 +408,9 @@ function getRequiredEnvParam(paramName) {
|
||||
return value;
|
||||
}
|
||||
exports.getRequiredEnvParam = getRequiredEnvParam;
|
||||
function isHTTPError(arg) {
|
||||
var _a;
|
||||
return ((_a = arg) === null || _a === void 0 ? void 0 : _a.status) !== undefined && Number.isInteger(arg.status);
|
||||
}
|
||||
exports.isHTTPError = isHTTPError;
|
||||
//# sourceMappingURL=util.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user