/** * Known git hosting platforms with built-in compare URL support. * * Each platform has a specific URL format for compare links: * - `github`: `{baseUrl}/compare/{fromCommit}...{toCommit}` * - `gitlab`: `{baseUrl}/-/compare/{fromCommit}...{toCommit}` * - `bitbucket`: `{baseUrl}/compare/{toCommit}..{fromCommit}` (reversed order) * - `azure-devops`: `{baseUrl}/compare?version=GT{toCommit}&compareVersion=GT{fromCommit}` */ type KnownPlatform = 'github' | 'gitlab' | 'bitbucket' | 'azure-devops'; /** * Platform identifier. * * - Known platforms have built-in compare URL formatters * - `custom` requires a custom `formatCompareUrl` function * - `unknown` indicates platform could not be determined (no URL generation) */ type RepositoryPlatform = KnownPlatform | 'custom' | 'unknown'; /** * Checks if a platform identifier is a known platform with built-in support. * * @param platform - Platform identifier to check * @returns True if the platform is a known platform * * @example Checking if platform has built-in support * ```typescript * isKnownPlatform('github') // true * isKnownPlatform('gitlab') // true * isKnownPlatform('custom') // false * isKnownPlatform('unknown') // false * ``` */ declare function isKnownPlatform(platform: RepositoryPlatform): platform is KnownPlatform; /** * Known platform hostnames mapped to their platform type. * Used for automatic platform detection from repository URLs. * * Includes both standard SaaS domains and common patterns for self-hosted instances. */ declare const PLATFORM_HOSTNAMES: ReadonlyMap; /** * Detects platform from a hostname. * * First checks for exact match in known platforms, then applies heuristics * for self-hosted instances (e.g., `github.company.com` → `github`). * * @param hostname - Hostname to detect platform from (e.g., "github.com") * @returns Detected platform or 'unknown' if not recognized * * @example Detecting platform from hostname * ```typescript * detectPlatformFromHostname('github.com') // 'github' * detectPlatformFromHostname('gitlab.mycompany.com') // 'gitlab' * detectPlatformFromHostname('custom-git.internal') // 'unknown' * ``` */ declare function detectPlatformFromHostname(hostname: string): RepositoryPlatform; /** * Custom compare URL formatter function. * * @param fromCommit - The source commit hash for comparison (older version) * @param toCommit - The target commit hash for comparison (newer version) * @returns Full compare URL string * * @example * ```typescript * const formatter: CompareUrlFormatter = (from, to) => * `https://my-git.internal/diff/${from}/${to}` * ``` */ type CompareUrlFormatter = (fromCommit: string, toCommit: string) => string; /** * Repository configuration for compare URL generation. * * Supports both standard platforms and self-hosted instances. * When using a known platform, compare URLs are generated automatically. * For custom or unknown platforms, provide a `formatCompareUrl` function. * * @example * ```typescript * // GitHub repository * const github: RepositoryConfig = { * platform: 'github', * baseUrl: 'https://github.com/owner/repo' * } * * // Self-hosted GitLab * const gitlabSelfHosted: RepositoryConfig = { * platform: 'gitlab', * baseUrl: 'https://gitlab.mycompany.com/team/project' * } * * // Custom platform with formatter * const custom: RepositoryConfig = { * platform: 'custom', * baseUrl: 'https://custom-git.internal/repo', * formatCompareUrl: (from, to) => `https://custom-git.internal/diff/${from}/${to}` * } * ``` */ interface RepositoryConfig { /** * Platform type - determines URL format for known platforms. */ readonly platform: RepositoryPlatform; /** * Base URL for the repository. * * This is the URL without any trailing slashes or paths like `/compare`. * * @example * - GitHub: `"https://github.com/owner/repo"` * - GitLab: `"https://gitlab.com/group/project"` * - Azure DevOps: `"https://dev.azure.com/org/project/_git/repo"` */ readonly baseUrl: string; /** * Custom compare URL formatter. * * Required when `platform` is `'custom'`. * Optional for known platforms (overrides built-in formatter). * * Receives the from and to tags, returns the full compare URL. */ readonly formatCompareUrl?: CompareUrlFormatter; } /** * Options for creating a repository config. */ interface CreateRepositoryConfigOptions { /** * Platform type - determines URL format for known platforms. */ readonly platform: RepositoryPlatform; /** * Base URL for the repository. * Trailing slashes will be automatically stripped. */ readonly baseUrl: string; /** * Custom compare URL formatter. * Required when platform is 'custom'. */ readonly formatCompareUrl?: CompareUrlFormatter; } /** * Creates a new RepositoryConfig. * * Normalizes the base URL by stripping trailing slashes and validating * that custom platforms have a formatter function. * * @param options - Repository configuration options * @returns A new RepositoryConfig object * @throws {Error} if platform is 'custom' but no formatCompareUrl is provided * * @example Creating repository configurations * ```typescript * // GitHub repository * const config = createRepositoryConfig({ * platform: 'github', * baseUrl: 'https://github.com/owner/repo' * }) * * // Custom platform * const customConfig = createRepositoryConfig({ * platform: 'custom', * baseUrl: 'https://my-git.internal/repo', * formatCompareUrl: (from, to) => `https://my-git.internal/diff/${from}/${to}` * }) * ``` */ declare function createRepositoryConfig(options: CreateRepositoryConfigOptions): RepositoryConfig; /** * Checks if a value is a RepositoryConfig object. * * @param value - Value to check * @returns True if the value is a RepositoryConfig * * @example Type-checking repository config values * ```typescript * const config = { platform: 'github', baseUrl: 'https://...' } * if (isRepositoryConfig(config)) { * // config is typed as RepositoryConfig * } * ``` */ declare function isRepositoryConfig(value: unknown): value is RepositoryConfig; /** * How to resolve repository information for compare URLs. * * - `explicit`: Use only the provided `RepositoryConfig`; error if missing * - `inferred`: Auto-detect from package.json repository field or git remote * - `disabled`: Do not generate compare URLs (default for backward compatibility) */ type RepositoryResolutionMode = 'explicit' | 'inferred' | 'disabled'; /** * Sources for repository inference, in order of preference. * * - `package-json`: Read from `repository` field in package.json * - `git-remote`: Read from `git remote get-url origin` */ type RepositoryInferenceSource = 'package-json' | 'git-remote'; /** * Full repository resolution configuration. * * Provides fine-grained control over repository resolution behavior. * * @example * ```typescript * // Explicit configuration - must provide repository * const explicit: RepositoryResolution = { * mode: 'explicit', * repository: { * platform: 'github', * baseUrl: 'https://github.com/owner/repo' * } * } * * // Auto-detection with custom order * const inferred: RepositoryResolution = { * mode: 'inferred', * inferenceOrder: ['git-remote', 'package-json'] // Try git first * } * * // Disabled * const disabled: RepositoryResolution = { * mode: 'disabled' * } * ``` */ interface RepositoryResolution { /** * Resolution mode. */ readonly mode: RepositoryResolutionMode; /** * Explicit repository config. * * Required when `mode` is `'explicit'`. * Ignored when `mode` is `'inferred'` or `'disabled'`. */ readonly repository?: RepositoryConfig; /** * Inference source order when `mode` is `'inferred'`. * * Sources are tried in order until one succeeds. * Default: `['package-json', 'git-remote']` */ readonly inferenceOrder?: readonly RepositoryInferenceSource[]; } /** * Creates a disabled repository resolution configuration. * * No compare URLs will be generated. * * @returns A RepositoryResolution with mode 'disabled' * * @example Disabling repository resolution * ```typescript * const config = createDisabledResolution() * // { mode: 'disabled' } * ``` */ declare function createDisabledResolution(): RepositoryResolution; /** * Creates an explicit repository resolution configuration. * * @param repository - The repository config to use * @returns A RepositoryResolution with mode 'explicit' * * @example Using an explicit repository configuration * ```typescript * const config = createExplicitResolution({ * platform: 'github', * baseUrl: 'https://github.com/owner/repo' * }) * ``` */ declare function createExplicitResolution(repository: RepositoryConfig): RepositoryResolution; /** * Creates an inferred repository resolution configuration. * * @param inferenceOrder - Order to try inference sources (default: package-json first) * @returns A RepositoryResolution with mode 'inferred' * * @example Configuring inference order * ```typescript * // Default order: package.json → git remote * const config = createInferredResolution() * * // Custom order: git remote → package.json * const customOrder = createInferredResolution(['git-remote', 'package-json']) * ``` */ declare function createInferredResolution(inferenceOrder?: readonly RepositoryInferenceSource[]): RepositoryResolution; /** * Checks if a value is a RepositoryResolution object. * * @param value - Value to check * @returns True if the value is a RepositoryResolution * * @example Type-checking resolution configurations * ```typescript * import { isRepositoryResolution } from '@hyperfrontend/versioning' * * const config = loadConfig() * if (isRepositoryResolution(config.repository)) { * console.log('Repository mode:', config.repository.mode) * } * ``` */ declare function isRepositoryResolution(value: unknown): value is RepositoryResolution; /** * Default inference order when mode is 'inferred'. */ declare const DEFAULT_INFERENCE_ORDER: readonly RepositoryInferenceSource[]; export { DEFAULT_INFERENCE_ORDER, PLATFORM_HOSTNAMES, createDisabledResolution, createExplicitResolution, createInferredResolution, createRepositoryConfig, detectPlatformFromHostname, isKnownPlatform, isRepositoryConfig, isRepositoryResolution }; export type { CompareUrlFormatter, CreateRepositoryConfigOptions, KnownPlatform, RepositoryConfig, RepositoryInferenceSource, RepositoryPlatform, RepositoryResolution, RepositoryResolutionMode };