Skip to content

Commit e537ff2

Browse files
committed
Make path optional in parseRemoteFileAddress
1 parent 598d008 commit e537ff2

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

lib/entry-points.js

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

src/config/remote-file.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import test from "ava";
33
import { ConfigurationError } from "../util";
44

55
import {
6+
DEFAULT_CONFIG_FILE_NAME,
67
DEFAULT_CONFIG_FILE_REF,
78
parseRemoteFileAddress,
89
RemoteFileAddress,
@@ -27,6 +28,22 @@ test("expandConfigFileInput accepts full remote addresses", async (t) => {
2728
);
2829
});
2930

31+
test("expandConfigFileInput accepts remote address without a path", async (t) => {
32+
t.deepEqual(parseRemoteFileAddress("owner/repo@ref"), {
33+
owner: "owner",
34+
repo: "repo",
35+
path: DEFAULT_CONFIG_FILE_NAME,
36+
ref: "ref",
37+
} satisfies RemoteFileAddress);
38+
39+
t.deepEqual(parseRemoteFileAddress("owner/repo"), {
40+
owner: "owner",
41+
repo: "repo",
42+
path: DEFAULT_CONFIG_FILE_NAME,
43+
ref: DEFAULT_CONFIG_FILE_REF,
44+
} satisfies RemoteFileAddress);
45+
});
46+
3047
test("expandConfigFileInput accepts remote address without a ref", async (t) => {
3148
t.deepEqual(parseRemoteFileAddress("owner/repo/path"), {
3249
owner: "owner",
@@ -47,7 +64,7 @@ test("expandConfigFileInput rejects invalid values", async (t) => {
4764
t.throws(() => parseRemoteFileAddress(" "), {
4865
instanceOf: ConfigurationError,
4966
});
50-
t.throws(() => parseRemoteFileAddress("repo:/absolute"), {
67+
t.throws(() => parseRemoteFileAddress("repo//absolute"), {
5168
instanceOf: ConfigurationError,
5269
});
5370
t.throws(() => parseRemoteFileAddress("repo:file.yml:unexpected"), {

src/config/remote-file.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export interface RemoteFileAddress {
1313
ref: string;
1414
}
1515

16+
/** The default file path to use in configuration file shorthands. */
17+
export const DEFAULT_CONFIG_FILE_NAME = ".github/codeql-action.yaml";
18+
1619
/** The default ref to use in configuration file shorthands. */
1720
export const DEFAULT_CONFIG_FILE_REF = "main";
1821

@@ -26,16 +29,12 @@ export const DEFAULT_CONFIG_FILE_REF = "main";
2629
export function parseRemoteFileAddress(configFile: string): RemoteFileAddress {
2730
// retrieve the various parts of the config location, and ensure they're present
2831
const format = new RegExp(
29-
"(?<owner>[^/]+)/(?<repo>[^/]+)/(?<path>[^@]+)(@(?<ref>.*))?",
32+
"(?<owner>[^/]+)/(?<repo>[^/@]+)(/(?<path>[^@]+))?(@(?<ref>.*))?",
3033
);
3134
const pieces = format.exec(configFile);
3235

3336
// Check that the regular expression matched and that we have at least the required components.
34-
if (
35-
!pieces?.groups?.owner ||
36-
!pieces?.groups?.repo ||
37-
!pieces?.groups?.path
38-
) {
37+
if (!pieces?.groups?.owner || !pieces?.groups?.repo) {
3938
throw new ConfigurationError(
4039
errorMessages.getConfigFileRepoFormatInvalidMessage(configFile),
4140
);
@@ -44,7 +43,7 @@ export function parseRemoteFileAddress(configFile: string): RemoteFileAddress {
4443
return {
4544
owner: pieces.groups.owner,
4645
repo: pieces.groups.repo,
47-
path: pieces.groups.path,
46+
path: pieces.groups.path || DEFAULT_CONFIG_FILE_NAME,
4847
ref: pieces.groups.ref || DEFAULT_CONFIG_FILE_REF,
4948
};
5049
}

0 commit comments

Comments
 (0)