Skip to content

Commit 5c02493

Browse files
authored
Merge pull request #2394 from rvermeulen/rvermeulen/extend-init-complete-status-report
Extend init complete status report
2 parents 3ec2588 + a8ab493 commit 5c02493

12 files changed

+94
-13
lines changed

lib/codeql.js

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import * as setupCodeql from "./setup-codeql";
3131
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
3232
import { shouldEnableIndirectTracing } from "./tracer-config";
3333
import * as util from "./util";
34-
import { BuildMode, wrapError } from "./util";
34+
import { BuildMode, wrapError, cloneObject } from "./util";
3535

3636
type Options = Array<string | number | boolean>;
3737

@@ -1306,10 +1306,6 @@ async function generateCodeScanningConfig(
13061306
return codeScanningConfigFile;
13071307
}
13081308

1309-
function cloneObject<T>(obj: T): T {
1310-
return JSON.parse(JSON.stringify(obj)) as T;
1311-
}
1312-
13131309
// This constant sets the size of each TRAP cache in megabytes.
13141310
const TRAP_CACHE_SIZE_MB = 1024;
13151311

src/config-utils.ts

+9
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,15 @@ function parseRegistries(
881881
}
882882
}
883883

884+
export function parseRegistriesWithoutCredentials(
885+
registriesInput?: string,
886+
): RegistryConfigNoCredentials[] | undefined {
887+
return parseRegistries(registriesInput)?.map((r) => {
888+
const { url, packages } = r;
889+
return { url, packages };
890+
});
891+
}
892+
884893
function isLocal(configPath: string): boolean {
885894
// If the path starts with ./, look locally
886895
if (configPath.indexOf("./") === 0) {

src/init-action.ts

+42
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
ConfigurationError,
6161
wrapError,
6262
checkActionVersion,
63+
cloneObject,
6364
} from "./util";
6465
import { validateWorkflow } from "./workflow";
6566

@@ -85,12 +86,19 @@ interface InitWithConfigStatusReport extends InitStatusReport {
8586
paths_ignore: string;
8687
/** Comma-separated list of queries sources, from the 'queries' config field or workflow input. */
8788
queries: string;
89+
/** Stringified JSON object of packs, from the 'packs' config field or workflow input. */
90+
packs: string;
8891
/** Comma-separated list of languages for which we are using TRAP caching. */
8992
trap_cache_languages: string;
9093
/** Size of TRAP caches that we downloaded, in bytes. */
9194
trap_cache_download_size_bytes: number;
9295
/** Time taken to download TRAP caches, in milliseconds. */
9396
trap_cache_download_duration_ms: number;
97+
/** Stringified JSON array of registry configuration objects, from the 'registries' config field
98+
or workflow input. **/
99+
registries: string;
100+
/** Stringified JSON object representing a query-filters, from the 'query-filters' config field. **/
101+
query_filters: string;
94102
}
95103

96104
/** Fields of the init status report populated when the tools source is `download`. */
@@ -174,18 +182,52 @@ async function sendCompletedStatusReport(
174182
queries.push(...queriesInput.split(","));
175183
}
176184

185+
let packs: Record<string, string[]> = {};
186+
if (
187+
(config.augmentationProperties.packsInputCombines ||
188+
!config.augmentationProperties.packsInput) &&
189+
config.originalUserInput.packs
190+
) {
191+
// Make a copy, because we might modify `packs`.
192+
const copyPacksFromOriginalUserInput = cloneObject(
193+
config.originalUserInput.packs,
194+
);
195+
// If it is an array, then assume there is only a single language being analyzed.
196+
if (Array.isArray(copyPacksFromOriginalUserInput)) {
197+
packs[config.languages[0]] = copyPacksFromOriginalUserInput;
198+
} else {
199+
packs = copyPacksFromOriginalUserInput;
200+
}
201+
}
202+
203+
if (config.augmentationProperties.packsInput) {
204+
packs[config.languages[0]] ??= [];
205+
packs[config.languages[0]].push(
206+
...config.augmentationProperties.packsInput,
207+
);
208+
}
209+
177210
// Append fields that are dependent on `config`
178211
const initWithConfigStatusReport: InitWithConfigStatusReport = {
179212
...initStatusReport,
180213
disable_default_queries: disableDefaultQueries,
181214
paths,
182215
paths_ignore: pathsIgnore,
183216
queries: queries.join(","),
217+
packs: JSON.stringify(packs),
184218
trap_cache_languages: Object.keys(config.trapCaches).join(","),
185219
trap_cache_download_size_bytes: Math.round(
186220
await getTotalCacheSize(config.trapCaches, logger),
187221
),
188222
trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime),
223+
query_filters: JSON.stringify(
224+
config.originalUserInput["query-filters"] ?? [],
225+
),
226+
registries: JSON.stringify(
227+
configUtils.parseRegistriesWithoutCredentials(
228+
getOptionalInput("registries"),
229+
) ?? [],
230+
),
189231
};
190232
await sendStatusReport({
191233
...initWithConfigStatusReport,

src/util.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1100,3 +1100,7 @@ export enum BuildMode {
11001100
/** The database will be created by building the source root using manually specified build steps. */
11011101
Manual = "manual",
11021102
}
1103+
1104+
export function cloneObject<T>(obj: T): T {
1105+
return JSON.parse(JSON.stringify(obj)) as T;
1106+
}

0 commit comments

Comments
 (0)