validateConfig static method

bool validateConfig(
  1. HooksConfigModel hooksConfig
)

Validates the hook configuration and prints actionable errors. Returns true if validation passes.

Implementation

static bool validateConfig(HooksConfigModel hooksConfig) {
  if (hooksConfig.isEmpty) return true;

  bool valid = true;
  final errors = <String>[];
  final warnings = <String>[];

  for (final entry in hooksConfig.hooks.entries) {
    final name = entry.key;
    final hook = entry.value;

    if (!hook.hasSteps && !hook.hasPipeline) {
      warnings.add(
          'hooks.$name: No steps or run_pipeline. Hook will do nothing.');
    }

    if (hook.hasPipeline && hook.hasSteps) {
      warnings.add(
          'hooks.$name: Both run_pipeline and steps are set. Only run_pipeline will be used.');
    }

    for (int i = 0; i < hook.steps.length; i++) {
      final step = hook.steps[i];
      if (step.command.trim().isEmpty) {
        errors.add(
            'hooks.$name.steps[${i + 1}] "${step.name}": command is empty.');
        valid = false;
      }
      if (step.workingDirectory != null &&
          !Directory(step.workingDirectory!).existsSync()) {
        warnings.add(
            'hooks.$name.steps[${i + 1}] "${step.name}": working_directory "${step.workingDirectory}" does not exist yet.');
      }
    }
  }

  if (errors.isNotEmpty || warnings.isNotEmpty) {
    print('');
    for (final e in errors) {
      print('   ❌ $e');
    }
    for (final w in warnings) {
      print('   ⚠️  $w');
    }
    print('');
  }

  return valid;
}