From 116b08e20f847c7e1b4e1f096f06eb1d84e1299e Mon Sep 17 00:00:00 2001 From: Dennis Seah Date: Fri, 3 Apr 2020 12:18:16 -0700 Subject: [PATCH] [FEATURE] simplify option values inherit from config.yaml for service create rev cmd --- docs/commands/data.json | 6 +++-- .../service/create-revision.decorator.json | 6 +++-- src/commands/service/create-revision.ts | 23 ++++++------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/commands/data.json b/docs/commands/data.json index 1e3c26ee6..128b87660 100644 --- a/docs/commands/data.json +++ b/docs/commands/data.json @@ -536,12 +536,14 @@ { "arg": "-a, --personal-access-token ", "description": "Personal access token associated with your Azure DevOps token; falls back to azure_devops.access_token in your spk config", - "required": true + "required": true, + "inherit": "azure_devops.access_token" }, { "arg": "-o, --org-name ", "description": "Your Azure DevOps organization name; falls back to azure_devops.org in your spk config", - "required": true + "required": true, + "inherit": "azure_devops.org" }, { "arg": "--target-branch", diff --git a/src/commands/service/create-revision.decorator.json b/src/commands/service/create-revision.decorator.json index 6ae321a93..0b7dfa5ea 100644 --- a/src/commands/service/create-revision.decorator.json +++ b/src/commands/service/create-revision.decorator.json @@ -24,12 +24,14 @@ { "arg": "-a, --personal-access-token ", "description": "Personal access token associated with your Azure DevOps token; falls back to azure_devops.access_token in your spk config", - "required": true + "required": true, + "inherit": "azure_devops.access_token" }, { "arg": "-o, --org-name ", "description": "Your Azure DevOps organization name; falls back to azure_devops.org in your spk config", - "required": true + "required": true, + "inherit": "azure_devops.org" }, { "arg": "--target-branch", diff --git a/src/commands/service/create-revision.ts b/src/commands/service/create-revision.ts index 8d3bd361f..53fbf5a4c 100644 --- a/src/commands/service/create-revision.ts +++ b/src/commands/service/create-revision.ts @@ -6,6 +6,7 @@ import { Bedrock, Config } from "../../config"; import { build as buildCmd, exit as exitCmd, + populateInheritValueFromConfig, validateForRequiredValues, } from "../../lib/commandBuilder"; import { createPullRequest } from "../../lib/git/azure"; @@ -121,12 +122,9 @@ export const execute = async ( exitFn: (status: number) => Promise ): Promise => { try { - const { azure_devops } = Config(); - opts.orgName = opts.orgName || azure_devops?.org; - opts.personalAccessToken = - opts.personalAccessToken || azure_devops?.access_token!; opts.description = opts.description || "This is automated PR generated via SPK"; + populateInheritValueFromConfig(decorator, Config(), opts); //////////////////////////////////////////////////////////////////////// // Give defaults @@ -150,19 +148,12 @@ export const execute = async ( // Default the remote to the git origin opts.remoteUrl = await getRemoteUrl(opts.remoteUrl); - const errors = validateForRequiredValues(decorator, { - orgName: opts.orgName, - personalAccessToken: opts.personalAccessToken, - remoteUrl: opts.remoteUrl, - sourceBranch: opts.sourceBranch, - }); - if (errors.length > 0) { - await exitFn(1); - } else { - await makePullRequest(defaultRings, opts); - await exitFn(0); - } + // error will thrown if validation fails. + validateForRequiredValues(decorator, opts, true); + + await makePullRequest(defaultRings, opts); + await exitFn(0); } catch (err) { logger.error(err); await exitFn(1);