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

Commit e2f6df1

Browse files
Spk setup (#349)
* initial work * disable the spk setup command because it is not ready Co-authored-by: Samiya Akhtar <samiyaakhtar7@gmail.com>
1 parent 1643c91 commit e2f6df1

File tree

11 files changed

+807
-168
lines changed

11 files changed

+807
-168
lines changed

src/commands/init.test.ts

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ import {
1313
execute,
1414
getConfig,
1515
handleInteractiveMode,
16-
ORG_NAME_VIOLATION,
1716
prompt,
18-
validateAccessToken,
19-
validateOrgName,
20-
validatePersonalAccessToken,
21-
validateProjectName
17+
validatePersonalAccessToken
2218
} from "./init";
2319
import * as init from "./init";
2420

@@ -107,72 +103,6 @@ describe("Test execute function", () => {
107103
});
108104
});
109105

110-
describe("test validateOrgName function", () => {
111-
it("empty value and value with space", () => {
112-
expect(validateOrgName("")).toBe("Must enter an organization");
113-
expect(validateOrgName(" ")).toBe("Must enter an organization");
114-
});
115-
it("invalid value", () => {
116-
expect(validateOrgName("-abc")).toBe(ORG_NAME_VIOLATION);
117-
expect(validateOrgName(".abc")).toBe(ORG_NAME_VIOLATION);
118-
expect(validateOrgName("abc.")).toBe(ORG_NAME_VIOLATION);
119-
expect(validateOrgName("a b")).toBe(ORG_NAME_VIOLATION);
120-
});
121-
it("valid value", () => {
122-
expect(validateOrgName("hello")).toBe(true);
123-
expect(validateOrgName("1Microsoft")).toBe(true);
124-
expect(validateOrgName("Microsoft#1")).toBe(true);
125-
});
126-
});
127-
128-
describe("test validateProjectName function", () => {
129-
it("empty value and value with space", () => {
130-
expect(validateProjectName("")).toBe("Must enter a project name");
131-
expect(validateProjectName(" ")).toBe("Must enter a project name");
132-
});
133-
it("space in value", () => {
134-
expect(validateProjectName("a b")).toBe(
135-
"Project name cannot contains spaces"
136-
);
137-
});
138-
it("value over 64 chars long", () => {
139-
expect(validateProjectName("a".repeat(65))).toBe(
140-
"Project name cannot be longer than 64 characters"
141-
);
142-
});
143-
it("invalid value", () => {
144-
expect(validateProjectName("_abc")).toBe(
145-
"Project name cannot begin with an underscore"
146-
);
147-
expect(validateProjectName(".abc")).toBe(
148-
"Project name cannot begin or end with a period"
149-
);
150-
expect(validateProjectName("abc.")).toBe(
151-
"Project name cannot begin or end with a period"
152-
);
153-
expect(validateProjectName(".abc.")).toBe(
154-
"Project name cannot begin or end with a period"
155-
);
156-
expect(validateProjectName("a*b")).toBe(
157-
`Project name can't contain special characters, such as / : \ ~ & % ; @ ' " ? < > | # $ * } { , + = [ ]`
158-
);
159-
});
160-
it("valid value", () => {
161-
expect(validateProjectName("BedrockSPK")).toBe(true);
162-
});
163-
});
164-
165-
describe("test validateAccessToken function", () => {
166-
it("empty value", () => {
167-
expect(validateAccessToken("")).toBe(
168-
"Must enter a personal access token with read/write/manage permissions"
169-
);
170-
});
171-
it("validate value", () => {
172-
expect(validateAccessToken("mysecretshhhh")).toBe(true);
173-
});
174-
});
175-
176106
describe("test getConfig function", () => {
177107
it("with configuration file", () => {
178108
const mockedValues = {

src/commands/init.ts

Lines changed: 6 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
} from "../config";
1212
import { build as buildCmd, exit as exitCmd } from "../lib/commandBuilder";
1313
import { deepClone } from "../lib/util";
14-
import { hasValue } from "../lib/validator";
14+
import {
15+
hasValue,
16+
validateAccessToken,
17+
validateOrgName,
18+
validateProjectName
19+
} from "../lib/validator";
1520
import { logger } from "../logger";
1621
import { IConfigYaml } from "../types";
1722
import decorator from "./init.decorator.json";
@@ -27,9 +32,6 @@ interface IAnswer {
2732
azdo_pat: string;
2833
}
2934

30-
export const ORG_NAME_VIOLATION =
31-
"Organization names must start with a letter or number, followed by letters, numbers or hyphens, and must end with a letter or number.";
32-
3335
/**
3436
* Handles the case where command is loading a file.
3537
*
@@ -41,91 +43,6 @@ export const handleFileConfig = (file: string) => {
4143
logger.info("Successfully initialized the spk tool!");
4244
};
4345

44-
/**
45-
* Returns true if organization name is proper.
46-
*
47-
* @param value Organization Name
48-
*/
49-
export const validateOrgName = (value: string): string | boolean => {
50-
if (!hasValue(value.trim())) {
51-
return "Must enter an organization";
52-
}
53-
const pass = value.match(
54-
/^[0-9a-zA-Z][^\s]*[0-9a-zA-Z]$/ // No Spaces
55-
);
56-
if (pass) {
57-
return true;
58-
}
59-
return ORG_NAME_VIOLATION;
60-
};
61-
62-
/**
63-
* Returns true if project name is proper.
64-
*
65-
* @param value Project Name
66-
*/
67-
export const validateProjectName = (value: string): string | boolean => {
68-
if (!hasValue(value)) {
69-
return "Must enter a project name";
70-
}
71-
if (value.indexOf(" ") !== -1) {
72-
return "Project name cannot contains spaces";
73-
}
74-
if (value.length > 64) {
75-
return "Project name cannot be longer than 64 characters";
76-
}
77-
if (value.startsWith("_")) {
78-
return "Project name cannot begin with an underscore";
79-
}
80-
if (value.startsWith(".") || value.endsWith(".")) {
81-
return "Project name cannot begin or end with a period";
82-
}
83-
84-
const invalidChars = [
85-
"/",
86-
":",
87-
"\\",
88-
"~",
89-
"&",
90-
"%",
91-
";",
92-
"@",
93-
"'",
94-
'"',
95-
"?",
96-
"<",
97-
">",
98-
"|",
99-
"#",
100-
"$",
101-
"*",
102-
"}",
103-
"{",
104-
",",
105-
"+",
106-
"=",
107-
"[",
108-
"]"
109-
];
110-
if (invalidChars.some(x => value.indexOf(x) !== -1)) {
111-
return `Project name can't contain special characters, such as / : \ ~ & % ; @ ' " ? < > | # $ * } { , + = [ ]`;
112-
}
113-
114-
return true;
115-
};
116-
117-
/**
118-
* Returns true if access token is not empty string
119-
*
120-
* @param value Access token
121-
*/
122-
export const validateAccessToken = (value: string): string | boolean => {
123-
if (!hasValue(value)) {
124-
return "Must enter a personal access token with read/write/manage permissions";
125-
}
126-
return true;
127-
};
128-
12946
/**
13047
* Prompts for questions
13148
*

src/commands/setup.decorator.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"command": "setup",
3+
"alias": "s",
4+
"description": "An interactive command to setup resources in azure and azure dev-ops",
5+
"disabled": true,
6+
"options": [
7+
{
8+
"arg": "-f, --file <config-file-path>",
9+
"description": "Path to the file that contains answers to the questions."
10+
}
11+
]
12+
}

src/commands/setup.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Description
2+
3+
This command assists in creating resources in Azure DevOps so that you can get
4+
started with using Bedrock. It creates
5+
6+
1. An Azure DevOps project.
7+
8+
By Default, it runs in an interactive mode where you are prompted for answers
9+
for a few questions
10+
11+
1. Azure DevOps Organization Name
12+
2. Azure DevOps Project Name, the project to be created.
13+
3. Azure DevOps Personal Access Token. The token needs to have these permissions
14+
1. Read and write projects.
15+
16+
It can also run in a non interactive mode by providing a file that contains
17+
answers to the above questions.
18+
19+
```
20+
spk setup --file <file-name>
21+
```
22+
23+
Content of this file is as follow
24+
25+
```
26+
azdo_org_name=<Azure DevOps Organization Name>
27+
azdo_project_name=<Azure DevOps Project Name>
28+
azdo_pat=<Azure DevOps Personal Access Token>
29+
```
30+
31+
azdo_project_name is optional and default value is `BedrockRocks`

0 commit comments

Comments
 (0)