-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdev-data.ts
126 lines (116 loc) · 3.8 KB
/
dev-data.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
73
74
75
76
77
78
79
80
81
82
83
84
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/
import { IssueContext, User, PullRequestContext, Repository, Token } from "@gitpod/gitpod-protocol";
import { GitHubScope } from "../github/scopes";
import { GitLabScope } from "../gitlab/scopes";
export namespace DevData {
export function createTestUser(): User {
return {
id: "somefox",
name: "somefox",
avatarUrl: "https://github.com/typefox.png",
creationDate: new Date().toISOString(),
identities: [
{
authId: "33891423",
authName: "somefox",
authProviderId: "Public-GitHub",
primaryEmail: "[email protected]",
},
{
authId: "3171928",
authName: "somefox",
authProviderId: "Public-GitLab",
primaryEmail: "[email protected]",
},
],
additionalData: {
emailNotificationSettings: {
allowsChangelogMail: true,
allowsDevXMail: true,
},
},
};
}
export function createGitHubTestToken(): Token {
return {
...getTokenFromEnv("GITPOD_TEST_TOKEN_GITHUB"),
scopes: [GitHubScope.EMAIL, GitHubScope.PUBLIC, GitHubScope.PRIVATE],
};
}
export function createDummyHostContextProvider(): any {
return {
get: (hostname: string) => {
const authProviderId = hostname === "github.com" ? "Public-GitHub" : "Public-GitLab";
return {
authProvider: {
authProviderId,
},
};
},
};
}
export function createGitlabTestToken(): Token {
return {
...getTokenFromEnv("GITPOD_TEST_TOKEN_GITLAB"),
scopes: [GitLabScope.READ_USER, GitLabScope.API],
};
}
export function createBitbucketTestToken(): Token {
const result = {
...getTokenFromEnv("GITPOD_TEST_TOKEN_BITBUCKET"),
scopes: [],
};
return result;
}
export function createGiteaTestToken(): Token {
return {
...getTokenFromEnv("GITPOD_TEST_TOKEN_GITEA"),
scopes: [],
};
}
function getTokenFromEnv(varname: string): Token {
const secret = process.env[varname];
if (!secret) {
throw new Error(`${varname} env var is not set`);
}
return JSON.parse(secret);
}
export function createPrContext(user: User): PullRequestContext {
const repository: Repository = {
host: "github.com",
owner: user.identities[0].authName,
name: "gitpod-test-repo",
cloneUrl: "https://github.com/gitpod-io/gitpod-test-repo.git",
};
return <PullRequestContext>{
repository,
title: "Test PR",
nr: 13,
ref: "12test",
revision: "",
base: {
repository,
ref: "1test",
},
};
}
export function createIssueContext(user: User): IssueContext {
const repository: Repository = {
host: "github.com",
owner: user.identities[0].authName,
name: "gitpod-test-repo",
cloneUrl: "https://github.com/gitpod-io/gitpod-test-repo.git",
};
return <IssueContext>{
ref: "GH-15",
repository,
title: "My First Issue",
nr: 15,
revision: "",
};
}
}