Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 31b1ee9

Browse files
[FEATURE] inheritence information in operational doc (#510)
* [FEATURE] inheritence information in operational doc * Update pipeline.ts * Update pipeline.test.ts Co-authored-by: Yvonne Radsmikham <[email protected]>
1 parent bffdf30 commit 31b1ee9

File tree

7 files changed

+48
-50
lines changed

7 files changed

+48
-50
lines changed

docs/commands/data.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,14 @@
461461
{
462462
"arg": "-a, --personal-access-token <personal-access-token>",
463463
"description": "Personal Access Token",
464-
"required": true
464+
"required": true,
465+
"inherit": "azureDevops.access_token"
465466
},
466467
{
467468
"arg": "-o, --org-name <organization-name>",
468469
"description": "Organization Name for Azure DevOps",
469-
"required": true
470+
"required": true,
471+
"inherit": "azureDevops.org"
470472
},
471473
{
472474
"arg": "-u, --repo-url <repo-url>",
@@ -476,7 +478,8 @@
476478
{
477479
"arg": "-d, --devops-project <devops-project>",
478480
"description": "Azure DevOps Project name",
479-
"required": true
481+
"required": true,
482+
"inherit": "azureDevops.project"
480483
},
481484
{
482485
"arg": "-b, --build-script-url <build-script-url>",

src/commands/hld/pipeline.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ const orgNameTest = (hasVal: boolean): void => {
9393
);
9494
} else {
9595
expect(() => populateValues(data)).toThrow(
96-
`The following arguments are required:
97-
-o, --org-name <organization-name>`
96+
`validation-err-missing-vals: These mandatory options were missing:
97+
-o, --org-name <organization-name>. Provide them.`
9898
);
9999
}
100100
};
@@ -119,8 +119,8 @@ const projectNameTest = (hasVal: boolean): void => {
119119
);
120120
} else {
121121
expect(() => populateValues(data)).toThrow(
122-
`The following arguments are required:
123-
-d, --devops-project <devops-project>`
122+
`validation-err-missing-vals: These mandatory options were missing:
123+
-d, --devops-project <devops-project>. Provide them.`
124124
);
125125
}
126126
};

