@spinnaker/core 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spinnaker/core",
3
3
  "license": "Apache-2.0",
4
- "version": "0.15.0",
4
+ "version": "0.15.1",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "scripts": {
@@ -120,5 +120,5 @@
120
120
  "shx": "0.3.3",
121
121
  "typescript": "4.3.5"
122
122
  },
123
- "gitHead": "c4b42b16cee7d8746087e9e1bcc4b00751dd4bc7"
123
+ "gitHead": "187272ef1933753688fb8f7966e250a27104612a"
124
124
  }
@@ -6,7 +6,8 @@ import { StageConfigField } from '../../../..';
6
6
  import { BakeHelmConfigForm } from './BakeHelmConfigForm';
7
7
  import { AccountService } from '../../../../../account';
8
8
  import { ApplicationModelBuilder } from '../../../../../application';
9
- import type { IStage } from '../../../../../domain';
9
+ import { ExpectedArtifactService } from '../../../../../artifact';
10
+ import type { IExpectedArtifact, IStage } from '../../../../../domain';
10
11
  import { SpinFormik } from '../../../../../presentation';
11
12
  import { REACT_MODULE } from '../../../../../reactShims';
12
13
 
@@ -84,4 +85,48 @@ describe('<BakeHelmConfigForm />', () => {
84
85
 
85
86
  expect(component.find(StageConfigField).findWhere((x) => x.text() === helmChartFilePathFieldName).length).toBe(0);
86
87
  });
88
+
89
+ it('render the helm chart file path if the id of the git artifact is given but the account value does not exist', async () => {
90
+ const expectedArtifactDisplayName = 'test-artifact';
91
+ const expectedArtifactId = 'test-artifact-id';
92
+ const expectedGitArtifact: IExpectedArtifact = {
93
+ defaultArtifact: {
94
+ customKind: true,
95
+ id: 'defaultArtifact-id',
96
+ },
97
+ displayName: expectedArtifactDisplayName,
98
+ id: expectedArtifactId,
99
+ matchArtifact: {
100
+ artifactAccount: 'gitrepo',
101
+ id: expectedArtifactId,
102
+ reference: 'git repo',
103
+ type: 'git/repo',
104
+ version: 'master',
105
+ },
106
+ useDefaultArtifact: false,
107
+ usePriorArtifact: false,
108
+ };
109
+ const stage = ({
110
+ inputArtifacts: [{ id: expectedArtifactId }],
111
+ } as unknown) as IStage;
112
+
113
+ spyOn(ExpectedArtifactService, 'getExpectedArtifactsAvailableToStage').and.returnValue([expectedGitArtifact]);
114
+
115
+ const props = getProps();
116
+
117
+ const component = mount(
118
+ <SpinFormik
119
+ initialValues={stage}
120
+ onSubmit={() => null}
121
+ validate={() => null}
122
+ render={(formik) => <BakeHelmConfigForm {...props} formik={formik} />}
123
+ />,
124
+ );
125
+
126
+ await new Promise((resolve) => setTimeout(resolve)); // wait one js tick for promise to resolve
127
+ component.setProps({}); // force a re-render
128
+
129
+ expect(component.find('.Select-value-label > span').text().includes(expectedArtifactDisplayName)).toBe(true);
130
+ expect(component.find(StageConfigField).findWhere((x) => x.text() === helmChartFilePathFieldName).length).toBe(1);
131
+ });
87
132
  });
@@ -2,7 +2,12 @@ import React from 'react';
2
2
 
3
3
  import type { IFormikStageConfigInjectedProps } from '../../FormikStageConfig';
4
4
  import { AccountService } from '../../../../../account';
5
- import { ArtifactTypePatterns, excludeAllTypesExcept, StageArtifactSelectorDelegate } from '../../../../../artifact';
5
+ import {
6
+ ArtifactTypePatterns,
7
+ excludeAllTypesExcept,
8
+ ExpectedArtifactService,
9
+ StageArtifactSelectorDelegate,
10
+ } from '../../../../../artifact';
6
11
  import { StageConfigField } from '../../common/stageConfigField/StageConfigField';
7
12
  import type { IArtifact, IExpectedArtifact } from '../../../../../domain';
