Skip to content

Commit c9b75a7

Browse files
committed
Add fixCategory to AnalysisConfig
1 parent 10a2917 commit c9b75a7

File tree

8 files changed

+78
-10
lines changed

8 files changed

+78
-10
lines changed

lib/analyze-action.js

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

lib/init-action-post.js

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

lib/upload-lib.js

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

lib/upload-sarif-action.js

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

src/analyses.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { fixCodeQualityCategory } from "./actions-util";
2+
import { Logger } from "./logging";
13
import { ConfigurationError } from "./util";
24

35
export enum AnalysisKind {
@@ -61,6 +63,8 @@ export interface AnalysisConfig {
6163
/** A predicate on filenames to decide whether a SARIF file
6264
* belongs to this kind of analysis. */
6365
sarifPredicate: (name: string) => boolean;
66+
/** Analysis-specific adjustment of the category. */
67+
fixCategory: (logger: Logger, category?: string) => string | undefined;
6468
/** A prefix for environment variables used to track the uniqueness of SARIF uploads. */
6569
sentinelPrefix: string;
6670
}
@@ -74,6 +78,7 @@ export const CodeScanning: AnalysisConfig = {
7478
sarifPredicate: (name) =>
7579
name.endsWith(CodeScanning.sarifExtension) &&
7680
!CodeQuality.sarifPredicate(name),
81+
fixCategory: (_, category) => category,
7782
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
7883
};
7984

@@ -84,6 +89,7 @@ export const CodeQuality: AnalysisConfig = {
8489
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY,
8590
sarifExtension: ".quality.sarif",
8691
sarifPredicate: (name) => name.endsWith(CodeQuality.sarifExtension),
92+
fixCategory: fixCodeQualityCategory,
8793
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
8894
};
8995

src/analyze-action.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,17 @@ async function run() {
345345
}
346346

347347
if (isCodeQualityEnabled(config)) {
348+
const analysis = analyses.CodeQuality;
348349
const qualityUploadResult = await uploadLib.uploadFiles(
349350
outputDir,
350351
actionsUtil.getRequiredInput("checkout_path"),
351-
actionsUtil.fixCodeQualityCategory(
352+
analysis.fixCategory(
352353
logger,
353354
actionsUtil.getOptionalInput("category"),
354355
),
355356
features,
356357
logger,
357-
analyses.CodeQuality,
358+
analysis,
358359
);
359360
core.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
360361
}

src/analyze.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as del from "del";
77
import * as yaml from "js-yaml";
88

99
import {
10-
fixCodeQualityCategory,
1110
getRequiredInput,
1211
getTemporaryDirectory,
1312
PullRequestBranches,
@@ -781,7 +780,7 @@ export async function runQueries(
781780
// accepted by the Code Quality backend.
782781
let category = automationDetailsId;
783782
if (analysis.kind === analyses.AnalysisKind.CodeQuality) {
784-
category = fixCodeQualityCategory(logger, automationDetailsId);
783+
category = analysis.fixCategory(logger, automationDetailsId);
785784
}
786785

787786
const sarifFile = path.join(

src/upload-sarif.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from "fs";
22

3-
import * as actionsUtil from "./actions-util";
43
import * as analyses from "./analyses";
54
import { FeatureEnablement } from "./feature-flags";
65
import { Logger } from "./logging";
@@ -112,7 +111,7 @@ export async function uploadSarif(
112111
pathStats,
113112
checkoutPath,
114113
analyses.CodeQuality,
115-
actionsUtil.fixCodeQualityCategory(logger, category),
114+
analyses.CodeQuality.fixCategory(logger, category),
116115
);
117116
if (qualityUploadResult !== undefined) {
118117
uploadResults[analyses.AnalysisKind.CodeQuality] = qualityUploadResult;

0 commit comments

Comments
 (0)