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

Commit 88bdec5

Browse files
Remove --repo-name argument for service pipeline installations (#309)
* removed --repo-name argument * minor edits * updated tests, additional cleanup * updated unit tests * updated test for service pipeline * update tests * updated tests * attempting to resolve project pipeline tests * check and provide error handling for GitHub repos * additional unit tests * Updated integration tests * removed --repo-name argument * minor edits * updated tests, additional cleanup * updated unit tests * updated test for service pipeline * update tests * updated tests * attempting to resolve project pipeline tests * check and provide error handling for GitHub repos * additional unit tests * Updated integration tests * resolve conflict * using url parse to parse url string and check hostname * resolve docs * update tests * revert test.templates.yaml * resolve regex in create-revision.test.ts Co-authored-by: Dennis Seah <[email protected]>
1 parent 97b1028 commit 88bdec5

File tree

15 files changed

+173
-61
lines changed

15 files changed

+173
-61
lines changed

guides/hld-management.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ Options:
105105
-n, --pipeline-name <pipeline-name> Name of the pipeline to be created (default: "")
106106
-p, --personal-access-token <personal-access-token> Personal Access Token (default: "")
107107
-o, --org-name <org-name> Organization Name for Azure DevOps (default: "")
108-
-r, --hld-name <hld-name> HLD Repository Name in Azure DevOps (default: "")
109108
-u, --hld-url <hld-url> HLD Repository URL (default: "")
110109
-m, --manifest-url <manifest-url> Manifest Repository URL (default: "")
111110
-d, --devops-project <devops-project> Azure DevOps Project (default: "")

src/commands/hld/pipeline.decorator.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
"description": "Organization Name for Azure DevOps",
1919
"defaultValue": ""
2020
},
21-
{
22-
"arg": "-r, --hld-name <hld-name>",
23-
"description": "HLD Repository Name in Azure DevOps",
24-
"defaultValue": ""
25-
},
2621
{
2722
"arg": "-u, --hld-url <hld-url>",
2823
"description": "HLD Repository URL",

src/commands/hld/pipeline.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe("test populateValues function", () => {
8989
buildScriptUrl: "",
9090
devopsProject: "",
9191
hldName: "",
92-
hldUrl: "",
93-
manifestUrl: "",
92+
hldUrl: "https://dev.azure.com/mocked/fabrikam/_git/hld",
93+
manifestUrl: "https://dev.azure.com/mocked/fabrikam/_git/materialized",
9494
orgName: "",
9595
personalAccessToken: "",
9696
pipelineName: "",
@@ -117,6 +117,36 @@ describe("test populateValues function", () => {
117117
);
118118
expect(values.yamlFileBranch).toBe("");
119119
});
120+
it("negative tests: github repos not supported", () => {
121+
expect(() =>
122+
populateValues({
123+
buildScriptUrl: "",
124+
devopsProject: "",
125+
hldName: "",
126+
hldUrl: "https://github.com/fabrikam/hld",
127+
manifestUrl: "https://github.com/fabrikam/materialized",
128+
orgName: "",
129+
personalAccessToken: "",
130+
pipelineName: "",
131+
yamlFileBranch: ""
132+
})
133+
).toThrow(`GitHub repos are not supported`);
134+
});
135+
it("negative tests: github repos not supported", () => {
136+
expect(() =>
137+
populateValues({
138+
buildScriptUrl: "",
139+
devopsProject: "",
140+
hldName: "",
141+
hldUrl: "https://github.com/fabrikam/hld",
142+
manifestUrl: "https://github.com/fabrikam/materialized",
143+
orgName: "",
144+
personalAccessToken: "",
145+
pipelineName: "",
146+
yamlFileBranch: ""
147+
})
148+
).toThrow(`GitHub repos are not supported`);
149+
});
120150
});
121151

