Refactor parseNewRemoteFileAddress out of parseRemoteFileAddress

This commit is contained in:
Michael B. Gale
2026-07-14 20:41:00 +01:00
parent 3ac40703e2
commit 7ec982acb7
2 changed files with 71 additions and 34 deletions

41
lib/entry-points.js generated
View File

@@ -148296,6 +148296,25 @@ function parseOldRemoteFileAddress(input) {
ref: pieces.groups.ref.trim()
});
}
function parseNewRemoteFileAddress(env, configFile) {
const format = new RegExp(
"^((?<owner>[^:@/]+)/)?(?<repo>[^:@/]+)(@(?<ref>[^:]+))?(:(?<path>.+))?$"
);
const pieces = format.exec(configFile.trim());
const repo = pieces?.groups?.repo?.trim();
if (!pieces?.groups || !repo || repo.length === 0) {
return new Failure(void 0);
}
const owner = pieces.groups.owner?.trim();
const path29 = pieces.groups.path?.trim();
const ref = pieces.groups.ref?.trim();
return new Success({
owner: owner || getDefaultOwner(env),
repo,
path: path29 || DEFAULT_CONFIG_FILE_NAME,
ref: ref || DEFAULT_CONFIG_FILE_REF
});
}
async function parseRemoteFileAddress(actionState, configFile) {
const oldFormatAddressResult = parseOldRemoteFileAddress(configFile);
if (oldFormatAddressResult.isSuccess()) {
@@ -148309,30 +148328,22 @@ async function parseRemoteFileAddress(actionState, configFile) {
getConfigFileRepoOldFormatInvalidMessage(configFile)
);
}
const format = new RegExp(
"^((?<owner>[^:@/]+)/)?(?<repo>[^:@/]+)(@(?<ref>[^:]+))?(:(?<path>.+))?$"
const newFormatAddressResult = parseNewRemoteFileAddress(
actionState.env,
configFile
);
const pieces = format.exec(configFile.trim());
const repo = pieces?.groups?.repo?.trim();
if (!pieces?.groups || !repo || repo.length === 0) {
if (newFormatAddressResult.isFailure()) {
throw new ConfigurationError(
getConfigFileRepoFormatInvalidMessage(configFile)
);
}
const owner = pieces.groups.owner?.trim();
const path29 = pieces.groups.path?.trim();
const ref = pieces.groups.ref?.trim();
if (path29?.startsWith("/")) {
const address = newFormatAddressResult.value;
if (address.path.startsWith("/")) {
throw new ConfigurationError(
`The path component of '${configFile}' cannot be an absolute path.`
);
}
return {
owner: owner || getDefaultOwner(actionState.env),
repo,
path: path29 || DEFAULT_CONFIG_FILE_NAME,
ref: ref || DEFAULT_CONFIG_FILE_REF
};
return address;
}
// src/config/file.ts