/**
 * GitHub URL Utilities
 *
 * Utilities for converting local file paths to GitHub URLs.
 */
/**
 * Clean a local path for use in GitHub URLs
 * Removes leading ./ and ensures .specweave prefix if needed
 */
function cleanLocalPath(localPath) {
    let cleanPath = localPath.replace(/^\.\//, '');
    if (!cleanPath.startsWith('.specweave')) {
        cleanPath = `.specweave/${cleanPath}`;
    }
    return cleanPath;
}
/**
 * Convert local file path to GitHub URL
 *
 * @param localPath - Local file path (can start with ./ or be absolute)
 * @param options - GitHub repository options
 * @returns Full GitHub URL
 *
 * @example
 * ```typescript
 * toGitHubUrl('.specweave/docs/internal/specs/default/FS-001/FEATURE.md', {
 *   owner: 'anton-abyzov',
 *   repo: 'specweave',
 *   branch: 'develop'
 * });
 * // => 'https://github.com/anton-abyzov/specweave/blob/develop/.specweave/docs/internal/specs/default/FS-001/FEATURE.md'
 * ```
 */
export function toGitHubUrl(localPath, options) {
    const { owner, repo, branch = 'develop' } = options;
    const cleanPath = cleanLocalPath(localPath);
    return `https://github.com/${owner}/${repo}/blob/${branch}/${cleanPath}`;
}
/**
 * Convert local directory path to GitHub tree URL
 *
 * @param localPath - Local directory path
 * @param options - GitHub repository options
 * @returns Full GitHub tree URL
 *
 * @example
 * ```typescript
 * toGitHubTreeUrl('.specweave/increments/0001-feature', {
 *   owner: 'anton-abyzov',
 *   repo: 'specweave',
 *   branch: 'develop'
 * });
 * // => 'https://github.com/anton-abyzov/specweave/tree/develop/.specweave/increments/0001-feature'
 * ```
 */
export function toGitHubTreeUrl(localPath, options) {
    const { owner, repo, branch = 'develop' } = options;
    const cleanPath = cleanLocalPath(localPath);
    return `https://github.com/${owner}/${repo}/tree/${branch}/${cleanPath}`;
}
/**
 * Get GitHub URL options from git remote
 *
 * @returns GitHub URL options or null if not a GitHub repository
 */
export async function getGitHubOptions() {
    try {
        const { execFile } = await import('child_process');
        const { promisify } = await import('util');
        const execFileAsync = promisify(execFile);
        // Get remote URL
        const { stdout } = await execFileAsync('git', ['remote', 'get-url', 'origin']);
        const remoteUrl = stdout.trim();
        // Parse GitHub URL (supports both HTTPS and SSH)
        // HTTPS: https://github.com/owner/repo.git
        // SSH: git@github.com:owner/repo.git
        const match = remoteUrl.match(/github\.com[:/]([^/]+)\/(.+?)(?:\.git)?$/);
        if (!match) {
            return null;
        }
        const [, owner, repo] = match;
        // Get current branch
        const { stdout: branchOutput } = await execFileAsync('git', ['branch', '--show-current']);
        const branch = branchOutput.trim() || 'develop';
        return { owner, repo, branch };
    }
    catch (error) {
        return null;
    }
}
//# sourceMappingURL=github-url.js.map