Skip to content

Commit 73f4741

Browse files
committed
Refactor pack registry code out of config-utils
1 parent 5094019 commit 73f4741

4 files changed

Lines changed: 75 additions & 64 deletions

File tree

lib/entry-points.js

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

src/config-utils.ts

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import {
3030
UserConfig,
3131
} from "./config/db-config";
3232
import { getRemoteConfig } from "./config/file";
33+
import {
34+
parseRegistries,
35+
type RegistryConfigNoCredentials,
36+
type RegistryConfigWithCredentials,
37+
} from "./config/pack-registries";
3338
import {
3439
addNoLanguageDiagnostic,
3540
makeTelemetryDiagnostic,
@@ -123,29 +128,6 @@ const OVERLAY_MINIMUM_MEMORY_MB = 5 * 1024;
123128
*/
124129
const CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE = "2.24.3";
125130

126-
export type RegistryConfigWithCredentials = RegistryConfigNoCredentials & {
127-
// Token to use when downloading packs from this registry.
128-
token: string;
129-
};
130-
131-
/**
132-
* The list of registries and the associated pack globs that determine where each
133-
* pack can be downloaded from.
134-
*/
135-
export interface RegistryConfigNoCredentials {
136-
// URL of a package registry, eg- https://ghcr.io/v2/
137-
url: string;
138-
139-
// List of globs that determine which packs are associated with this registry.
140-
packages: string[] | string;
141-
142-
// Kind of registry, either "github" or "docker". Default is "docker".
143-
// "docker" refers specifically to the GitHub Container Registry, which is the usual way of sharing CodeQL packs.
144-
// "github" refers to packs published as content in a GitHub repository. This kind of registry is used in scenarios
145-
// where GHCR is not available, such as certain GHES environments.
146-
kind?: "github" | "docker";
147-
}
148-
149131
async function getSupportedLanguageMap(
150132
codeql: CodeQL,
151133
logger: Logger,
@@ -1200,29 +1182,6 @@ export async function initConfig(
12001182
return config;
12011183
}
12021184

1203-
function parseRegistries(
1204-
registriesInput: string | undefined,
1205-
): RegistryConfigWithCredentials[] | undefined {
1206-
try {
1207-
return registriesInput
1208-
? (yaml.load(registriesInput) as RegistryConfigWithCredentials[])
1209-
: undefined;
1210-
} catch {
1211-
throw new ConfigurationError(
1212-
"Invalid registries input. Must be a YAML string.",
1213-
);
1214-
}
1215-
}
1216-
1217-
export function parseRegistriesWithoutCredentials(
1218-
registriesInput?: string,
1219-
): RegistryConfigNoCredentials[] | undefined {
1220-
return parseRegistries(registriesInput)?.map((r) => {
1221-
const { url, packages, kind } = r;
1222-
return { url, packages, kind };
1223-
});
1224-
}
1225-
12261185
function isLocal(configPath: string): boolean {
12271186
// If the path starts with ./, look locally
12281187
if (configPath.indexOf("./") === 0) {

src/config/pack-registries.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as yaml from "js-yaml";
2+
3+
import { ConfigurationError } from "../util";
4+
5+
export type RegistryConfigWithCredentials = RegistryConfigNoCredentials & {
6+
// Token to use when downloading packs from this registry.
7+
token: string;
8+
};
9+
10+
/**
11+
* The list of registries and the associated pack globs that determine where each
12+
* pack can be downloaded from.
13+
*/
14+
export interface RegistryConfigNoCredentials {
15+
// URL of a package registry, eg- https://ghcr.io/v2/
16+
url: string;
17+
18+
// List of globs that determine which packs are associated with this registry.
19+
packages: string[] | string;
20+
21+
// Kind of registry, either "github" or "docker". Default is "docker".
22+
// "docker" refers specifically to the GitHub Container Registry, which is the usual way of sharing CodeQL packs.
23+
// "github" refers to packs published as content in a GitHub repository. This kind of registry is used in scenarios
24+
// where GHCR is not available, such as certain GHES environments.
25+
kind?: "github" | "docker";
26+
}
27+
28+
export function parseRegistries(
29+
registriesInput: string | undefined,
30+
): RegistryConfigWithCredentials[] | undefined {
31+
try {
32+
return registriesInput
33+
? (yaml.load(registriesInput) as RegistryConfigWithCredentials[])
34+
: undefined;
35+
} catch {
36+
throw new ConfigurationError(
37+
"Invalid registries input. Must be a YAML string.",
38+
);
39+
}
40+
}
41+
42+
export function parseRegistriesWithoutCredentials(
43+
registriesInput?: string,
44+
): RegistryConfigNoCredentials[] | undefined {
45+
return parseRegistries(registriesInput)?.map((r) => {
46+
const { url, packages, kind } = r;
47+
return { url, packages, kind };
48+
});
49+
}

src/status-report.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
isSelfHostedRunner,
1313
} from "./actions-util";
1414
import { getAnalysisKey, getApiClient } from "./api-client";
15-
import { parseRegistriesWithoutCredentials, type Config } from "./config-utils";
15+
import type { Config } from "./config/action-config";
16+
import { parseRegistriesWithoutCredentials } from "./config/pack-registries";
1617
import { DependencyCacheRestoreStatusReport } from "./dependency-caching";
1718
import { DocUrl } from "./doc-url";
1819
import { EnvVar } from "./environment";

0 commit comments

Comments
 (0)