mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Add and use RepositoryNwoStr type
This commit is contained in:
13
lib/entry-points.js
generated
13
lib/entry-points.js
generated
@@ -170638,6 +170638,9 @@ function getCurrentInstance(env) {
|
||||
}
|
||||
|
||||
// src/repository.ts
|
||||
function isRepositoryNwoStr(val) {
|
||||
return val.includes("/");
|
||||
}
|
||||
function getRepositoryNwo() {
|
||||
return getRepositoryNwoFromEnv("GITHUB_REPOSITORY");
|
||||
}
|
||||
@@ -175719,7 +175722,15 @@ function getCodeQLActionRepository(action) {
|
||||
);
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
return action.env.getRequired("GITHUB_ACTION_REPOSITORY" /* GITHUB_ACTION_REPOSITORY */);
|
||||
const actionRepository = action.env.getRequired(
|
||||
"GITHUB_ACTION_REPOSITORY" /* GITHUB_ACTION_REPOSITORY */
|
||||
);
|
||||
if (isRepositoryNwoStr(actionRepository)) {
|
||||
return actionRepository;
|
||||
}
|
||||
throw new Error(
|
||||
`The value of '${"GITHUB_ACTION_REPOSITORY" /* GITHUB_ACTION_REPOSITORY */}' is '${actionRepository}', which does not match the expected 'owner/repo' format.`
|
||||
);
|
||||
}
|
||||
var DEFAULT_DOWNLOAD_SOURCE = [
|
||||
GITHUB_DOTCOM_URL,
|
||||
|
||||
@@ -6,6 +6,14 @@ export interface RepositoryNwo {
|
||||
repo: string;
|
||||
}
|
||||
|
||||
/** An approximation of what a repository NWO string looks like. */
|
||||
export type RepositoryNwoStr = `${string}/${string}`;
|
||||
|
||||
/** A basic check that `val` looks like a `RepositoryNwoStr`. */
|
||||
export function isRepositoryNwoStr(val: string): val is RepositoryNwoStr {
|
||||
return val.includes("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the repository name with owner from the environment variable
|
||||
* `GITHUB_REPOSITORY`.
|
||||
|
||||
@@ -3,6 +3,7 @@ import { isRunningLocalAction } from "../actions-util";
|
||||
import * as api from "../api-client";
|
||||
import { ActionsEnvVars } from "../environment";
|
||||
import { GITHUB_DOTCOM_URL } from "../github";
|
||||
import { isRepositoryNwoStr, type RepositoryNwoStr } from "../repository";
|
||||
|
||||
/** The NWO of the standard CodeQL Action repository. */
|
||||
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
@@ -17,7 +18,7 @@ export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
*/
|
||||
export function getCodeQLActionRepository(
|
||||
action: ActionState<["ReadOnlyEnv", "Logger"]>,
|
||||
): string {
|
||||
): RepositoryNwoStr {
|
||||
if (isRunningLocalAction(action.env)) {
|
||||
// This handles the case where the Action does not come from an Action repository,
|
||||
// e.g. our integration tests which use the Action code from the current checkout.
|
||||
@@ -28,11 +29,21 @@ export function getCodeQLActionRepository(
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
|
||||
return action.env.getRequired(ActionsEnvVars.GITHUB_ACTION_REPOSITORY);
|
||||
const actionRepository = action.env.getRequired(
|
||||
ActionsEnvVars.GITHUB_ACTION_REPOSITORY,
|
||||
);
|
||||
|
||||
if (isRepositoryNwoStr(actionRepository)) {
|
||||
return actionRepository;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`The value of '${ActionsEnvVars.GITHUB_ACTION_REPOSITORY}' is '${actionRepository}', which does not match the expected 'owner/repo' format.`,
|
||||
);
|
||||
}
|
||||
|
||||
/**A download source is a pair of strings. */
|
||||
export type DownloadSource = [string, string];
|
||||
export type DownloadSource = [string, RepositoryNwoStr];
|
||||
|
||||
/** GitHub.com, and the canonical Action. */
|
||||
export const DEFAULT_DOWNLOAD_SOURCE: DownloadSource = [
|
||||
@@ -77,7 +88,7 @@ export async function getCodeQLAssetDownloadURL(
|
||||
): Promise<DownloadURL> {
|
||||
const codeQLActionRepository = getCodeQLActionRepository(action);
|
||||
|
||||
const potentialDownloadSources: Array<[string, string]> = [
|
||||
const potentialDownloadSources: Array<[string, RepositoryNwoStr]> = [
|
||||
// This GitHub instance, and this Action.
|
||||
[apiDetails.url, codeQLActionRepository],
|
||||
// This GitHub instance, and the canonical Action.
|
||||
|
||||
Reference in New Issue
Block a user