122152
describe("test execute function", () => {

src/commands/hld/pipeline.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
BUILD_SCRIPT_URL,
1111
RENDER_HLD_PIPELINE_FILENAME
1212
} from "../../lib/constants";
13-
import { getRepositoryName } from "../../lib/gitutils";
13+
import { getRepositoryName, isGitHubUrl } from "../../lib/gitutils";
1414
import {
1515
createPipelineForDefinition,
1616
definitionForAzureRepoPipeline,
@@ -43,14 +43,22 @@ export const populateValues = (opts: ICommandOptions) => {
4343
// exception will be thrown if spk's config.yaml is missing
4444
const { azure_devops } = Config();
4545

46+
if (!opts.hldUrl || !opts.manifestUrl) {
47+
throw Error(`HLD repo url or manifest url not defined.`);
48+
}
49+
const hldGitUrlType = isGitHubUrl(opts.hldUrl);
50+
const manifestGitUrlType = isGitHubUrl(opts.manifestUrl);
51+
if (hldGitUrlType || manifestGitUrlType) {
52+
throw Error(`GitHub repos are not supported`);
53+
}
4654
opts.hldUrl =
4755
opts.hldUrl || emptyStringIfUndefined(azure_devops?.hld_repository);
4856

4957
opts.manifestUrl =
5058
opts.manifestUrl ||
5159
emptyStringIfUndefined(azure_devops?.manifest_repository);
5260

53-
opts.hldName = opts.hldName || getRepositoryName(opts.hldUrl);
61+
opts.hldName = getRepositoryName(opts.hldUrl);
5462

5563
opts.orgName = opts.orgName || emptyStringIfUndefined(azure_devops?.org);
5664

src/commands/project/pipeline.decorator.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
"description": "Organization Name for Azure DevOps",
1919
"required": true
2020
},
21-
{
22-
"arg": "-r, --repo-name <repo-name>",
23-
"description": "Repository Name in Azure DevOps",
24-
"required": true
25-
},
2621
{
2722
"arg": "-u, --repo-url <repo-url>",
2823
"description": "Repository URL",

src/commands/project/pipeline.test.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ afterAll(() => {
2525
disableVerboseLogging();
2626
});
2727

28+
const gitUrl = "https://github.com/CatalystCode/spk.git";
29+
2830
const mockValues: ICommandOptions = {
2931
buildScriptUrl: "buildScriptUrl",
3032
devopsProject: "azDoProject",
@@ -41,13 +43,22 @@ const mockMissingValues: ICommandOptions = {
4143
devopsProject: undefined,
4244
orgName: undefined,
4345
personalAccessToken: undefined,
44-
pipelineName: undefined,
45-
repoName: undefined,
46-
repoUrl: undefined,
46+
pipelineName: "pipelineName",
47+
repoName: "repoName",
48+
repoUrl: "",
4749
yamlFileBranch: ""
4850
};
4951

50-
const gitUrl = "https://github.com/CatalystCode/spk.git";
52+
const nullValues: ICommandOptions = {
53+
buildScriptUrl: undefined,
54+
devopsProject: undefined,
55+
orgName: undefined,
56+
personalAccessToken: undefined,
57+
pipelineName: "pipelineName",
58+
repoName: "repoName",
59+
repoUrl: "https://github.com",
60+
yamlFileBranch: ""
61+
};
5162

5263
describe("test valid function", () => {
5364
it("negative test", async () => {
@@ -71,13 +82,14 @@ describe("test fetchValidateValues function", () => {
7182
}
7283
});
7384
it("SPK Config's azure_devops do not have value", () => {
74-
const values = fetchValidateValues(mockValues, gitUrl, {
75-
azure_devops: {}
76-
});
77-
expect(values).toEqual(mockValues);
85+
expect(() => {
86+
fetchValidateValues(mockMissingValues, gitUrl, {
87+
azure_devops: {}
88+
});
89+
}).toThrow(`Repo url not defined`);
7890
});
7991
it("SPK Config's azure_devops do not have value and command line does not have values", () => {
80-
const values = fetchValidateValues(mockMissingValues, gitUrl, {
92+
const values = fetchValidateValues(nullValues, gitUrl, {
8193
azure_devops: {}
8294
});
8395
expect(values).toBeNull();
@@ -106,6 +118,30 @@ describe("installLifecyclePipeline and execute tests", () => {
106118
expect(exitFn).toBeCalledTimes(1);
107119
expect(exitFn.mock.calls).toEqual([[0]]);
108120
});
121+
it("test execute function: missing repo url and pipeline name", async () => {
122+
const exitFn = jest.fn();
123+
await execute(mockMissingValues, "", exitFn);
124+
expect(exitFn).toBeCalledTimes(1);
125+
expect(exitFn.mock.calls).toEqual([[1]]);
126+
});
127+
it("test execute function: github repos not supported", async () => {
128+
const exitFn = jest.fn();
129+
await execute(nullValues, "", exitFn);
130+
expect(exitFn).toBeCalledTimes(1);
131+
expect(exitFn.mock.calls).toEqual([[1]]);
132+
});
133+
it("test execute function: missing repo url and pipeline name", async () => {
134+
const exitFn = jest.fn();
135+
await execute(mockMissingValues, "", exitFn);
136+
expect(exitFn).toBeCalledTimes(1);
137+
expect(exitFn.mock.calls).toEqual([[1]]);
138+
});
139+
it("test execute function: github repos not supported", async () => {
140+
const exitFn = jest.fn();
141+
await execute(nullValues, "", exitFn);
142+
expect(exitFn).toBeCalledTimes(1);
143+
expect(exitFn.mock.calls).toEqual([[1]]);
144+
});
109145
it("should create a pipeline", async () => {
110146
(createPipelineForDefinition as jest.Mock).mockReturnValue({ id: 10 });
111147
try {

src/commands/project/pipeline.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
import {
2121
getOriginUrl,
2222
getRepositoryName,
23-
getRepositoryUrl
23+
getRepositoryUrl,
24+
isGitHubUrl
2425
} from "../../lib/gitutils";
2526
import {
2627
createPipelineForDefinition,
@@ -36,9 +37,9 @@ export interface ICommandOptions {
3637
orgName: string | undefined;
3738
personalAccessToken: string | undefined;
3839
devopsProject: string | undefined;
39-
pipelineName: string | undefined;
40-
repoName: string | undefined;
41-
repoUrl: string | undefined;
40+
pipelineName: string;
41+
repoName: string;
42+
repoUrl: string;
4243
buildScriptUrl: string | undefined;
4344
yamlFileBranch: string;
4445
}
@@ -70,15 +71,17 @@ export const fetchValidateValues = (
7071
throw new Error("SPK Config is missing");
7172
}
7273
const azure_devops = spkConfig?.azure_devops;
73-
74+
if (!opts.repoUrl) {
75+
throw Error(`Repo url not defined`);
76+
}
7477
const values: ICommandOptions = {
7578
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
7679
devopsProject: opts.devopsProject || azure_devops?.project,
7780
orgName: opts.orgName || azure_devops?.org,
7881
personalAccessToken: opts.personalAccessToken || azure_devops?.access_token,
7982
pipelineName:
8083
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle",
81-
repoName: opts.repoName || getRepositoryName(gitOriginUrl),
84+
repoName: getRepositoryName(gitOriginUrl),
8285
repoUrl: opts.repoUrl || getRepositoryUrl(gitOriginUrl),
8386
yamlFileBranch: opts.yamlFileBranch
8487
};
@@ -110,6 +113,19 @@ export const execute = async (
110113
projectPath: string,
111114
exitFn: (status: number) => Promise<void>
112115
) => {
116+
if (!opts.repoUrl || !opts.pipelineName) {
117+
logger.error(`Values for repo url and/or pipeline name are missing`);
118+
await exitFn(1);
119+
return;
120+
}
121+
const gitUrlType = await isGitHubUrl(opts.repoUrl);
122+
if (gitUrlType) {
123+
logger.error(
124+
`GitHub repos are not supported. Repo url: ${opts.repoUrl} is invalid`
125+
);
126+
await exitFn(1);
127+
return;
128+
}
113129
if (!projectPath) {
114130
logger.error("Project Path is missing");
115131
await exitFn(1);

src/commands/service/create-revision.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe("Create pull request", () => {
250250
describe("test getRemoteUrl function", () => {
251251
it("sanity test: get original url", async done => {
252252
const res = await getRemoteUrl(undefined);
253-
expect(!!res.match(/CatalystCode\/spk/i)).toBe(true);
253+
expect(!!res.match(/(.*?)\/spk/i)).toBe(true);
254254
done();
255255
});
256256
it("sanity test", async done => {

src/commands/service/pipeline.decorator.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
"description": "Organization Name for Azure DevOps",
1919
"defaultValue": ""
2020
},
21-
{
22-
"arg": "-r, --repo-name <repo-name>",
23-
"description": "Repository Name in Azure DevOps",
24-
"defaultValue": ""
25-
},
2621
{
2722
"arg": "-u, --repo-url <repo-url>",
2823
"description": "Repository URL",

src/commands/service/pipeline.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ describe("test execute function", () => {
8484
expect(exitFn).toBeCalledTimes(1);
8585
expect(exitFn.mock.calls).toEqual([[1]]);
8686
});
87+
it("negative test: repo url not defined", async () => {
88+
const exitFn = jest.fn();
89+
const mockedVals = getMockedValues();
90+
mockedVals.repoUrl = "";
91+
await execute("serviceName", mockedVals, exitFn);
92+
expect(exitFn).toBeCalledTimes(1);
93+
});
94+
it("negative test: github repo not supported", async () => {
95+
const exitFn = jest.fn();
96+
const mockedVals = getMockedValues();
97+
mockedVals.repoUrl = "https://github.com/microsoft/bedrock";
98+
await execute("serviceName", mockedVals, exitFn);
99+
expect(exitFn).toBeCalledTimes(1);
100+
});
87101
});
88102

89103
describe("required pipeline variables", () => {

0 commit comments

Comments
 (0)