From 8553b1ed7602c6796fe5d9afeb50507f9892ca63 Mon Sep 17 00:00:00 2001 From: spinnakerbot Date: Mon, 15 Jul 2019 14:29:59 -0400 Subject: [PATCH] fix(core): Render template triggers, notif, params for manual execution (#7223) (#7224) https://github.com/spinnaker/spinnaker/issues/4565 --- .../manualPipelineExecution.controller.js | 75 ++++++++++++------- ...manualPipelineExecution.controller.spec.js | 7 ++ .../manualPipelineExecution.html | 35 +++++---- 3 files changed, 75 insertions(+), 42 deletions(-) diff --git a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.js b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.js index 3088dcb521f..3cf6ee4ac65 100644 --- a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.js +++ b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.js @@ -30,7 +30,8 @@ module.exports = angular 'pipeline', 'application', 'trigger', - function($scope, $uibModalInstance, pipeline, application, trigger) { + '$q', + function($scope, $uibModalInstance, pipeline, application, trigger, $q) { let applicationNotifications = []; let pipelineNotifications = []; @@ -136,21 +137,39 @@ module.exports = angular } }; - const updatePipelinePlan = pipeline => { - 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 getPlannedPipeline = pipeline => + $q(resolve => { + const isV1PipelineMissingStages = + pipeline.type === 'templatedPipeline' && (pipeline.stages === undefined || pipeline.stages.length === 0); + const isV2Pipeline = PipelineTemplateV2Service.isV2PipelineConfig(pipeline); + + if (isV1PipelineMissingStages || isV2Pipeline) { + PipelineTemplateReader.getPipelinePlan(pipeline) + .then(plan => { + updateStageComponents(plan.stages); + resolve(isV2Pipeline ? plan : pipeline); + }) + .catch(() => { + if (isV2Pipeline) { + this.planError = true; + } + updateStageComponents(pipeline.stages); + resolve(pipeline); + }); + } else { + updateStageComponents(pipeline.stages); + resolve(pipeline); + } + }); const getManualExecutionComponents = stages => { const additionalComponents = stages.map(stage => Registry.pipeline.getManualExecutionComponentForStage(stage)); return _.uniq(_.compact(additionalComponents)); }; + const updateStageComponents = pipelineStages => + (this.stageComponents = getManualExecutionComponents(pipelineStages)); + /** * Controller API */ @@ -172,26 +191,26 @@ module.exports = angular }; this.pipelineSelected = () => { - const pipeline = this.command.pipeline, - executions = application.executions.data || []; + getPlannedPipeline(this.command.pipeline).then(pipeline => { + this.command.pipeline = pipeline; + const executions = application.executions.data || []; - pipelineNotifications = pipeline.notifications || []; - synchronizeNotifications(); + pipelineNotifications = pipeline.notifications || []; + synchronizeNotifications(); - this.currentlyRunningExecutions = executions.filter( - execution => execution.pipelineConfigId === pipeline.id && execution.isActive, - ); - addTriggers(); - this.triggerUpdated(); - - updatePipelinePlan(pipeline); - - if (pipeline.parameterConfig && pipeline.parameterConfig.length) { - this.parameters = {}; - this.hasRequiredParameters = pipeline.parameterConfig.some(p => p.required); - pipeline.parameterConfig.forEach(p => this.addParameter(p)); - this.updateParameters(); - } + this.currentlyRunningExecutions = executions.filter( + execution => execution.pipelineConfigId === pipeline.id && execution.isActive, + ); + addTriggers(); + this.triggerUpdated(); + + if (pipeline.parameterConfig && pipeline.parameterConfig.length) { + this.parameters = {}; + this.hasRequiredParameters = pipeline.parameterConfig.some(p => p.required); + pipeline.parameterConfig.forEach(p => this.addParameter(p)); + this.updateParameters(); + } + }); }; this.addParameter = parameterConfig => { diff --git a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.spec.js b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.spec.js index d51866881c5..28f9d205f9e 100644 --- a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.spec.js +++ b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.controller.spec.js @@ -51,7 +51,9 @@ describe('Controller: ManualPipelineExecution', function() { }, }; + spyOn(AppNotificationsService, 'getNotificationsForApplication').and.returnValue(this.$q.when({})); this.initializeController(application, application.pipelineConfigs.data[0]); + this.scope.$digest(); expect(this.ctrl.currentlyRunningExecutions).toEqual([application.executions.data[1]]); }); @@ -75,7 +77,9 @@ describe('Controller: ManualPipelineExecution', function() { executions: { data: [] }, }; + spyOn(AppNotificationsService, 'getNotificationsForApplication').and.returnValue(this.$q.when({})); this.initializeController(application, application.pipelineConfigs.data[0]); + this.scope.$digest(); expect(this.ctrl.parameters).toEqual({ foo: undefined, bar: 'mr. peanutbutter', baz: '', bojack: null }); }); }); @@ -153,6 +157,7 @@ describe('Controller: ManualPipelineExecution', function() { expect(this.ctrl.notifications).toEqual([notifications[1], notifications[0]]); this.ctrl.command.pipeline = application.pipelineConfigs.data[1]; this.ctrl.pipelineSelected(); + this.scope.$digest(); expect(this.ctrl.notifications).toEqual([notifications[1], notifications[2]]); }); }); @@ -209,7 +214,9 @@ describe('Controller: ManualPipelineExecution', function() { executions: { data: [] }, }; + spyOn(AppNotificationsService, 'getNotificationsForApplication').and.returnValue(this.$q.when({})); this.initializeController(application, application.pipelineConfigs.data[0], this.modalInstance); + this.scope.$digest(); this.ctrl.execute(); expect(this.command.trigger.parameters).toEqual({ bar: 'mr. peanutbutter' }); }); diff --git a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.html b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.html index 5292d8c58b9..b1769bf72ba 100644 --- a/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.html +++ b/app/scripts/modules/core/src/pipeline/manualExecution/manualPipelineExecution.html @@ -7,7 +7,10 @@

Confirm Execution

Select Pipeline

-