UNPKG

dryrun-ci

Version:

DryRun CI - Local GitLab CI/CD pipeline testing tool with Docker execution, performance monitoring, and security sandboxing

144 lines (143 loc) 8.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHelper = void 0; const chalk_1 = __importDefault(require("chalk")); class ErrorHelper { static formatError(message, context = {}) { let output = ''; output += chalk_1.default.red('❌ ') + chalk_1.default.bold(message) + '\n'; if (context.file) { const location = context.line ? `:${context.line}${context.column ? `:${context.column}` : ''}` : ''; output += chalk_1.default.gray(` in ${context.file}${location}`) + '\n'; } if (context.suggestion) { output += chalk_1.default.blue('💡 ') + chalk_1.default.cyan('Suggestion: ') + context.suggestion + '\n'; } if (context.moreInfo) { output += chalk_1.default.gray(' ') + context.moreInfo + '\n'; } if (context.relatedFiles && context.relatedFiles.length > 0) { output += chalk_1.default.gray(' Related files: ') + context.relatedFiles.join(', ') + '\n'; } return output; } static formatWarning(message, context = {}) { let output = ''; output += chalk_1.default.yellow('⚠️ ') + chalk_1.default.bold(message) + '\n'; if (context.file) { const location = context.line ? `:${context.line}${context.column ? `:${context.column}` : ''}` : ''; output += chalk_1.default.gray(` in ${context.file}${location}`) + '\n'; } if (context.suggestion) { output += chalk_1.default.blue('💡 ') + chalk_1.default.cyan('Suggestion: ') + context.suggestion + '\n'; } return output; } static formatInfo(message, context = {}) { let output = ''; output += chalk_1.default.blue('ℹ️ ') + chalk_1.default.bold(message) + '\n'; if (context.file) { const location = context.line ? `:${context.line}${context.column ? `:${context.column}` : ''}` : ''; output += chalk_1.default.gray(` in ${context.file}${location}`) + '\n'; } if (context.suggestion) { output += chalk_1.default.blue('💡 ') + chalk_1.default.cyan('Suggestion: ') + context.suggestion + '\n'; } return output; } static formatSuccess(message) { return chalk_1.default.green('✅ ') + chalk_1.default.bold(message) + '\n'; } static formatPipelineError(stage, job, error, context = {}) { let output = ''; output += chalk_1.default.red('❌ Pipeline failed') + '\n'; output += chalk_1.default.gray(` Stage: ${stage}`) + '\n'; output += chalk_1.default.gray(` Job: ${job}`) + '\n'; output += chalk_1.default.gray(` Error: ${error}`) + '\n'; if (context.suggestion) { output += chalk_1.default.blue('💡 ') + chalk_1.default.cyan('How to fix: ') + context.suggestion + '\n'; } output += chalk_1.default.gray('\n To debug locally:') + '\n'; output += chalk_1.default.gray(' 1. Check the configuration in .gitlab-ci.yml') + '\n'; output += chalk_1.default.gray(' 2. Verify all required files are present') + '\n'; output += chalk_1.default.gray(' 3. Test the failing commands manually') + '\n'; output += chalk_1.default.gray(' 4. Run with --verbose for detailed output') + '\n'; return output; } static formatValidationErrors(errors) { let output = ''; output += chalk_1.default.red('❌ Configuration validation failed') + '\n\n'; errors.forEach((error, index) => { output += chalk_1.default.red(`${index + 1}. `) + error.message + '\n'; if (error.file) { const location = error.line ? `:${error.line}${error.column ? `:${error.column}` : ''}` : ''; output += chalk_1.default.gray(` in ${error.file}${location}`) + '\n'; } if (error.suggestion) { output += chalk_1.default.blue(' 💡 ') + error.suggestion + '\n'; } output += '\n'; }); output += chalk_1.default.yellow('Before pushing to GitLab:') + '\n'; output += chalk_1.default.gray('• Fix these issues locally') + '\n'; output += chalk_1.default.gray('• Test again with: dryrun-ci run --dry-run') + '\n'; output += chalk_1.default.gray('• Validate syntax with: dryrun-ci scan') + '\n'; return output; } static formatTroubleshootingTips(issueType) { let output = ''; output += chalk_1.default.blue('🔧 Troubleshooting Tips') + '\n'; switch (issueType) { case 'yaml-syntax': output += chalk_1.default.gray('• YAML syntax errors are common - check indentation') + '\n'; output += chalk_1.default.gray('• Use spaces, not tabs for indentation') + '\n'; output += chalk_1.default.gray('• Validate YAML online: https://www.yamllint.com/') + '\n'; output += chalk_1.default.gray('• Common issue: missing quotes around special characters') + '\n'; break; case 'job-failure': output += chalk_1.default.gray('• Check if all required dependencies are installed') + '\n'; output += chalk_1.default.gray('• Verify file paths and permissions') + '\n'; output += chalk_1.default.gray('• Test commands manually in the same environment') + '\n'; output += chalk_1.default.gray('• Check environment variables and secrets') + '\n'; break; case 'docker-build': output += chalk_1.default.gray('• Check if Docker daemon is running') + '\n'; output += chalk_1.default.gray('• Verify base image exists and is accessible') + '\n'; output += chalk_1.default.gray('• Check Dockerfile syntax and build context') + '\n'; output += chalk_1.default.gray('• Consider using specific image tags instead of latest') + '\n'; break; case 'nixpacks-build': output += chalk_1.default.gray('• Ensure Nixpacks is installed: npm install -g nixpacks') + '\n'; output += chalk_1.default.gray('• Check nixpacks.toml configuration') + '\n'; output += chalk_1.default.gray('• Verify supported language/framework') + '\n'; output += chalk_1.default.gray('• Test build locally: nixpacks build .') + '\n'; break; default: output += chalk_1.default.gray('• Run with --verbose for more detailed output') + '\n'; output += chalk_1.default.gray('• Check GitLab CI/CD documentation') + '\n'; output += chalk_1.default.gray('• Verify all required files are present') + '\n'; output += chalk_1.default.gray('• Test locally before pushing to GitLab') + '\n'; } return output; } static formatPrePushChecklist() { let output = ''; output += chalk_1.default.green('✅ Pre-push Checklist') + '\n'; output += chalk_1.default.gray('Run these commands before pushing to GitLab:') + '\n\n'; output += chalk_1.default.blue('1. ') + chalk_1.default.white('Scan for issues:') + '\n'; output += chalk_1.default.gray(' dryrun-ci scan') + '\n\n'; output += chalk_1.default.blue('2. ') + chalk_1.default.white('Validate configuration:') + '\n'; output += chalk_1.default.gray(' dryrun-ci run --dry-run') + '\n\n'; output += chalk_1.default.blue('3. ') + chalk_1.default.white('Test critical jobs:') + '\n'; output += chalk_1.default.gray(' dryrun-ci run --job build') + '\n'; output += chalk_1.default.gray(' dryrun-ci run --job test') + '\n\n'; output += chalk_1.default.blue('4. ') + chalk_1.default.white('Check for security issues:') + '\n'; output += chalk_1.default.gray(' dryrun-ci scan --security') + '\n\n'; output += chalk_1.default.green('✅ All clear? You\'re ready to push!') + '\n'; return output; } } exports.ErrorHelper = ErrorHelper;