mirror of
https://github.com/github/codeql-action.git
synced 2026-05-08 06:40:19 +00:00
Add isOtherAnalysisSarif with tests
This commit is contained in:
@@ -2,6 +2,7 @@ import test from "ava";
|
||||
|
||||
import {
|
||||
AnalysisKind,
|
||||
isOtherAnalysisSarif,
|
||||
parseAnalysisKinds,
|
||||
supportedAnalysisKinds,
|
||||
} from "./analyses";
|
||||
@@ -34,3 +35,23 @@ test("Parsing analysis kinds requires at least one analysis kind", async (t) =>
|
||||
instanceOf: ConfigurationError,
|
||||
});
|
||||
});
|
||||
|
||||
test("isOtherAnalysisSarif", async (t) => {
|
||||
function expectTrue(analysisKind: AnalysisKind, filepath: string) {
|
||||
t.assert(
|
||||
isOtherAnalysisSarif(analysisKind, filepath),
|
||||
`Expected ${filepath} to be for another analysis kind, but it matched ${analysisKind}.`,
|
||||
);
|
||||
}
|
||||
function expectFalse(analysisKind: AnalysisKind, filepath: string) {
|
||||
t.assert(
|
||||
!isOtherAnalysisSarif(analysisKind, filepath),
|
||||
`Expected ${filepath} to be for ${analysisKind}, but it matched some other analysis kind.`,
|
||||
);
|
||||
}
|
||||
expectTrue(AnalysisKind.CodeQuality, "test.sarif");
|
||||
expectFalse(AnalysisKind.CodeQuality, "test.quality.sarif");
|
||||
expectTrue(AnalysisKind.CodeScanning, "test.quality.sarif");
|
||||
expectFalse(AnalysisKind.CodeScanning, "test.sarif");
|
||||
expectFalse(AnalysisKind.CodeScanning, "test.json");
|
||||
});
|
||||
|
||||
@@ -86,3 +86,23 @@ export const CodeQuality: AnalysisConfig = {
|
||||
sarifPredicate: (name) => name.endsWith(CodeQuality.sarifExtension),
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||
};
|
||||
|
||||
// An array of all analysis configurations we know of.
|
||||
export const Analyses = [CodeScanning, CodeQuality];
|
||||
|
||||
/**
|
||||
* Determines based on the given `filepath`, whether the file is a SARIF file for
|
||||
* an analysis other than the one given by `current`.
|
||||
*
|
||||
* @param current The current analysis kind.
|
||||
* @param filepath The path of the file to check.
|
||||
* @returns True if `filepath` is a SARIF file for an analysis other than `current`; False otherwise.
|
||||
*/
|
||||
export function isOtherAnalysisSarif(
|
||||
current: AnalysisKind,
|
||||
filepath: string,
|
||||
): boolean {
|
||||
return Analyses.some(
|
||||
(config) => config.kind !== current && config.sarifPredicate(filepath),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user