mirror of
https://github.com/github/codeql-action.git
synced 2026-04-29 18:30:14 +00:00
Add and use getAnalysisConfig
This commit is contained in:
@@ -87,6 +87,23 @@ export const CodeQuality: AnalysisConfig = {
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the `AnalysisConfig` corresponding to `kind`.
|
||||
* @param kind The analysis kind to get the `AnalysisConfig` for.
|
||||
* @returns The `AnalysisConfig` corresponding to `kind`.
|
||||
*/
|
||||
export function getAnalysisConfig(kind: AnalysisKind): AnalysisConfig {
|
||||
// Using a switch statement here accomplishes two things:
|
||||
// 1. The type checker believes us that we have a case for every `AnalysisKind`.
|
||||
// 2. If we ever add another member to `AnalysisKind`, the type checker will alert us that we have to add a case.
|
||||
switch (kind) {
|
||||
case AnalysisKind.CodeScanning:
|
||||
return CodeScanning;
|
||||
case AnalysisKind.CodeQuality:
|
||||
return CodeQuality;
|
||||
}
|
||||
}
|
||||
|
||||
// Since we have overlapping extensions (i.e. ".sarif" includes ".quality.sarif"),
|
||||
// we want to scan a folder containing SARIF files in an order that finds the more
|
||||
// specific extensions first. This constant defines an array in the order of analyis
|
||||
|
||||
@@ -7,8 +7,8 @@ import * as sinon from "sinon";
|
||||
import {
|
||||
AnalysisConfig,
|
||||
AnalysisKind,
|
||||
CodeQuality,
|
||||
CodeScanning,
|
||||
getAnalysisConfig,
|
||||
} from "./analyses";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { createFeatures, setupTests } from "./testing-utils";
|
||||
@@ -117,9 +117,7 @@ const uploadSarifMacro = test.macro({
|
||||
sinon.match.any,
|
||||
features,
|
||||
logger,
|
||||
analysisKind === AnalysisKind.CodeScanning
|
||||
? CodeScanning
|
||||
: CodeQuality,
|
||||
getAnalysisConfig(analysisKind),
|
||||
)
|
||||
.resolves(expectedResult[analysisKind as AnalysisKind]?.uploadResult);
|
||||
}
|
||||
@@ -146,9 +144,7 @@ const uploadSarifMacro = test.macro({
|
||||
sinon.match.any,
|
||||
features,
|
||||
logger,
|
||||
analysisKind === AnalysisKind.CodeScanning
|
||||
? CodeScanning
|
||||
: CodeQuality,
|
||||
getAnalysisConfig(analysisKind),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -164,9 +160,7 @@ const uploadSarifMacro = test.macro({
|
||||
sinon.match.any,
|
||||
features,
|
||||
logger,
|
||||
analysisKind === AnalysisKind.CodeScanning
|
||||
? CodeScanning
|
||||
: CodeQuality,
|
||||
getAnalysisConfig(analysisKind),
|
||||
),
|
||||
`uploadSpecifiedFiles was called for ${analysisKind}, but should not have been.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user