From 619053142b1005a9615fb124c48225da1616f7ff Mon Sep 17 00:00:00 2001 From: Luis Fernando Pollo <1323478+luispollo@users.noreply.github.com> Date: Wed, 8 Jan 2020 14:48:28 -0800 Subject: [PATCH] Refactor validation to allow different types of triggers --- .../ImportDeliveryConfigStageConfig.tsx | 21 +++++++++++++++++-- .../managed/importDeliveryConfigStage.ts | 13 ++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/scripts/modules/core/src/pipeline/config/stages/managed/ImportDeliveryConfigStageConfig.tsx b/app/scripts/modules/core/src/pipeline/config/stages/managed/ImportDeliveryConfigStageConfig.tsx index d1288a16bf8..07fb12d37a7 100644 --- a/app/scripts/modules/core/src/pipeline/config/stages/managed/ImportDeliveryConfigStageConfig.tsx +++ b/app/scripts/modules/core/src/pipeline/config/stages/managed/ImportDeliveryConfigStageConfig.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { SETTINGS } from 'core/config/settings'; -import { IStageConfigProps, FormikStageConfig } from 'core/pipeline'; -import { FormikFormField, TextInput } from 'core/presentation'; +import { IStageConfigProps, FormikStageConfig, IContextualValidator } from 'core/pipeline'; +import { FormikFormField, FormValidator, TextInput } from 'core/presentation'; import { HelpField } from 'core/help'; +import { IStage } from 'core/domain'; export const ImportDeliveryConfigStageConfig: React.ComponentType = stageConfigProps => ( ); + +export const validate: IContextualValidator = (_stage: IStage, context: any) => { + if (context.pipeline.triggers.length != 1) { + return { + error: + 'This stage requires a trigger that provides information about your source control repo (such ' + + 'as a Git Trigger), to locate your Delivery Config manifest.', + }; + } + const formValidator = new FormValidator(context.pipeline.triggers[0]); + formValidator.field('source', 'Repo Type').required(); + formValidator.field('project', 'Project').required(); + formValidator.field('slug', 'Repo Name').required(); + formValidator.field('branch', 'Branch').required(); + return formValidator.validateForm(); +}; diff --git a/app/scripts/modules/core/src/pipeline/config/stages/managed/importDeliveryConfigStage.ts b/app/scripts/modules/core/src/pipeline/config/stages/managed/importDeliveryConfigStage.ts index a355fb2c565..72d231ed52a 100644 --- a/app/scripts/modules/core/src/pipeline/config/stages/managed/importDeliveryConfigStage.ts +++ b/app/scripts/modules/core/src/pipeline/config/stages/managed/importDeliveryConfigStage.ts @@ -1,9 +1,8 @@ import { Registry } from 'core/registry'; import { ExecutionDetailsTasks } from 'core/pipeline'; -import { ImportDeliveryConfigStageConfig } from './ImportDeliveryConfigStageConfig'; +import { ImportDeliveryConfigStageConfig, validate } from './ImportDeliveryConfigStageConfig'; import { ImportDeliveryConfigExecutionDetails } from './ImportDeliveryConfigExecutionDetails'; -import { IStageOrTriggerBeforeTypeValidationConfig } from 'core/pipeline/config/validation/stageOrTriggerBeforeType.validator'; import { SETTINGS } from 'core/config'; if (SETTINGS.feature.managedDelivery) { @@ -17,14 +16,6 @@ if (SETTINGS.feature.managedDelivery) { restartable: false, component: ImportDeliveryConfigStageConfig, executionDetailsSections: [ImportDeliveryConfigExecutionDetails, ExecutionDetailsTasks], - //validateFn: validate, - validators: [ - { - type: 'stageOrTriggerBeforeType', - // FIXME: this needs to be generalized so that it accepts a rocket trigger in the netflix deployment - stageType: 'git', - message: 'This stage requires a git trigger to locate your Delivery Config manifest.', - } as IStageOrTriggerBeforeTypeValidationConfig, - ], + validateFn: validate, }); }