From 9ef8be7176ff5afdc4c6ac2856a68855b885505b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 23 Jun 2026 16:44:31 +0100 Subject: [PATCH] Refactor `parseRemoteFileAddress` out of `getRemoteConfig` --- lib/entry-points.js | 36 +++++++++++++++++++++--------------- src/config/file.ts | 21 ++++++--------------- src/config/remote-file.ts | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 93b8254ac..792a8cbd8 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -151428,6 +151428,20 @@ function parseUserConfig(logger, pathInput, contents, validateConfig) { } } +// src/config/remote-file.ts +function parseRemoteFileAddress(configFile) { + const format = new RegExp( + "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)" + ); + const pieces = format.exec(configFile); + if (pieces?.groups === void 0 || pieces.length < 5) { + throw new ConfigurationError( + getConfigFileRepoFormatInvalidMessage(configFile) + ); + } + return pieces.groups; +} + // src/config/file.ts function getConfigFileInput(logger, actions, repositoryProperties) { const input = actions.getOptionalInput("config-file"); @@ -151445,20 +151459,12 @@ function getConfigFileInput(logger, actions, repositoryProperties) { return void 0; } async function getRemoteConfig(logger, configFile, apiDetails, validateConfig) { - const format = new RegExp( - "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)" - ); - const pieces = format.exec(configFile); - if (pieces?.groups === void 0 || pieces.length < 5) { - throw new ConfigurationError( - getConfigFileRepoFormatInvalidMessage(configFile) - ); - } + const groups = parseRemoteFileAddress(configFile); const response = await getApiClientWithExternalAuth(apiDetails).rest.repos.getContent({ - owner: pieces.groups.owner, - repo: pieces.groups.repo, - path: pieces.groups.path, - ref: pieces.groups.ref + owner: groups.owner, + repo: groups.repo, + path: groups.path, + ref: groups.ref }); let fileContents; if ("content" in response.data && response.data.content !== void 0) { @@ -160738,7 +160744,7 @@ var import_async = __toESM(require_async(), 1); var import_path6 = require("path"); // node_modules/archiver/lib/error.js -var import_util29 = __toESM(require("util"), 1); +var import_util30 = __toESM(require("util"), 1); var ERROR_CODES = { ABORTED: "archive was aborted", DIRECTORYDIRPATHREQUIRED: "diretory dirpath argument must be a non-empty string value", @@ -160763,7 +160769,7 @@ function ArchiverError(code, data) { this.code = code; this.data = data; } -import_util29.default.inherits(ArchiverError, Error); +import_util30.default.inherits(ArchiverError, Error); // node_modules/archiver/lib/core.js var import_readable_stream2 = __toESM(require_ours(), 1); diff --git a/src/config/file.ts b/src/config/file.ts index 537d42f65..b48a27c5c 100644 --- a/src/config/file.ts +++ b/src/config/file.ts @@ -9,6 +9,7 @@ import { Logger } from "../logging"; import { ConfigurationError } from "../util"; import { parseUserConfig, UserConfig } from "./db-config"; +import { parseRemoteFileAddress } from "./remote-file"; /** * Gets the value that is configured for the configuration file, if any. @@ -44,25 +45,15 @@ export async function getRemoteConfig( apiDetails: api.GitHubApiCombinedDetails, validateConfig: boolean, ): Promise { - // retrieve the various parts of the config location, and ensure they're present - const format = new RegExp( - "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)", - ); - const pieces = format.exec(configFile); - // 5 = 4 groups + the whole expression - if (pieces?.groups === undefined || pieces.length < 5) { - throw new ConfigurationError( - errorMessages.getConfigFileRepoFormatInvalidMessage(configFile), - ); - } + const groups = parseRemoteFileAddress(configFile); const response = await api .getApiClientWithExternalAuth(apiDetails) .rest.repos.getContent({ - owner: pieces.groups.owner, - repo: pieces.groups.repo, - path: pieces.groups.path, - ref: pieces.groups.ref, + owner: groups.owner, + repo: groups.repo, + path: groups.path, + ref: groups.ref, }); let fileContents: string; diff --git a/src/config/remote-file.ts b/src/config/remote-file.ts index cb90b6820..a50e197eb 100644 --- a/src/config/remote-file.ts +++ b/src/config/remote-file.ts @@ -1,3 +1,6 @@ +import * as errorMessages from "../error-messages"; +import { ConfigurationError } from "../util"; + /** Represents remote file addresses. */ export interface RemoteFileAddress { /** The owner of the repository. */ @@ -9,3 +12,27 @@ export interface RemoteFileAddress { /** The ref of the repository. */ ref: string; } + +/** + * Attempts to parse `configFile` into an array of `RemoteFileAddress` components. + * + * @param configFile The string to try and parse. + * @returns The successful result of executing the regex. + * @throws `ConfigurationError` if the format of `configFile` is not valid. + */ +export function parseRemoteFileAddress(configFile: string) { + // retrieve the various parts of the config location, and ensure they're present + const format = new RegExp( + "(?[^/]+)/(?[^/]+)/(?[^@]+)@(?.*)", + ); + const pieces = format.exec(configFile); + + // 5 = 4 groups + the whole expression + if (pieces?.groups === undefined || pieces.length < 5) { + throw new ConfigurationError( + errorMessages.getConfigFileRepoFormatInvalidMessage(configFile), + ); + } + + return pieces.groups; +}