Skip to content

Commit 38846b6

Browse files
committed
Move UploadTarget definitions to analyses.ts
1 parent e550de2 commit 38846b6

File tree

10 files changed

+121
-127
lines changed

10 files changed

+121
-127
lines changed

lib/analyze-action.js

Lines changed: 20 additions & 20 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: 12 additions & 12 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: 20 additions & 31 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: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyses.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,34 @@ export async function parseAnalysisKinds(
3838
new Set(components.map((component) => component as AnalysisKind)),
3939
);
4040
}
41+
42+
// Enumerates API endpoints that accept SARIF files.
43+
export enum SARIF_UPLOAD_ENDPOINT {
44+
CODE_SCANNING = "PUT /repos/:owner/:repo/code-scanning/analysis",
45+
CODE_QUALITY = "PUT /repos/:owner/:repo/code-quality/analysis",
46+
}
47+
48+
// Represents configurations for different services that we can upload SARIF to.
49+
export interface UploadTarget {
50+
name: string;
51+
target: SARIF_UPLOAD_ENDPOINT;
52+
sarifPredicate: (name: string) => boolean;
53+
sentinelPrefix: string;
54+
}
55+
56+
// Represents the Code Scanning upload target.
57+
export const CodeScanningTarget: UploadTarget = {
58+
name: "code scanning",
59+
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING,
60+
sarifPredicate: (name) =>
61+
name.endsWith(".sarif") && !CodeQualityTarget.sarifPredicate(name),
62+
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
63+
};
64+
65+
// Represents the Code Quality upload target.
66+
export const CodeQualityTarget: UploadTarget = {
67+
name: "code quality",
68+
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY,
69+
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
70+
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
71+
};

src/analyze-action.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { performance } from "perf_hooks";
55
import * as core from "@actions/core";
66

77
import * as actionsUtil from "./actions-util";
8+
import * as analyses from "./analyses";
89
import {
910
CodeQLAnalysisError,
1011
dbIsFinalized,
@@ -332,7 +333,7 @@ async function run() {
332333
actionsUtil.getOptionalInput("category"),
333334
features,
334335
logger,
335-
uploadLib.CodeScanningTarget,
336+
analyses.CodeScanningTarget,
336337
);
337338
core.setOutput("sarif-id", uploadResult.sarifID);
338339

@@ -346,7 +347,7 @@ async function run() {
346347
),
347348
features,
348349
logger,
349-
uploadLib.CodeQualityTarget,
350+
analyses.CodeQualityTarget,
350351
);
351352
core.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
352353
}

src/init-action-post-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as core from "@actions/core";
44
import * as github from "@actions/github";
55

66
import * as actionsUtil from "./actions-util";
7+
import { CodeScanningTarget } from "./analyses";
78
import { getApiClient } from "./api-client";
89
import { CodeQL, getCodeQL } from "./codeql";
910
import { Config } from "./config-utils";
@@ -104,7 +105,7 @@ async function maybeUploadFailedSarif(
104105
category,
105106
features,
106107
logger,
107-
uploadLib.CodeScanningTarget,
108+
CodeScanningTarget,
108109
);
109110
await uploadLib.waitForProcessing(
110111
repositoryNwo,

src/upload-lib.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path";
33

44
import test from "ava";
55

6+
import { CodeQualityTarget, CodeScanningTarget } from "./analyses";
67
import { getRunnerLogger, Logger } from "./logging";
78
import { setupTests } from "./testing-utils";
89
import * as uploadLib from "./upload-lib";
@@ -128,7 +129,7 @@ test("finding SARIF files", async (t) => {
128129

129130
const sarifFiles = uploadLib.findSarifFilesInDir(
130131
tmpDir,
131-
uploadLib.CodeScanningTarget.sarifPredicate,
132+
CodeScanningTarget.sarifPredicate,
132133
);
133134

134135
t.deepEqual(sarifFiles, [
@@ -140,7 +141,7 @@ test("finding SARIF files", async (t) => {
140141

141142
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
142143
tmpDir,
143-
uploadLib.CodeQualityTarget.sarifPredicate,
144+
CodeQualityTarget.sarifPredicate,
144145
);
145146

146147
t.deepEqual(qualitySarifFiles, [
@@ -335,7 +336,7 @@ test("validateUniqueCategory with different prefixes", (t) => {
335336
t.notThrows(() =>
336337
uploadLib.validateUniqueCategory(
337338
createMockSarif(),
338-
uploadLib.CodeQualityTarget.sentinelPrefix,
339+
CodeQualityTarget.sentinelPrefix,
339340
),
340341
);
341342
});

0 commit comments

Comments
 (0)