-
Notifications
You must be signed in to change notification settings - Fork 231
/
common.ts
74 lines (63 loc) · 2.31 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as vm from "azure-devops-node-api";
import * as lim from "azure-devops-node-api/interfaces/LocationsInterfaces";
function getEnv(name: string): string {
let val = process.env[name];
if (!val) {
console.error(`${name} env var not set`);
process.exit(1);
}
return val;
}
export async function getWebApi(serverUrl?: string): Promise<vm.WebApi> {
serverUrl = serverUrl || getEnv("API_URL");
return await this.getApi(serverUrl);
}
export async function getApi(serverUrl: string): Promise<vm.WebApi> {
return new Promise<vm.WebApi>(async (resolve, reject) => {
try {
let token = getEnv("API_TOKEN");
let authHandler = vm.getPersonalAccessTokenHandler(token);
let option = undefined;
// The following sample is for testing proxy
// option = {
// proxy: {
// proxyUrl: "http://127.0.0.1:8888"
// // proxyUsername: "1",
// // proxyPassword: "1",
// // proxyBypassHosts: [
// // "github\.com"
// // ],
// },
// ignoreSslError: true
// };
// The following sample is for testing cert
// option = {
// cert: {
// caFile: "E:\\certutil\\doctest\\ca2.pem",
// certFile: "E:\\certutil\\doctest\\client-cert2.pem",
// keyFile: "E:\\certutil\\doctest\\client-cert-key2.pem",
// passphrase: "test123",
// },
// };
let vsts: vm.WebApi = new vm.WebApi(serverUrl, authHandler, option);
let connData: lim.ConnectionData = await vsts.connect();
console.log(`Hello ${connData.authenticatedUser.providerDisplayName}`);
resolve(vsts);
}
catch (err) {
reject(err);
}
});
}
export function getProject(): string {
return getEnv("API_PROJECT");
}
export function banner(title: string): void {
console.log("=======================================");
console.log(`\t${title}`);
console.log("=======================================");
}
export function heading(title: string): void {
console.log();
console.log(`> ${title}`);
}