8
13
  import { MapEditor } from '../../../../../forms';
@@ -41,6 +46,25 @@ export class BakeHelmConfigForm extends React.Component<IFormikStageConfigInject
41
46
  },
42
47
  ]);
43
48
  }
49
+
50
+ // If the Expected Artifact id is provided but the account is not, then attempt to find the artifact from
51
+ // upstream stages and set the account value.
52
+ // This is needed because helm chart file path field will need to be rendered if the artifact has a git repo account type
53
+ const expectedArtifact = this.getInputArtifact(stage, 0);
54
+ if (expectedArtifact.id && !expectedArtifact.account) {
55
+ const availableArtifacts = ExpectedArtifactService.getExpectedArtifactsAvailableToStage(
56
+ stage,
57
+ this.props.pipeline,
58
+ );
59
+ const expectedMatchedArtifact = availableArtifacts.find((a) => a.id === expectedArtifact.id);
60
+ if (expectedMatchedArtifact && expectedMatchedArtifact.matchArtifact) {
61
+ this.props.formik.setFieldValue(
62
+ `inputArtifacts[0].account`,
63
+ expectedMatchedArtifact.matchArtifact.artifactAccount,
64
+ );
65
+ }
66
+ }
67
+
44
68
  AccountService.getArtifactAccounts().then((artifactAccounts) => {
45
69
  this.setState({
46
70
  gitRepoArtifactAccountNames: artifactAccounts
@@ -56,9 +80,16 @@ export class BakeHelmConfigForm extends React.Component<IFormikStageConfigInject
56
80
  this.props.formik.setFieldValue(`inputArtifacts[${index}].account`, artifact.artifactAccount);
57
81
  };
58
82
 
59
- private onTemplateArtifactSelected = (id: string, index: number) => {
60
- this.props.formik.setFieldValue(`inputArtifacts[${index}].id`, id);
83
+ private onTemplateArtifactSelected = (artifact: IExpectedArtifact, index: number) => {
84
+ this.props.formik.setFieldValue(`inputArtifacts[${index}].id`, artifact.id);
61
85
  this.props.formik.setFieldValue(`inputArtifacts[${index}].artifact`, null);
86
+ // Set the account to matchArtifact.artifactAccount if it exists.
87
+ // This account value will be used to determine if the Helm Chart File Path should be displayed.
88
+ if (artifact.matchArtifact) {
89
+ this.props.formik.setFieldValue(`inputArtifacts[${index}].account`, artifact.matchArtifact.artifactAccount);
90
+ } else {
91
+ this.props.formik.setFieldValue(`inputArtifacts[${index}].account`, null);
92
+ }
62
93
  };
63
94
 
64
95
  private addInputArtifact = () => {
@@ -119,7 +150,6 @@ export class BakeHelmConfigForm extends React.Component<IFormikStageConfigInject
119
150
 
120
151
  public render() {
121
152
  const stage = this.props.formik.values;
122
-
123
153
  return (
124
154
  <>
125
155
  <h4>Helm Options</h4>
@@ -150,7 +180,7 @@ export class BakeHelmConfigForm extends React.Component<IFormikStageConfigInject
150
180
  onArtifactEdited={(artifact) => {
151
181
  this.onTemplateArtifactEdited(artifact, 0);
152
182
  }}
153
- onExpectedArtifactSelected={(artifact: IExpectedArtifact) => this.onTemplateArtifactSelected(artifact.id, 0)}
183
+ onExpectedArtifactSelected={(artifact: IExpectedArtifact) => this.onTemplateArtifactSelected(artifact, 0)}
154
184
  pipeline={this.props.pipeline}
155
185
  stage={stage}
156
186
  />
@@ -180,7 +210,7 @@ export class BakeHelmConfigForm extends React.Component<IFormikStageConfigInject
180
210
  this.onTemplateArtifactEdited(artifact, index + 1);
181
211
  }}
182
212
  onExpectedArtifactSelected={(artifact: IExpectedArtifact) =>
183
- this.onTemplateArtifactSelected(artifact.id, index + 1)
213
+ this.onTemplateArtifactSelected(artifact, index + 1)
184
214
  }
185
215
  pipeline={this.props.pipeline}
186
216
  stage={stage}