mirror of
https://github.com/github/codeql-action.git
synced 2025-12-23 15:50:11 +08:00
Move .sarif predicates into UploadTarget instances and rename
This commit is contained in:
16
lib/upload-lib.js
generated
16
lib/upload-lib.js
generated
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.defaultIsSarif = exports.qualityIsSarif = exports.SARIF_UPLOAD_ENDPOINT = void 0;
|
||||
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.SARIF_UPLOAD_ENDPOINT = void 0;
|
||||
exports.shouldShowCombineSarifFilesDeprecationWarning = shouldShowCombineSarifFilesDeprecationWarning;
|
||||
exports.populateRunAutomationDetails = populateRunAutomationDetails;
|
||||
exports.findSarifFilesInDir = findSarifFilesInDir;
|
||||
@@ -282,13 +282,9 @@ async function uploadPayload(payload, repositoryNwo, logger, target = SARIF_UPLO
|
||||
throw (0, api_client_1.wrapApiConfigurationError)(e);
|
||||
}
|
||||
}
|
||||
const qualityIsSarif = (name) => name.endsWith(".quality.sarif");
|
||||
exports.qualityIsSarif = qualityIsSarif;
|
||||
const defaultIsSarif = (name) => name.endsWith(".sarif") && !(0, exports.qualityIsSarif)(name);
|
||||
exports.defaultIsSarif = defaultIsSarif;
|
||||
// Recursively walks a directory and returns all SARIF files it finds.
|
||||
// Does not follow symlinks.
|
||||
function findSarifFilesInDir(sarifPath, isSarif = exports.defaultIsSarif) {
|
||||
function findSarifFilesInDir(sarifPath, isSarif = exports.CodeScanningTarget.sarifPredicate) {
|
||||
const sarifFiles = [];
|
||||
const walkSarifFiles = (dir) => {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
@@ -304,7 +300,7 @@ function findSarifFilesInDir(sarifPath, isSarif = exports.defaultIsSarif) {
|
||||
walkSarifFiles(sarifPath);
|
||||
return sarifFiles;
|
||||
}
|
||||
function getSarifFilePaths(sarifPath, isSarif = exports.defaultIsSarif) {
|
||||
function getSarifFilePaths(sarifPath, isSarif = exports.CodeScanningTarget.sarifPredicate) {
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
// This is always a configuration error, even for first-party runs.
|
||||
throw new util_1.ConfigurationError(`Path does not exist: ${sarifPath}`);
|
||||
@@ -425,14 +421,14 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
|
||||
exports.CodeScanningTarget = {
|
||||
name: "code scanning",
|
||||
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
||||
sarifFilter: exports.defaultIsSarif,
|
||||
sarifPredicate: (name) => name.endsWith(".sarif") && !exports.CodeQualityTarget.sarifPredicate(name),
|
||||
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
||||
};
|
||||
// Represents the Code Quality upload target.
|
||||
exports.CodeQualityTarget = {
|
||||
name: "code quality",
|
||||
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
||||
sarifFilter: exports.qualityIsSarif,
|
||||
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||
};
|
||||
/**
|
||||
@@ -440,7 +436,7 @@ exports.CodeQualityTarget = {
|
||||
* to.
|
||||
*/
|
||||
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget = exports.CodeScanningTarget) {
|
||||
const sarifPaths = getSarifFilePaths(inputSarifPath, uploadTarget.sarifFilter);
|
||||
const sarifPaths = getSarifFilePaths(inputSarifPath, uploadTarget.sarifPredicate);
|
||||
return uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget);
|
||||
}
|
||||
/**
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
lib/upload-lib.test.js
generated
2
lib/upload-lib.test.js
generated
@@ -101,7 +101,7 @@ ava_1.default.beforeEach(() => {
|
||||
path.join(tmpDir, "dir1", "d.sarif"),
|
||||
path.join(tmpDir, "dir1", "dir2", "e.sarif"),
|
||||
]);
|
||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(tmpDir, uploadLib.qualityIsSarif);
|
||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(tmpDir, uploadLib.CodeQualityTarget.sarifPredicate);
|
||||
t.deepEqual(qualitySarifFiles, [
|
||||
path.join(tmpDir, "a.quality.sarif"),
|
||||
path.join(tmpDir, "dir1", "b.quality.sarif"),
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -137,7 +137,7 @@ test("finding SARIF files", async (t) => {
|
||||
|
||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
|
||||
tmpDir,
|
||||
uploadLib.qualityIsSarif,
|
||||
uploadLib.CodeQualityTarget.sarifPredicate,
|
||||
);
|
||||
|
||||
t.deepEqual(qualitySarifFiles, [
|
||||
|
||||
@@ -380,15 +380,11 @@ export interface UploadResult {
|
||||
sarifID: string;
|
||||
}
|
||||
|
||||
export const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
|
||||
export const defaultIsSarif = (name: string) =>
|
||||
name.endsWith(".sarif") && !qualityIsSarif(name);
|
||||
|
||||
// Recursively walks a directory and returns all SARIF files it finds.
|
||||
// Does not follow symlinks.
|
||||
export function findSarifFilesInDir(
|
||||
sarifPath: string,
|
||||
isSarif: (name: string) => boolean = defaultIsSarif,
|
||||
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
|
||||
): string[] {
|
||||
const sarifFiles: string[] = [];
|
||||
const walkSarifFiles = (dir: string) => {
|
||||
@@ -407,7 +403,7 @@ export function findSarifFilesInDir(
|
||||
|
||||
export function getSarifFilePaths(
|
||||
sarifPath: string,
|
||||
isSarif: (name: string) => boolean = defaultIsSarif,
|
||||
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
|
||||
) {
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
// This is always a configuration error, even for first-party runs.
|
||||
@@ -585,7 +581,7 @@ export function buildPayload(
|
||||
export interface UploadTarget {
|
||||
name: string;
|
||||
target: SARIF_UPLOAD_ENDPOINT;
|
||||
sarifFilter: (name: string) => boolean;
|
||||
sarifPredicate: (name: string) => boolean;
|
||||
sentinelPrefix: string;
|
||||
}
|
||||
|
||||
@@ -593,7 +589,7 @@ export interface UploadTarget {
|
||||
export const CodeScanningTarget: UploadTarget = {
|
||||
name: "code scanning",
|
||||
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
||||
sarifFilter: defaultIsSarif,
|
||||
sarifPredicate: (name) => name.endsWith(".sarif") && !CodeQualityTarget.sarifPredicate(name),
|
||||
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
||||
};
|
||||
|
||||
@@ -601,7 +597,7 @@ export const CodeScanningTarget: UploadTarget = {
|
||||
export const CodeQualityTarget: UploadTarget = {
|
||||
name: "code quality",
|
||||
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
||||
sarifFilter: qualityIsSarif,
|
||||
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||
};
|
||||
|
||||
@@ -619,7 +615,7 @@ export async function uploadFiles(
|
||||
): Promise<UploadResult> {
|
||||
const sarifPaths = getSarifFilePaths(
|
||||
inputSarifPath,
|
||||
uploadTarget.sarifFilter,
|
||||
uploadTarget.sarifPredicate,
|
||||
);
|
||||
|
||||
return uploadSpecifiedFiles(
|
||||
|
||||
Reference in New Issue
Block a user