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

Commit bffdf30

Browse files
[HOUSEKEEPING] simplify inheriting opt values from config.yaml for svc pipeline cmd (#508)
Co-authored-by: Yvonne Radsmikham <[email protected]>
1 parent 933746d commit bffdf30

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

docs/commands/data.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,16 @@
653653
{
654654
"arg": "-a, --personal-access-token <personal-access-token>",
655655
"description": "Personal Access Token",
656-
"defaultValue": ""
656+
"defaultValue": "",
657+
"inherit": "azure_devops.access_token",
658+
"required": true
657659
},
658660
{
659661
"arg": "-o, --org-name <organization-name>",
660662
"description": "Organization Name for Azure DevOps",
661-
"defaultValue": ""
663+
"defaultValue": "",
664+
"inherit": "azure_devops.org",
665+
"required": true
662666
},
663667
{
664668
"arg": "-u, --repo-url <repo-url>",
@@ -668,7 +672,9 @@
668672
{
669673
"arg": "-d, --devops-project <devops-project>",
670674
"description": "Azure DevOps Project",
671-
"defaultValue": ""
675+
"defaultValue": "",
676+
"inherit": "azure_devops.project",
677+
"required": true
672678
},
673679
{
674680
"arg": "-b, --build-script-url <build-script-url>",

src/commands/service/pipeline.decorator.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
{
1212
"arg": "-a, --personal-access-token <personal-access-token>",
1313
"description": "Personal Access Token",
14-
"defaultValue": ""
14+
"defaultValue": "",
15+
"inherit": "azure_devops.access_token",
16+
"required": true
1517
},
1618
{
1719
"arg": "-o, --org-name <organization-name>",
1820
"description": "Organization Name for Azure DevOps",
19-
"defaultValue": ""
21+
"defaultValue": "",
22+
"inherit": "azure_devops.org",
23+
"required": true
2024
},
2125
{
2226
"arg": "-u, --repo-url <repo-url>",
@@ -26,7 +30,9 @@
2630
{
2731
"arg": "-d, --devops-project <devops-project>",
2832
"description": "Azure DevOps Project",
29-
"defaultValue": ""
33+
"defaultValue": "",
34+
"inherit": "azure_devops.project",
35+
"required": true
3036
},
3137
{
3238
"arg": "-b, --build-script-url <build-script-url>",

src/commands/service/pipeline.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import commander from "commander";
77
import path from "path";
88
import { Config } from "../../config";
99
import { validateRepository } from "../../lib/git/azure";
10-
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
10+
import {
11+
build as buildCmd,
12+
exit as exitCmd,
13+
populateInheritValueFromConfig,
14+
validateForRequiredValues,
15+
} from "../../lib/commandBuilder";
1116
import {
1217
BUILD_SCRIPT_URL,
1318
SERVICE_PIPELINE_FILENAME,
@@ -28,12 +33,12 @@ import {
2833
} from "../../lib/pipelines/pipelines";
2934
import { logger } from "../../logger";
3035
import decorator from "./pipeline.decorator.json";
36+
import { build as buildError } from "../../lib/errorBuilder";
37+
import { errorStatusCode } from "../../lib/errorStatusCode";
3138
import {
3239
validateOrgNameThrowable,
3340
validateProjectNameThrowable,
3441
} from "../../lib/validator";
35-
import { build as buildError } from "../../lib/errorBuilder";
36-
import { errorStatusCode } from "../../lib/errorStatusCode";
3742

3843
export interface CommandOptions {
3944
orgName: string;
@@ -51,22 +56,19 @@ export const fetchValues = async (
5156
serviceName: string,
5257
opts: CommandOptions
5358
): Promise<CommandOptions> => {
54-
const { azure_devops } = Config();
5559
const gitOriginUrl = await getOriginUrl();
5660
const repoUrl = validateRepoUrl(opts, gitOriginUrl);
5761

58-
opts.orgName = opts.orgName || azure_devops?.org || "";
59-
opts.personalAccessToken =
60-
opts.personalAccessToken || azure_devops?.access_token || "";
61-
opts.devopsProject = opts.devopsProject || azure_devops?.project || "";
62+
populateInheritValueFromConfig(decorator, Config(), opts);
63+
validateForRequiredValues(decorator, opts, true);
64+
6265
opts.pipelineName = opts.pipelineName || serviceName + "-pipeline";
6366
opts.repoName = getRepositoryName(repoUrl);
6467
opts.repoUrl = opts.repoUrl || getRepositoryUrl(gitOriginUrl);
6568
opts.buildScriptUrl = opts.buildScriptUrl || BUILD_SCRIPT_URL;
6669

6770
validateOrgNameThrowable(opts.orgName);
6871
validateProjectNameThrowable(opts.devopsProject);
69-
7072
return opts;
7173
};
7274

@@ -168,13 +170,15 @@ export const execute = async (
168170
try {
169171
const gitOriginUrl = await getOriginUrl();
170172
const repoUrl = validateRepoUrl(opts, gitOriginUrl);
171-
const gitUrlType = await isGitHubUrl(repoUrl);
173+
const gitUrlType = isGitHubUrl(repoUrl);
174+
172175
if (gitUrlType) {
173176
throw buildError(errorStatusCode.VALIDATION_ERR, {
174177
errorKey: "project-pipeline-err-github-repo",
175178
values: [repoUrl],
176179
});
177180
}
181+
178182
await fetchValues(serviceName, opts);
179183
const accessOpts: AzureDevOpsOpts = {
180184
orgName: opts.orgName,

0 commit comments

Comments
 (0)