Skip to content

Commit 0525f9e

Browse files
committed
Add and use getAnalysisConfig
1 parent 2c06a70 commit 0525f9e

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/analyses.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ export const CodeQuality: AnalysisConfig = {
8787
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
8888
};
8989

90+
/**
91+
* Gets the `AnalysisConfig` corresponding to `kind`.
92+
* @param kind The analysis kind to get the `AnalysisConfig` for.
93+
* @returns The `AnalysisConfig` corresponding to `kind`.
94+
*/
95+
export function getAnalysisConfig(kind: AnalysisKind): AnalysisConfig {
96+
// Using a switch statement here accomplishes two things:
97+
// 1. The type checker believes us that we have a case for every `AnalysisKind`.
98+
// 2. If we ever add another member to `AnalysisKind`, the type checker will alert us that we have to add a case.
99+
switch (kind) {
100+
case AnalysisKind.CodeScanning:
101+
return CodeScanning;
102+
case AnalysisKind.CodeQuality:
103+
return CodeQuality;
104+
}
105+
}
106+
90107
// Since we have overlapping extensions (i.e. ".sarif" includes ".quality.sarif"),
91108
// we want to scan a folder containing SARIF files in an order that finds the more
92109
// specific extensions first. This constant defines an array in the order of analyis

src/upload-sarif.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as sinon from "sinon";
77
import {
88
AnalysisConfig,
99
AnalysisKind,
10-
CodeQuality,
1110
CodeScanning,
11+
getAnalysisConfig,
1212
} from "./analyses";
1313
import { getRunnerLogger } from "./logging";
1414
import { createFeatures, setupTests } from "./testing-utils";
@@ -117,9 +117,7 @@ const uploadSarifMacro = test.macro({
117117
sinon.match.any,
118118
features,
119119
logger,
120-
analysisKind === AnalysisKind.CodeScanning
121-
? CodeScanning
122-
: CodeQuality,
120+
getAnalysisConfig(analysisKind),
123121
)
124122
.resolves(expectedResult[analysisKind as AnalysisKind]?.uploadResult);
125123
}
@@ -146,9 +144,7 @@ const uploadSarifMacro = test.macro({
146144
sinon.match.any,
147145
features,
148146
logger,
149-
analysisKind === AnalysisKind.CodeScanning
150-
? CodeScanning
151-
: CodeQuality,
147+
getAnalysisConfig(analysisKind),
152148
),
153149
);
154150
} else {
@@ -164,9 +160,7 @@ const uploadSarifMacro = test.macro({
164160
sinon.match.any,
165161
features,
166162
logger,
167-
analysisKind === AnalysisKind.CodeScanning
168-
? CodeScanning
169-
: CodeQuality,
163+
getAnalysisConfig(analysisKind),
170164
),
171165
`uploadSpecifiedFiles was called for ${analysisKind}, but should not have been.`,
172166
);

0 commit comments

Comments
 (0)