mirror of
https://github.com/github/codeql-action.git
synced 2025-12-07 08:18:08 +08:00
Compare commits
1 Commits
codeql-bun
...
robertbrig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ebdeafc2f |
6
lib/actions-util.js
generated
6
lib/actions-util.js
generated
@@ -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
42
lib/analyze-action.js
generated
42
lib/analyze-action.js
generated
@@ -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
5
lib/util.js
generated
5
lib/util.js
generated
@@ -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
|
||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@ import * as yaml from "js-yaml";
|
||||
|
||||
import * as api from "./api-client";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import { getRequiredEnvParam, GITHUB_DOTCOM_URL } from "./util";
|
||||
import { getRequiredEnvParam, GITHUB_DOTCOM_URL, isHTTPError } from "./util";
|
||||
|
||||
/**
|
||||
* The utils in this module are meant to be run inside of the action only.
|
||||
@@ -576,15 +576,6 @@ export async function createStatusReportBase(
|
||||
return statusReport;
|
||||
}
|
||||
|
||||
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 =
|
||||
|
||||
@@ -76,19 +76,23 @@ async function uploadDatabases(
|
||||
}
|
||||
|
||||
const client = getApiClient(apiDetails);
|
||||
const optInResponse = await client.request(
|
||||
"GET /repos/:owner/:repo/code-scanning/databases",
|
||||
{
|
||||
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;
|
||||
}
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
const codeql = getCodeQL(config.codeQLCmd);
|
||||
@@ -100,21 +104,20 @@ async function uploadDatabases(
|
||||
|
||||
// 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) {
|
||||
logger.debug(`Successfully uploaded database for ${language}`);
|
||||
} else {
|
||||
// Log a warning but don't fail the workflow
|
||||
logger.warning(
|
||||
`Failed to upload database for ${language}. ${uploadResponse.data}`
|
||||
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}`);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
// Log a warning but don't fail the workflow
|
||||
logger.warning(`Failed to upload database for ${language}: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,3 +478,12 @@ export function getRequiredEnvParam(paramName: string): string {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export interface HTTPError {
|
||||
status: number;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export function isHTTPError(arg: any): arg is HTTPError {
|
||||
return arg?.status !== undefined && Number.isInteger(arg.status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user