Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,14 @@
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Personal Access Token",
"required": true
"required": true,
"inherit": "azureDevops.access_token"
},
{
"arg": "-o, --org-name <organization-name>",
"description": "Organization Name for Azure DevOps",
"required": true
"required": true,
"inherit": "azureDevops.org"
},
{
"arg": "-u, --repo-url <repo-url>",
Expand All @@ -476,7 +478,8 @@
{
"arg": "-d, --devops-project <devops-project>",
"description": "Azure DevOps Project name",
"required": true
"required": true,
"inherit": "azureDevops.project"
},
{
"arg": "-b, --build-script-url <build-script-url>",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/hld/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const orgNameTest = (hasVal: boolean): void => {
);
} else {
expect(() => populateValues(data)).toThrow(
`The following arguments are required:
-o, --org-name <organization-name>`
`validation-err-missing-vals: These mandatory options were missing:
-o, --org-name <organization-name>. Provide them.`
);
}
};
Expand All @@ -119,8 +119,8 @@ const projectNameTest = (hasVal: boolean): void => {
);
} else {
expect(() => populateValues(data)).toThrow(
`The following arguments are required:
-d, --devops-project <devops-project>`
`validation-err-missing-vals: These mandatory options were missing:
-d, --devops-project <devops-project>. Provide them.`
);
}
};
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/pipeline.decorator.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Personal Access Token",
"required": true
"required": true,
"inherit": "azureDevops.access_token"
},
{
"arg": "-o, --org-name <organization-name>",
"description": "Organization Name for Azure DevOps",
"required": true
"required": true,
"inherit": "azureDevops.org"
},
{
"arg": "-u, --repo-url <repo-url>",
Expand All @@ -26,7 +28,8 @@
{
"arg": "-d, --devops-project <devops-project>",
"description": "Azure DevOps Project name",
"required": true
"required": true,
"inherit": "azureDevops.project"
},
{
"arg": "-b, --build-script-url <build-script-url>",
Expand Down
7 changes: 6 additions & 1 deletion src/commands/project/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ describe("test fetchValidateValues function", () => {
fetchValidateValues(mockMissingValues, gitUrl, {
azure_devops: {},
});
}).toThrow(`project-pipeline-err-invalid-options: Invalid option values`);
})
.toThrow(`validation-err-missing-vals: These mandatory options were missing:
-a, --personal-access-token <personal-access-token>
-o, --org-name <organization-name>
-d, --devops-project <devops-project>. Provide them.`);
});

it("SPK Config's azure_devops do not have value and command line does not have values", () => {
expect(() => {
fetchValidateValues(nullValues, gitUrl, {
Expand Down
58 changes: 21 additions & 37 deletions src/commands/project/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { fileInfo as bedrockFileInfo } from "../../lib/bedrockYaml";
import {
build as buildCmd,
exit as exitCmd,
populateInheritValueFromConfig,
validateForRequiredValues,
} from "../../lib/commandBuilder";
import {
Expand Down Expand Up @@ -97,51 +98,34 @@ export const fetchValidateValues = (
"project-pipeline-err-spk-config-missing"
);
}
const azureDevops = spkConfig?.azure_devops;

const repoUrl = validateRepoUrl(opts, gitOriginUrl);
const values: CommandOptions = {
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
devopsProject: opts.devopsProject || azureDevops?.project,
orgName: opts.orgName || azureDevops?.org,
personalAccessToken: opts.personalAccessToken || azureDevops?.access_token,
pipelineName:
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle",
repoName: getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl),
repoUrl: opts.repoUrl || getRepositoryUrl(gitOriginUrl),
yamlFileBranch: opts.yamlFileBranch,
};

const map: { [key: string]: string | undefined } = {};
(Object.keys(values) as Array<keyof CommandOptions>).forEach((key) => {
const val = values[key];
if (key === "personalAccessToken") {
logger.debug(`${key}: XXXXXXXXXXXXXXXXX`);
} else {
logger.debug(`${key}: ${val}`);
}
map[key] = val;
});
(opts.pipelineName =
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle"),
(opts.repoName =
getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl)),
(opts.repoUrl = opts.repoUrl || getRepositoryUrl(gitOriginUrl));
opts.yamlFileBranch = opts.yamlFileBranch || "master";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is || "master" needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for defensive programming purposes.

opts.buildScriptUrl = opts.buildScriptUrl || BUILD_SCRIPT_URL;

const error = validateForRequiredValues(decorator, map);
if (error.length > 0) {
throw buildError(
errorStatusCode.VALIDATION_ERR,
"project-pipeline-err-invalid-options"
);
}
populateInheritValueFromConfig(decorator, Config(), opts);

// error will be thrown if validation fails
validateForRequiredValues(decorator, opts, true);

// validateForRequiredValues has validated the following
// values are validate, adding || "" is just to
// satisfy the no-non-null-assertion eslint rule
const configVals: ConfigValues = {
orgName: values.orgName || "",
buildScriptUrl: values.buildScriptUrl || BUILD_SCRIPT_URL,
devopsProject: values.devopsProject || "",
repoName: values.repoName,
personalAccessToken: values.personalAccessToken || "",
pipelineName: values.pipelineName || "",
repoUrl: values.repoUrl || "",
yamlFileBranch: values.yamlFileBranch,
orgName: opts.orgName || "",
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
devopsProject: opts.devopsProject || "",
repoName: opts.repoName,
personalAccessToken: opts.personalAccessToken || "",
pipelineName: opts.pipelineName || "",
repoUrl: opts.repoUrl || "",
yamlFileBranch: opts.yamlFileBranch,
};

validateProjectNameThrowable(configVals.devopsProject);
Expand Down
5 changes: 4 additions & 1 deletion src/lib/commandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export const validateForRequiredValues = (
const errors = missingItems.map((item) => item.opt.arg);

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

if (errors.length !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"project-pipeline-err-init-dependency": "Please run `spk project init` and `spk project cvg` commands before running this command to initialize the project.",
"project-pipeline-err-cvg": "Please run `spk project cvg` command before running this command to create a variable group.",
"project-pipeline-err-spk-config-missing": "SPK Config is missing",
"project-pipeline-err-invalid-options": "Invalid option values",
"project-pipeline-err-pipeline-create": "Error occurred during pipeline creation for {0}",
"project-pipeline-err-invalid-build-definition": "Invalid BuildDefinition created, parameter 'id' is missing from {0}",

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

"validation-err-missing-vals": "These mandatory options were missing:\n {0}. Provide them.",
"validation-err-org-name-missing": "Organization name was missing. Provide it.",
"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.",
"validation-err-password-missing": "Password was missing. Provide it.",
Expand Down