Skip to content

Commit

Permalink
feat(artifacts): find multiple artifacts from single execution (#7139)
Browse files Browse the repository at this point in the history
  • Loading branch information
maggieneterval authored Jun 21, 2019
1 parent 1532db4 commit 45e5aa3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@ import {
} from 'core/pipeline';
import { JsonUtils } from 'core/utils';

export function FindArtifactFromExecutionExecutionDetails(props: IExecutionDetailsSectionProps) {
const { stage } = props;
export class FindArtifactFromExecutionExecutionDetails extends React.Component<IExecutionDetailsSectionProps> {
public static title = 'artifactDetails';
public render() {
const { current, name, stage } = this.props;

return (
<ExecutionDetailsSection name={props.name} current={props.current}>
<div className="row">
<div className="col-md-9">
<dl className="dl-narrow dl-horizontal">
<dt>Match Artifact</dt>
<dd>{JsonUtils.makeSortedStringFromObject(stage.context.expectedArtifact.matchArtifact)}</dd>
{stage.context.expectedArtifact.useDefaultArtifact && <dt>Default Artifact</dt>}
{stage.context.expectedArtifact.useDefaultArtifact && (
<dd>{JsonUtils.makeSortedStringFromObject(stage.context.expectedArtifact.defaultArtifact)}</dd>
)}
</dl>
</div>
</div>

<StageFailureMessage stage={stage} message={stage.outputs.exception} />
<StageExecutionLogs stage={stage} />
</ExecutionDetailsSection>
);
}
// Prior versions of this stage accepted only one expected artifact.
const expectedArtifacts = Array.isArray(stage.context.expectedArtifacts)
? stage.context.expectedArtifacts
: [stage.context.expectedArtifact];

// TODO: refactor this to not use namespace
// eslint-disable-next-line
export namespace FindArtifactFromExecutionExecutionDetails {
export const title = 'findArtifactFromExecutionConfig';
return (
<ExecutionDetailsSection name={name} current={current}>
<div className="row">
{expectedArtifacts.map(expectedArtifact => (
<div key={expectedArtifact.id}>
<h5>{expectedArtifact.displayName}</h5>
<div>Match Artifact</div>
<pre>{JsonUtils.makeSortedStringFromObject(expectedArtifact.matchArtifact)}</pre>
{expectedArtifact.useDefaultArtifact && (
<>
<div>Default Artifact</div>
<pre>{JsonUtils.makeSortedStringFromObject(expectedArtifact.defaultArtifact)}</pre>
</>
)}
</div>
))}
</div>
<StageFailureMessage stage={stage} message={stage.outputs.exception} />
<StageExecutionLogs stage={stage} />
</ExecutionDetailsSection>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Find Artifact From Execution Controller:', function() {

it('properly initializes an empty stage', () => {
initializeController({});
const expectedArtifact = ctrl.stage.expectedArtifact;
const expectedArtifact = ctrl.stage.expectedArtifacts[0];
const executionOptions: any = ctrl.stage.executionOptions;

expect(executionOptions).toBeDefined();
Expand All @@ -41,7 +41,7 @@ describe('Find Artifact From Execution Controller:', function() {
executionOptions: existingExecutionOptions,
});

const expectedArtifact = ctrl.stage.expectedArtifact;
const expectedArtifact = ctrl.stage.expectedArtifacts[0];
const executionOptions: any = ctrl.stage.executionOptions;

expect(executionOptions).toBeDefined();
Expand All @@ -67,7 +67,7 @@ describe('Find Artifact From Execution Controller:', function() {
expectedArtifact: existingExpectedArtifact,
});

const expectedArtifact: any = ctrl.stage.expectedArtifact;
const expectedArtifact: any = ctrl.stage.expectedArtifacts[0];

expect(expectedArtifact).toBeDefined();
expect(expectedArtifact.id).toEqual(existingExpectedArtifact.id);
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Find Artifact From Execution Controller:', function() {
expectedArtifact: existingExpectedArtifact,
});

const expectedArtifact: any = ctrl.stage.expectedArtifact;
const expectedArtifact: any = ctrl.stage.expectedArtifacts[0];

expect(expectedArtifact).toBeDefined();
expect(expectedArtifact.id).toEqual(existingExpectedArtifact.id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { IController, IScope } from 'angular';

import { ApplicationReader } from 'core/application/service/ApplicationReader';
import { PipelineConfigService } from 'core/pipeline/config/services/PipelineConfigService';
import { IExpectedArtifact, IPipeline } from 'core/domain';
import { ExpectedArtifactService } from '@spinnaker/core';
import {
ApplicationReader,
ExpectedArtifactService,
IExpectedArtifact,
IPipeline,
IStage,
PipelineConfigService,
} from '@spinnaker/core';

export interface IFindArtifactFromExecutionStage {
application: string;
Expand All @@ -13,7 +17,8 @@ export interface IFindArtifactFromExecutionStage {
terminal?: boolean;
running?: boolean;
};
expectedArtifact: IExpectedArtifact;
expectedArtifact: IExpectedArtifact; // legacy
expectedArtifacts: IExpectedArtifact[];
}

export class FindArtifactFromExecutionCtrl implements IController {
Expand Down Expand Up @@ -41,8 +46,15 @@ export class FindArtifactFromExecutionCtrl implements IController {
// Prior versions of this stage didn't allow a default artifact, so existing
// stages may have a partly-initialized expected artifact. To handle these
// cases, default any fields that are not present in the artifact.
const emptyArtifact = ExpectedArtifactService.createEmptyArtifact();
this.stage.expectedArtifact = { ...emptyArtifact, ...this.stage.expectedArtifact };
const initialArtifact = ExpectedArtifactService.createEmptyArtifact();
if (this.stage.expectedArtifact) {
Object.assign(initialArtifact, this.stage.expectedArtifact);
}

// Prior versions of this stage accepted only one expected artifact.
if (!Array.isArray(this.stage.expectedArtifacts)) {
this.stage.expectedArtifacts = [initialArtifact];
}

this.loadApplications();
this.loadPipelines();
Expand Down Expand Up @@ -72,4 +84,12 @@ export class FindArtifactFromExecutionCtrl implements IController {
public onApplicationSelect() {
this.loadPipelines();
}

public addExpectedArtifact = () => {
ExpectedArtifactService.addNewArtifactTo(this.stage);
};

public removeExpectedArtifact = (stage: IStage, expectedArtifact: IExpectedArtifact) => {
stage.expectedArtifacts = stage.expectedArtifacts.filter((a: IExpectedArtifact) => a.id !== expectedArtifact.id);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ <h4>Execution Options</h4>
<label> <input type="checkbox" ng-model="ctrl.stage.executionOptions.running" /> that are still running </label>
</div>
</div>
<h4>Match Artifact</h4>
<expected-artifact expected-artifact="ctrl.stage.expectedArtifact"></expected-artifact>
<h4>Match Artifacts</h4>
<expected-artifact
ng-repeat="artifact in ctrl.stage.expectedArtifacts"
context="ctrl.stage"
expected-artifact="artifact"
remove-expected-artifact="ctrl.removeExpectedArtifact"
/>
<div class="row">
<div class="col-md-12">
<button class="btn btn-block btn-add-trigger add-new" ng-click="ctrl.addExpectedArtifact()">
<span class="glyphicon glyphicon-plus-sign"></span> Add Artifact
</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module(FIND_ARTIFACT_FROM_EXECUTION_STAGE, [])
.config(() => {
if (SETTINGS.feature.artifacts) {
Registry.pipeline.registerStage({
label: 'Find Artifact From Execution',
description: 'Find and bind an artifact from another execution',
label: 'Find Artifacts From Execution',
description: 'Find and bind artifacts from another execution',
key: 'findArtifactFromExecution',
templateUrl: require('./findArtifactFromExecutionConfig.html'),
controller: 'findArtifactFromExecutionCtrl',
Expand Down

0 comments on commit 45e5aa3

Please sign in to comment.