HookModel.fromYaml constructor

HookModel.fromYaml(
  1. String name,
  2. Map<String, dynamic> yamlMap
)

Implementation

factory HookModel.fromYaml(String name, Map<String, dynamic> yamlMap) {
  final stepsData = yamlMap['steps'];
  final steps = <HookStepModel>[];
  if (stepsData != null && stepsData is List) {
    for (int i = 0; i < stepsData.length; i++) {
      try {
        steps.add(HookStepModel.fromYaml(
            Map<String, dynamic>.from(stepsData[i] as Map)));
      } catch (e) {
        print('⚠️  [hooks.$name] Failed to parse step #${i + 1}: $e');
      }
    }
  }

  final runPipeline = yamlMap['run_pipeline']?.toString().trim();
  final runPipelineNormalized =
      (runPipeline == null || runPipeline.isEmpty) ? null : runPipeline;

  // Validate: must have steps OR run_pipeline
  if (steps.isEmpty && runPipelineNormalized == null) {
    print(
        '⚠️  [hooks.$name] Hook has no steps and no run_pipeline. It will do nothing when triggered.');
  }

  return HookModel(
    name: name,
    enabled: yamlMap['enabled'] == true,
    steps: steps,
    runPipeline: runPipelineNormalized,
    stopOnFailure: yamlMap['stop_on_failure'] ?? true,
    description: yamlMap['description']?.toString(),
  );
}