src/commands/project/pipeline.decorator.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
{
1212
"arg": "-a, --personal-access-token <personal-access-token>",
1313
"description": "Personal Access Token",
14-
"required": true
14+
"required": true,
15+
"inherit": "azureDevops.access_token"
1516
},
1617
{
1718
"arg": "-o, --org-name <organization-name>",
1819
"description": "Organization Name for Azure DevOps",
19-
"required": true
20+
"required": true,
21+
"inherit": "azureDevops.org"
2022
},
2123
{
2224
"arg": "-u, --repo-url <repo-url>",
@@ -26,7 +28,8 @@
2628
{
2729
"arg": "-d, --devops-project <devops-project>",
2830
"description": "Azure DevOps Project name",
29-
"required": true
31+
"required": true,
32+
"inherit": "azureDevops.project"
3033
},
3134
{
3235
"arg": "-b, --build-script-url <build-script-url>",

src/commands/project/pipeline.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ describe("test fetchValidateValues function", () => {
9797
fetchValidateValues(mockMissingValues, gitUrl, {
9898
azure_devops: {},
9999
});
100-
}).toThrow(`project-pipeline-err-invalid-options: Invalid option values`);
100+
})
101+
.toThrow(`validation-err-missing-vals: These mandatory options were missing:
102+
-a, --personal-access-token <personal-access-token>
103+
-o, --org-name <organization-name>
104+
-d, --devops-project <devops-project>. Provide them.`);
101105
});
106+
102107
it("SPK Config's azure_devops do not have value and command line does not have values", () => {
103108
expect(() => {
104109
fetchValidateValues(nullValues, gitUrl, {

src/commands/project/pipeline.ts

+21-37
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { fileInfo as bedrockFileInfo } from "../../lib/bedrockYaml";
1010
import {
1111
build as buildCmd,
1212
exit as exitCmd,
13+
populateInheritValueFromConfig,
1314
validateForRequiredValues,
1415
} from "../../lib/commandBuilder";
1516
import {
@@ -97,51 +98,34 @@ export const fetchValidateValues = (
9798
"project-pipeline-err-spk-config-missing"
9899
);
99100
}
100-
const azureDevops = spkConfig?.azure_devops;
101+
101102
const repoUrl = validateRepoUrl(opts, gitOriginUrl);
102-
const values: CommandOptions = {
103-
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
104-
devopsProject: opts.devopsProject || azureDevops?.project,
105-
orgName: opts.orgName || azureDevops?.org,
106-
personalAccessToken: opts.personalAccessToken || azureDevops?.access_token,
107-
pipelineName:
108-
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle",
109-
repoName: getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl),
110-
repoUrl: opts.repoUrl || getRepositoryUrl(gitOriginUrl),
111-
yamlFileBranch: opts.yamlFileBranch,
112-
};
113103

114-
const map: { [key: string]: string | undefined } = {};
115-
(Object.keys(values) as Array<keyof CommandOptions>).forEach((key) => {
116-
const val = values[key];
117-
if (key === "personalAccessToken") {
118-
logger.debug(`${key}: XXXXXXXXXXXXXXXXX`);
119-
} else {
120-
logger.debug(`${key}: ${val}`);
121-
}
122-
map[key] = val;
123-
});
104+
(opts.pipelineName =
105+
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle"),
106+
(opts.repoName =
107+
getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl)),
108+
(opts.repoUrl = opts.repoUrl || getRepositoryUrl(gitOriginUrl));
109+
opts.yamlFileBranch = opts.yamlFileBranch || "master";
110+
opts.buildScriptUrl = opts.buildScriptUrl || BUILD_SCRIPT_URL;
124111

125-
const error = validateForRequiredValues(decorator, map);
126-
if (error.length > 0) {
127-
throw buildError(
128-
errorStatusCode.VALIDATION_ERR,
129-
"project-pipeline-err-invalid-options"
130-
);
131-
}
112+
populateInheritValueFromConfig(decorator, Config(), opts);
113+
114+
// error will be thrown if validation fails
115+
validateForRequiredValues(decorator, opts, true);
132116

133117
// validateForRequiredValues has validated the following
134118
// values are validate, adding || "" is just to
135119
// satisfy the no-non-null-assertion eslint rule
136120
const configVals: ConfigValues = {
137-
orgName: values.orgName || "",
138-
buildScriptUrl: values.buildScriptUrl || BUILD_SCRIPT_URL,
139-
devopsProject: values.devopsProject || "",
140-
repoName: values.repoName,
141-
personalAccessToken: values.personalAccessToken || "",
142-
pipelineName: values.pipelineName || "",
143-
repoUrl: values.repoUrl || "",
144-
yamlFileBranch: values.yamlFileBranch,
121+
orgName: opts.orgName || "",
122+
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
123+
devopsProject: opts.devopsProject || "",
124+
repoName: opts.repoName,
125+
personalAccessToken: opts.personalAccessToken || "",
126+
pipelineName: opts.pipelineName || "",
127+
repoUrl: opts.repoUrl || "",
128+
yamlFileBranch: opts.yamlFileBranch,
145129
};
146130

147131
validateProjectNameThrowable(configVals.devopsProject);

src/lib/commandBuilder.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export const validateForRequiredValues = (
125125
const errors = missingItems.map((item) => item.opt.arg);
126126

127127
if (toThrow && errors.length !== 0) {
128-
throw `The following arguments are required:\n ${errors.join("\n ")}`;
128+
throw buildError(errorStatusCode.VALIDATION_ERR, {
129+
errorKey: "validation-err-missing-vals",
130+
values: [errors.join("\n ")],
131+
});
129132
}
130133

131134
if (errors.length !== 0) {

src/lib/i18n.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"project-pipeline-err-init-dependency": "Please run `spk project init` and `spk project cvg` commands before running this command to initialize the project.",
7070
"project-pipeline-err-cvg": "Please run `spk project cvg` command before running this command to create a variable group.",
7171
"project-pipeline-err-spk-config-missing": "SPK Config is missing",
72-
"project-pipeline-err-invalid-options": "Invalid option values",
7372
"project-pipeline-err-pipeline-create": "Error occurred during pipeline creation for {0}",
7473
"project-pipeline-err-invalid-build-definition": "Invalid BuildDefinition created, parameter 'id' is missing from {0}",
7574

@@ -224,6 +223,7 @@
224223
"variable-group-create-cmd-err-org-missing": "Provide a value for {0}.",
225224
"variable-group-create-cmd-err-file-missing": "Provide a file with the variable group manifest.",
226225

226+
"validation-err-missing-vals": "These mandatory options were missing:\n {0}. Provide them.",
227227
"validation-err-org-name-missing": "Organization name was missing. Provide it.",
228228
"validation-err-org-name": "Organization name must start with a letter or number, followed by letters, numbers or hyphens, and must end with a letter or number.",
229229
"validation-err-password-missing": "Password was missing. Provide it.",

0 commit comments

Comments
 (0)