Skip to content

Commit bf97a6d

Browse files
committed
Apply suggestions from code review
1 parent 7e086b2 commit bf97a6d

File tree

7 files changed

+55
-24
lines changed

7 files changed

+55
-24
lines changed

init/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ inputs:
1515
required: false
1616
registries:
1717
description: |
18-
A YAML string that defines the list of GitHub container registries to use for downloading packs. The string is in the following forma (the | is required on the first line):
18+
A YAML string that defines the list of GitHub container registries to use for downloading packs. The string is in the following form (the | is required on the first line):
1919
2020
registries: |
2121
- url: https://containers.GHEHOSTNAME1/v2/
@@ -28,7 +28,7 @@ inputs:
2828
packages: */*
2929
token: ${{ secrets.GHCR_TOKEN }}
3030
31-
The url property contains the url to the container registry you want to connect to.
31+
The url property contains the URL to the container registry you want to connect to.
3232
3333
The packages property contains a single entry or a list of globs specifying packages that can be found in the container registry. Order is important. Earlier entries will match before later entries.
3434

lib/config-utils.js

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

lib/config-utils.js.map

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

lib/config-utils.test.js

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

lib/config-utils.test.js.map

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

src/config-utils.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,12 +2253,13 @@ test("downloadPacks-no-registries", async (t) => {
22532253
go: ["c", "d"],
22542254
python: ["e", "f"],
22552255
},
2256-
undefined,
2256+
undefined, // registries
22572257
sampleApiDetails,
22582258
tmpDir,
22592259
logger
22602260
);
22612261

2262+
// Expecting packs to be downloaded once for java and once for python
22622263
t.deepEqual(packDownloadStub.callCount, 2);
22632264
// no config file was created, so pass `undefined` as the config file path
22642265
t.deepEqual(packDownloadStub.firstCall.args, [["a", "b"], undefined]);
@@ -2283,7 +2284,7 @@ test("downloadPacks-with-registries", async (t) => {
22832284
{
22842285
url: "https://containers.GHEHOSTNAME1/v2/",
22852286
packages: "semmle/*",
2286-
token: "still-a-token",
2287+
token: "still-not-a-token",
22872288
},
22882289
];
22892290

@@ -2292,15 +2293,15 @@ test("downloadPacks-with-registries", async (t) => {
22922293
packDownloadStub.callsFake((packs, configFile) => {
22932294
t.deepEqual(configFile, expectedConfigFile);
22942295
// verify the env vars were set correctly
2295-
t.deepEqual(process.env.GITHUB_TOKEN, "token");
2296+
t.deepEqual(process.env.GITHUB_TOKEN, sampleApiDetails.auth);
22962297
t.deepEqual(
22972298
process.env.CODEQL_REGISTRIES_AUTH,
22982299
"http://ghcr.io=not-a-token,https://containers.GHEHOSTNAME1/v2/=still-a-token"
22992300
);
23002301

23012302
// verify the config file contents were set correctly
23022303
const config = yaml.load(fs.readFileSync(configFile, "utf8")) as {
2303-
registries: configUtils.SafeRegistryConfig[];
2304+
registries: configUtils.RegistryConfigNoCredentials[];
23042305
};
23052306
t.deepEqual(
23062307
config.registries,

src/config-utils.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface UserConfig {
6161

6262
export type QueryFilter = ExcludeQueryFilter | IncludeQueryFilter;
6363

64-
export type RegistryConfig = SafeRegistryConfig & {
64+
export type RegistryConfigWithCredentials = RegistryConfigNoCredentials & {
6565
// Token to use when downloading packs from this registry.
6666
token: string;
6767
};
@@ -70,7 +70,7 @@ export type RegistryConfig = SafeRegistryConfig & {
7070
* The list of registries and the associated pack globs that determine where each
7171
* pack can be downloaded from.
7272
*/
73-
export interface SafeRegistryConfig {
73+
export interface RegistryConfigNoCredentials {
7474
// URL of a package registry, eg- https://ghcr.io/v2/
7575
url: string;
7676

@@ -1721,15 +1721,15 @@ export async function initConfig(
17211721
return config;
17221722
}
17231723

1724-
function parseRegistries(registriesInput: string | undefined) {
1724+
function parseRegistries(
1725+
registriesInput: string | undefined
1726+
): RegistryConfigWithCredentials[] | undefined {
17251727
try {
1726-
return registriesInput ? yaml.l(registriesInput) : undefined;
1728+
return registriesInput
1729+
? (yaml.load(registriesInput) as RegistryConfigWithCredentials[])
1730+
: undefined;
17271731
} catch (e) {
1728-
throw new Error(
1729-
`Invalid registries input. Must be a JSON string, but got: ${
1730-
e instanceof Error ? e.message : String(e)
1731-
}`
1732-
);
1732+
throw new Error("Invalid registries input. Must be a YAML string.");
17331733
}
17341734
}
17351735

@@ -1834,7 +1834,7 @@ export async function downloadPacks(
18341834
codeQL: CodeQL,
18351835
languages: Language[],
18361836
packs: Packs,
1837-
registries: RegistryConfig[] | undefined,
1837+
registries: RegistryConfigWithCredentials[] | undefined,
18381838
apiDetails: api.GitHubApiDetails,
18391839
tmpDir: string,
18401840
logger: Logger
@@ -1888,7 +1888,9 @@ export async function downloadPacks(
18881888
);
18891889
}
18901890

1891-
function createRegistriesBlock(registries: RegistryConfig[]) {
1891+
function createRegistriesBlock(registries: RegistryConfigWithCredentials[]): {
1892+
registries: RegistryConfigNoCredentials[];
1893+
} {
18921894
// be sure to remove the `token` field from the registry before writing it to disk.
18931895
const safeRegistries = registries.map((registry) => ({
18941896
url: registry.url,
@@ -1900,6 +1902,18 @@ function createRegistriesBlock(registries: RegistryConfig[]) {
19001902
return qlconfig;
19011903
}
19021904

1905+
/**
1906+
* Create a temporary environment based on the existing environment and overridden
1907+
* by the given environment variables that are passed in as arguments.
1908+
*
1909+
* Use this new environment in the context of the given operation. After completing
1910+
* the operation, restore the original environment.
1911+
*
1912+
* This function does not support un-setting environment variables.
1913+
*
1914+
* @param env
1915+
* @param operation
1916+
*/
19031917
async function wrapEnvironment(
19041918
env: Record<string, string | undefined>,
19051919
operation: Function

0 commit comments

Comments
 (0)