"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidGithubRepositoryCoordinate = isValidGithubRepositoryCoordinate;
exports.isValidGithubRefName = isValidGithubRefName;
exports.isSafeGithubDirectoryPath = isSafeGithubDirectoryPath;
const GITHUB_OWNER_PATTERN = /^(?=.{1,39}$)[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/u;
const GITHUB_REPOSITORY_NAME_PATTERN = /^(?=.{1,100}$)(?!\.{1,2}$)[A-Za-z0-9._-]+$/u;
const GIT_REF_INVALID_CHARACTERS = "~^:?*[\\]";
function isValidGithubRepositoryCoordinate(value) {
    const parts = value.split("/");
    if (parts.length !== 2) {
        return false;
    }
    const [owner, repo] = parts;
    return (owner !== undefined &&
        repo !== undefined &&
        GITHUB_OWNER_PATTERN.test(owner) &&
        GITHUB_REPOSITORY_NAME_PATTERN.test(repo));
}
function isValidGithubRefName(value) {
    if (value === "" ||
        value.trim() !== value ||
        value === "@" ||
        value.startsWith("/") ||
        value.endsWith("/") ||
        value.endsWith(".") ||
        value.includes("//") ||
        value.includes("..") ||
        value.includes("@{") ||
        hasInvalidGitRefCharacter(value)) {
        return false;
    }
    return value
        .split("/")
        .every((segment) => segment !== "" &&
        !segment.startsWith(".") &&
        !segment.endsWith(".lock"));
}
function hasInvalidGitRefCharacter(value) {
    for (const character of value) {
        const code = character.charCodeAt(0);
        if (code <= 32 ||
            code === 127 ||
            GIT_REF_INVALID_CHARACTERS.includes(character)) {
            return true;
        }
    }
    return false;
}
function isSafeGithubDirectoryPath(value) {
    const normalized = value.trim();
    if (normalized === "" ||
        normalized.startsWith("/") ||
        normalized.endsWith("/")) {
        return false;
    }
    return normalized
        .split("/")
        .every((segment) => segment !== "" && segment !== "." && segment !== "..");
}
