Skip to content

Commit

Permalink
[FEATURE] simplify option values inherit from config.yaml for service…
Browse files Browse the repository at this point in the history
… create rev cmd (CatalystCode#507)

Co-authored-by: Yvonne Radsmikham <yvonne.radsmikham@gmail.com>
  • Loading branch information
dennisseah and yradsmikham committed Apr 6, 2020
1 parent b5d2773 commit 933746d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
6 changes: 4 additions & 2 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,14 @@
{
"arg": "-a, --personal-access-token <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 <organization-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",
Expand Down
6 changes: 4 additions & 2 deletions src/commands/service/create-revision.decorator.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
{
"arg": "-a, --personal-access-token <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 <organization-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",
Expand Down
16 changes: 3 additions & 13 deletions src/commands/service/create-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bedrock, Config } from "../../config";
import {
build as buildCmd,
exit as exitCmd,
populateInheritValueFromConfig,
validateForRequiredValues,
} from "../../lib/commandBuilder";
import { createPullRequest } from "../../lib/git/azure";
Expand Down Expand Up @@ -125,26 +126,15 @@ export const makePullRequest = async (
};

const populateValues = async (opts: CommandOptions): Promise<CommandValues> => {
const { azure_devops } = Config();
opts.orgName = opts.orgName || azure_devops?.org;
opts.personalAccessToken =
opts.personalAccessToken || azure_devops?.access_token;
populateInheritValueFromConfig(decorator, Config(), opts);

// Default the remote to the git origin
opts.remoteUrl = await getRemoteUrl(opts.remoteUrl);

// default pull request source branch to the current branch
opts.sourceBranch = await getSourceBranch(opts.sourceBranch);

const errors = validateForRequiredValues(decorator, {
orgName: opts.orgName,
personalAccessToken: opts.personalAccessToken,
remoteUrl: opts.remoteUrl,
sourceBranch: opts.sourceBranch,
});
if (errors.length > 0) {
throw Error("missing required values");
}
validateForRequiredValues(decorator, opts, true);

return {
// validateForRequiredValues confirm that sourceBranch has value
Expand Down

0 comments on commit 933746d

Please sign in to comment.