Skip to content

Commit

Permalink
Refactor validation to allow different types of triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
luispollo committed Jan 9, 2020
1 parent a921c52 commit 6190531
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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<IStageConfigProps> = stageConfigProps => (
<FormikStageConfig
Expand All @@ -27,3 +28,19 @@ export const ImportDeliveryConfigStageConfig: React.ComponentType<IStageConfigPr
)}
/>
);

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();
};
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
});
}

0 comments on commit 6190531

Please sign in to comment.