Skip to content

Commit 08955db

Browse files
committed
Move .sarif predicates into UploadTarget instances and rename
1 parent 71dd633 commit 08955db

File tree

6 files changed

+16
-24
lines changed

6 files changed

+16
-24
lines changed

lib/upload-lib.js

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test("finding SARIF files", async (t) => {
137137

138138
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
139139
tmpDir,
140-
uploadLib.qualityIsSarif,
140+
uploadLib.CodeQualityTarget.sarifPredicate,
141141
);
142142

143143
t.deepEqual(qualitySarifFiles, [

src/upload-lib.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,11 @@ export interface UploadResult {
380380
sarifID: string;
381381
}
382382

383-
export const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
384-
export const defaultIsSarif = (name: string) =>
385-
name.endsWith(".sarif") && !qualityIsSarif(name);
386-
387383
// Recursively walks a directory and returns all SARIF files it finds.
388384
// Does not follow symlinks.
389385
export function findSarifFilesInDir(
390386
sarifPath: string,
391-
isSarif: (name: string) => boolean = defaultIsSarif,
387+
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
392388
): string[] {
393389
const sarifFiles: string[] = [];
394390
const walkSarifFiles = (dir: string) => {
@@ -407,7 +403,7 @@ export function findSarifFilesInDir(
407403

408404
export function getSarifFilePaths(
409405
sarifPath: string,
410-
isSarif: (name: string) => boolean = defaultIsSarif,
406+
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
411407
) {
412408
if (!fs.existsSync(sarifPath)) {
413409
// This is always a configuration error, even for first-party runs.
@@ -585,23 +581,23 @@ export function buildPayload(
585581
export interface UploadTarget {
586582
name: string;
587583
target: SARIF_UPLOAD_ENDPOINT;
588-
sarifFilter: (name: string) => boolean;
584+
sarifPredicate: (name: string) => boolean;
589585
sentinelPrefix: string;
590586
}
591587

592588
// Represents the Code Scanning upload target.
593589
export const CodeScanningTarget: UploadTarget = {
594590
name: "code scanning",
595591
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
596-
sarifFilter: defaultIsSarif,
592+
sarifPredicate: (name) => name.endsWith(".sarif") && !CodeQualityTarget.sarifPredicate(name),
597593
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
598594
};
599595

600596
// Represents the Code Quality upload target.
601597
export const CodeQualityTarget: UploadTarget = {
602598
name: "code quality",
603599
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
604-
sarifFilter: qualityIsSarif,
600+
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
605601
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
606602
};
607603

@@ -619,7 +615,7 @@ export async function uploadFiles(
619615
): Promise<UploadResult> {
620616
const sarifPaths = getSarifFilePaths(
621617
inputSarifPath,
622-
uploadTarget.sarifFilter,
618+
uploadTarget.sarifPredicate,
623619
);
624620

625621
return uploadSpecifiedFiles(

0 commit comments

Comments
 (0)