Skip to content

Commit

Permalink
Take 2: Planning a new execution instead of using a previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
jervi committed Oct 25, 2018
1 parent 2fee498 commit 075dcb0
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AuthenticationService } from 'core/authentication';
import { Registry } from 'core/registry';
import { SETTINGS } from 'core/config/settings';
import { AppNotificationsService } from 'core/notification/AppNotificationsService';
import { PipelineTemplateReader } from 'core/pipeline/config/templates/PipelineTemplateReader';

import { STAGE_MANUAL_COMPONENTS } from './stageManualComponents.component';
import { TRIGGER_TEMPLATE } from './triggerTemplate.component';
Expand Down Expand Up @@ -109,6 +110,21 @@ module.exports = angular
this.command.trigger = suppliedTriggerCanBeInvoked ? trigger : _.head(this.triggers);
};

const updatePipelinePlan = (pipeline, executions) => {
if (pipeline.type === 'templatedPipeline' && (pipeline.stages === undefined || pipeline.stages.length === 0)) {
PipelineTemplateReader.getPipelinePlan(pipeline)
.then(plan => (this.stageComponents = getManualExecutionComponents(plan.stages)))
.catch(() => getManualExecutionComponents(pipeline.stages));
} else {
this.stageComponents = getManualExecutionComponents(pipeline.stages);
}
};

const getManualExecutionComponents = stages => {
const additionalComponents = stages.map(stage => Registry.pipeline.getManualExecutionComponentForStage(stage));
return _.uniq(_.compact(additionalComponents));
};

/**
* Controller API
*/
Expand All @@ -132,17 +148,6 @@ module.exports = angular
const pipeline = this.command.pipeline,
executions = application.executions.data || [];

if (
pipeline.type === 'templatedPipeline' &&
executions.length > 0 &&
(pipeline.stages === undefined || pipeline.stages.length === 0)
) {
const previousSuccessfulExecution = executions.find(e => e.stages.length > 0);
if (previousSuccessfulExecution) {
pipeline.stages = previousSuccessfulExecution.stages;
}
}

pipelineNotifications = pipeline.notifications || [];
synchronizeNotifications();

Expand All @@ -152,10 +157,7 @@ module.exports = angular
addTriggers();
this.triggerUpdated();

const additionalComponents = pipeline.stages.map(stage =>
Registry.pipeline.getManualExecutionComponentForStage(stage),
);
this.stageComponents = _.uniq(_.compact(additionalComponents));
updatePipelinePlan(pipeline, executions);

if (pipeline.parameterConfig && pipeline.parameterConfig.length) {
this.parameters = {};
Expand Down

0 comments on commit 075dcb0

Please sign in to comment.