import { RepositoryConfig, RepositoryPlatform } from '../models'; /** * Repository field formats from package.json. * * Package.json supports multiple formats for the repository field: * - Shorthand: `"github:owner/repo"` * - URL string: `"https://github.com/owner/repo"` * - Object: `{ "type": "git", "url": "..." }` */ interface PackageJsonRepository { /** * Repository type (typically "git"). */ readonly type?: string; /** * Repository URL. */ readonly url: string; /** * Directory within the repository (for monorepos). */ readonly directory?: string; } /** * Minimal package.json structure for repository inference. */ interface PackageJsonForRepository { /** * Repository field - can be a string or object. */ readonly repository?: string | PackageJsonRepository; } /** * Infers repository configuration from package.json content. * * Handles multiple formats: * - Shorthand: `"github:owner/repo"`, `"gitlab:group/project"`, `"bitbucket:team/repo"` * - Bare shorthand: `"owner/repo"` (defaults to GitHub) * - URL string: `"https://github.com/owner/repo"` * - Object with URL: `{ "type": "git", "url": "https://..." }` * * @param packageJsonContent - Raw JSON string content of package.json * @returns RepositoryConfig or null if repository cannot be inferred * * @example Inferring repository from package.json content * ```typescript * // Shorthand format * inferRepositoryFromPackageJson('{"repository": "github:owner/repo"}') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * // URL string * inferRepositoryFromPackageJson('{"repository": "https://github.com/owner/repo"}') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * // Object format * inferRepositoryFromPackageJson('{"repository": {"type": "git", "url": "https://github.com/owner/repo"}}') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * // Bare shorthand (defaults to GitHub) * inferRepositoryFromPackageJson('{"repository": "owner/repo"}') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * ``` */ declare function inferRepositoryFromPackageJson(packageJsonContent: string): RepositoryConfig | null; /** * Infers repository configuration from a parsed package.json object. * * This is useful when you already have the parsed object. * * @param packageJson - Parsed package.json object * @returns RepositoryConfig or null if repository cannot be inferred * * @example Inferring repository from parsed object * ```typescript * const pkg = { repository: 'github:owner/repo' } * inferRepositoryFromPackageJsonObject(pkg) * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * ``` */ declare function inferRepositoryFromPackageJsonObject(packageJson: PackageJsonForRepository): RepositoryConfig | null; /** * Extracts the repository URL from package.json content. * * Unlike `inferRepositoryFromPackageJson`, this returns just the URL string * without creating a RepositoryConfig. Useful when you need the raw URL. * * @param packageJsonContent - Raw JSON string content of package.json * @returns Repository URL string or null if not found * * @example Extracting raw repository URL * ```typescript * extractRepositoryUrl('{"repository": {"url": "https://github.com/owner/repo"}}') * // → 'https://github.com/owner/repo' * * extractRepositoryUrl('{"repository": "github:owner/repo"}') * // → null (shorthand is not a URL) * ``` */ declare function extractRepositoryUrl(packageJsonContent: string): string | null; /** * Parsed repository information extracted from a git URL. */ interface ParsedRepository { /** * Detected platform type. */ readonly platform: RepositoryPlatform; /** * Base URL for the repository (without trailing slashes or .git suffix). * * @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; } /** * Parses a git URL and extracts platform and base URL. * * Supports multiple URL formats: * - `https://github.com/owner/repo` * - `https://github.com/owner/repo.git` * - `git+https://github.com/owner/repo.git` * - `git://github.com/owner/repo.git` * - `git@github.com:owner/repo.git` (SSH format) * * Handles self-hosted instances by detecting platform from hostname: * - `github.mycompany.com` → `github` * - `gitlab.internal.com` → `gitlab` * * Handles Azure DevOps URL formats: * - `https://dev.azure.com/org/project/_git/repo` * - `https://org.visualstudio.com/project/_git/repo` * * @param gitUrl - Git repository URL in any supported format * @returns Parsed repository info with platform and base URL, or null if parsing fails * * @example Parsing various git URL formats * ```typescript * // GitHub HTTPS * parseRepositoryUrl('https://github.com/owner/repo') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * // SSH format * parseRepositoryUrl('git@github.com:owner/repo.git') * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * // Azure DevOps * parseRepositoryUrl('https://dev.azure.com/org/proj/_git/repo') * // → { platform: 'azure-devops', baseUrl: 'https://dev.azure.com/org/proj/_git/repo' } * * // Self-hosted GitLab * parseRepositoryUrl('https://gitlab.mycompany.com/team/project') * // → { platform: 'gitlab', baseUrl: 'https://gitlab.mycompany.com/team/project' } * ``` */ declare function parseRepositoryUrl(gitUrl: string): ParsedRepository | null; /** * Creates a RepositoryConfig from a git URL. * * This is a convenience function that combines `parseRepositoryUrl` with * `createRepositoryConfig` to produce a ready-to-use configuration. * * @param gitUrl - Git repository URL in any supported format * @returns RepositoryConfig or null if URL cannot be parsed * * @example Creating config from git URLs * ```typescript * const config = createRepositoryConfigFromUrl('https://github.com/owner/repo')) * // → { platform: 'github', baseUrl: 'https://github.com/owner/repo' } * * const config = createRepositoryConfigFromUrl('git@gitlab.com:group/project.git') * // → { platform: 'gitlab', baseUrl: 'https://gitlab.com/group/project' } * ``` */ declare function createRepositoryConfigFromUrl(gitUrl: string): RepositoryConfig | null; export { createRepositoryConfigFromUrl, extractRepositoryUrl, inferRepositoryFromPackageJson, inferRepositoryFromPackageJsonObject, parseRepositoryUrl }; export type { PackageJsonForRepository, PackageJsonRepository, ParsedRepository };