Skip to content

Commit f5830a3

Browse files
committed
Add and use RepositoryNwoStr type
1 parent f17b444 commit f5830a3

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎lib/entry-points.js‎

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

‎src/repository.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ export interface RepositoryNwo {
66
repo: string;
77
}
88

9+
/** An approximation of what a repository NWO string looks like. */
10+
export type RepositoryNwoStr = `${string}/${string}`;
11+
12+
/** A basic check that `val` looks like a `RepositoryNwoStr`. */
13+
export function isRepositoryNwoStr(val: string): val is RepositoryNwoStr {
14+
return val.includes("/");
15+
}
16+
917
/**
1018
* Get the repository name with owner from the environment variable
1119
* `GITHUB_REPOSITORY`.

‎src/setup/repository.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isRunningLocalAction } from "../actions-util";
33
import * as api from "../api-client";
44
import { ActionsEnvVars } from "../environment";
55
import { GITHUB_DOTCOM_URL } from "../github";
6+
import { isRepositoryNwoStr, type RepositoryNwoStr } from "../repository";
67

78
/** The NWO of the standard CodeQL Action repository. */
89
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
@@ -17,7 +18,7 @@ export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
1718
*/
1819
export function getCodeQLActionRepository(
1920
action: ActionState<["ReadOnlyEnv", "Logger"]>,
20-
): string {
21+
): RepositoryNwoStr {
2122
if (isRunningLocalAction(action.env)) {
2223
// This handles the case where the Action does not come from an Action repository,
2324
// e.g. our integration tests which use the Action code from the current checkout.
@@ -28,11 +29,21 @@ export function getCodeQLActionRepository(
2829
return CODEQL_DEFAULT_ACTION_REPOSITORY;
2930
}
3031

31-
return action.env.getRequired(ActionsEnvVars.GITHUB_ACTION_REPOSITORY);
32+
const actionRepository = action.env.getRequired(
33+
ActionsEnvVars.GITHUB_ACTION_REPOSITORY,
34+
);
35+
36+
if (isRepositoryNwoStr(actionRepository)) {
37+
return actionRepository;
38+
}
39+
40+
throw new Error(
41+
`The value of '${ActionsEnvVars.GITHUB_ACTION_REPOSITORY}' is '${actionRepository}', which does not match the expected 'owner/repo' format.`,
42+
);
3243
}
3344

3445
/**A download source is a pair of strings. */
35-
export type DownloadSource = [string, string];
46+
export type DownloadSource = [string, RepositoryNwoStr];
3647

3748
/** GitHub.com, and the canonical Action. */
3849
export const DEFAULT_DOWNLOAD_SOURCE: DownloadSource = [
@@ -77,7 +88,7 @@ export async function getCodeQLAssetDownloadURL(
7788
): Promise<DownloadURL> {
7889
const codeQLActionRepository = getCodeQLActionRepository(action);
7990

80-
const potentialDownloadSources: Array<[string, string]> = [
91+
const potentialDownloadSources: Array<[string, RepositoryNwoStr]> = [
8192
// This GitHub instance, and this Action.
8293
[apiDetails.url, codeQLActionRepository],
8394
// This GitHub instance, and the canonical Action.

0 commit comments

Comments
 (0)