Skip to content

Commit

Permalink
fix(artifacts): dedupe custom artifact types (#8179)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
maggieneterval and mergify[bot] committed Apr 15, 2020
1 parent a239ff2 commit 59ba88e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
Expand Up @@ -40,16 +40,9 @@ describe('ExpectedArtifactService', () => {
isDefault: true,
},
].map(k => ({ ...baseKindConfig, ...k }));
const customKindConfig = {
...baseKindConfig,
key: 'custom',
customKind: true,
isMatch: true,
isDefault: true,
};

beforeAll(() => {
kindConfigs.forEach(kindConfig => Registry.pipeline.registerArtifactKind(kindConfig));
Registry.pipeline.registerCustomArtifactKind(customKindConfig);
});

it('infers kind from type', () => {
Expand Down Expand Up @@ -77,7 +70,7 @@ describe('ExpectedArtifactService', () => {
type: 'bar-type',
};
const kindConfig = ExpectedArtifactService.getKindConfig(artifact, false);
expect(kindConfig).toEqual(customKindConfig);
expect(kindConfig).toEqual(Registry.pipeline.getCustomArtifactKind());
});

it('returns the custom kind when customKind is true, regardless of type, when isDefault is true', () => {
Expand All @@ -87,23 +80,23 @@ describe('ExpectedArtifactService', () => {
type: 'bar-type',
};
const kindConfig = ExpectedArtifactService.getKindConfig(artifact, true);
expect(kindConfig).toEqual(customKindConfig);
expect(kindConfig).toEqual(Registry.pipeline.getCustomArtifactKind());
});

it('returns the default kind if neither kind nor type are stored on artifact', () => {
const artifact: IArtifact = {
id: 'artifact-id',
};
const kindConfig = ExpectedArtifactService.getKindConfig(artifact, false);
expect(kindConfig).toEqual(customKindConfig);
expect(kindConfig).toEqual(Registry.pipeline.getCustomArtifactKind());
});

it('returns the default kind if neither kind nor type are stored on artifact when isDefault is true', () => {
const artifact: IArtifact = {
id: 'artifact-id',
};
const kindConfig = ExpectedArtifactService.getKindConfig(artifact, true);
expect(kindConfig).toEqual(customKindConfig);
expect(kindConfig).toEqual(Registry.pipeline.getCustomArtifactKind());
});
});
});
Expand Up @@ -30,7 +30,6 @@ export class PipelineRegistry {
private transformers: ITransformer[] = [];
private notificationTypes: INotificationTypeConfig[] = [];
private artifactKinds: IArtifactKindConfig[] = artifactKindConfigs;
private customArtifactKind: IArtifactKindConfig;

constructor() {
this.getStageConfig = memoize(this.getStageConfig.bind(this), (stage: IStage) =>
Expand Down Expand Up @@ -169,11 +168,6 @@ export class PipelineRegistry {
defaults(originalArtifactKind, artifactKindConfig);
}

public registerCustomArtifactKind(artifactKindConfig: IArtifactKindConfig): void {
this.customArtifactKind = artifactKindConfig;
this.registerArtifactKind(artifactKindConfig);
}

public getExecutionTransformers(): ITransformer[] {
return this.transformers;
}
Expand All @@ -199,7 +193,7 @@ export class PipelineRegistry {
}

public getCustomArtifactKind(): IArtifactKindConfig {
return cloneDeep(this.customArtifactKind);
return cloneDeep(this.artifactKinds.find(k => k.key === 'custom'));
}

private getCloudProvidersForStage(
Expand Down
Expand Up @@ -16,7 +16,7 @@ function controllerFn(artifact: IArtifact) {
export const CUSTOM_ARTIFACT = 'spinnaker.core.pipeline.trigger.custom.artifact';
module(CUSTOM_ARTIFACT, [])
.config(() => {
Registry.pipeline.registerCustomArtifactKind({
Registry.pipeline.mergeArtifactKind({
label: 'Custom',
description: 'A custom-defined artifact. (Deprecated)',
key: 'custom',
Expand Down

0 comments on commit 59ba88e

Please sign in to comment.