import { execSync } from 'node:child_process';
export class GithubCiCdAdapter {
    logger;
    constructor(logger) {
        this.logger = logger;
    }
    async setSecrets(params) {
        const spinner = this.logger.step('Configurando GitHub secrets...');
        for (const [name, value] of Object.entries(params.secrets)) {
            this.gh(`secret set ${name} --repo ${params.repo} --body '${value.replaceAll("'", String.raw `'\''`)}'`);
            this.logger.info(`  Secret: ${name}`);
        }
        spinner.succeed(`${Object.keys(params.secrets).length} secrets configurados en ${params.repo}`);
    }
    async setVariables(params) {
        const spinner = this.logger.step('Configurando GitHub variables...');
        for (const [name, value] of Object.entries(params.variables)) {
            this.gh(`variable set ${name} --repo ${params.repo} --body '${value}'`);
            this.logger.info(`  Variable: ${name}`);
        }
        spinner.succeed(`${Object.keys(params.variables).length} variables configuradas en ${params.repo}`);
    }
    async verifyAuth() {
        try {
            this.gh('auth status');
        }
        catch {
            throw new Error('No estás autenticado en GitHub CLI.\nEjecuta: gh auth login');
        }
    }
    gh(args) {
        try {
            return execSync(`gh ${args}`, { encoding: 'utf8', stdio: 'pipe' }).trim();
        }
        catch (error_) {
            const error = error_;
            throw new Error(`gh CLI error: ${error.stderr || error.message}`);
        }
    }
}
