import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarGitLabCI(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const _linhas = splitLines(src);
    const srcCompleto = src;
    const hardcodedSecrets = (srcCompleto.match(/\b(TOKEN|SECRET|PASSWORD|KEY)\b.*[:=]\s*['"][^'"]+['"]/gi) || []).filter(l => !/\$\{/.test(l)).length;
    if (hardcodedSecrets === 0) {
        score += 25;
        strengths.push('Sem secrets hardcoded');
    }
    else {
        issues.push(`${hardcodedSecrets} secret(s) hardcoded`);
    }
    if (!/image:\s*[^\s@]+:latest\b/.test(srcCompleto)) {
        score += 15;
        strengths.push('Imagens com versão fixa');
    }
    else {
        issues.push('Uso de imagem :latest');
    }
    if (/cache:/.test(srcCompleto)) {
        score += 20;
        strengths.push('Cache configurado');
    }
    else {
        issues.push('Cache não configurado');
    }
    if (/interruptible:/.test(srcCompleto)) {
        score += 10;
        strengths.push('Interruptible configurado');
    }
    else {
        issues.push('Jobs sem interruptible');
    }
    if (/include:/.test(srcCompleto)) {
        score += 10;
        strengths.push('Include templates configurados');
    }
    else {
        issues.push('Includes não utilizados');
    }
    if (/workflow:/.test(srcCompleto)) {
        score += 10;
        strengths.push('Workflow rules configuradas');
    }
    else {
        issues.push('Workflow rules ausentes');
    }
    if (!/\$\{\s*(CI_COMMIT_TITLE|CI_COMMIT_DESCRIPTION|GITLAB_USER_NAME)\s*\}/.test(srcCompleto)) {
        score += 10;
        strengths.push('Sem risco de script injection');
    }
    else {
        issues.push('Risco de script injection detectado');
    }
    return {
        score,
        maxScore,
        percentage: Math.round(score / maxScore * 100),
        issues,
        strengths
    };
}
export const pontuadorGitLabCI = {
    nome: 'pontuador-gitlab-ci',
    categoria: 'workflows',
    descricao: 'Pontua qualidade de GitLab CI',
    pontuar: pontuarGitLabCI
};
//# sourceMappingURL=scorer-gitlab-ci.js.map