Skip to content

Commit 45f13cf

Browse files
easyCZroboquat
authored andcommitted
Format components/server with prettier
1 parent 0bb20d0 commit 45f13cf

File tree

188 files changed

+10516
-7082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+10516
-7082
lines changed

components/server/ee/src/auth/email-domain-service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* See License.enterprise.txt in the project root folder.
55
*/
66

7-
import * as chai from 'chai';
8-
import { suite, test, timeout } from 'mocha-typescript';
9-
import { testContainer as dbTestContainer } from '@gitpod/gitpod-db/lib/test-container';
10-
import { ContainerModule } from 'inversify';
11-
import { EMailDomainService, EMailDomainServiceImpl } from '../auth/email-domain-service';
7+
import * as chai from "chai";
8+
import { suite, test, timeout } from "mocha-typescript";
9+
import { testContainer as dbTestContainer } from "@gitpod/gitpod-db/lib/test-container";
10+
import { ContainerModule } from "inversify";
11+
import { EMailDomainService, EMailDomainServiceImpl } from "../auth/email-domain-service";
1212
const expect = chai.expect;
1313

1414
const testContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
@@ -34,4 +34,4 @@ export class EMailDomainServiceSpec {
3434
}
3535
}
3636

37-
module.exports = new EMailDomainServiceSpec();
37+
module.exports = new EMailDomainServiceSpec();

components/server/ee/src/auth/email-domain-service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import { injectable, inject } from "inversify";
8-
import * as SwotJs from 'swot-js';
8+
import * as SwotJs from "swot-js";
99

1010
import { EmailDomainFilterDB } from "@gitpod/gitpod-db/lib/email-domain-filter-db";
1111
import { EduEmailDomainDB } from "@gitpod/gitpod-db/lib/edu-email-domain-db";
12-
import { BlockedUserFilter } from "../../../src/auth/blocked-user-filter"
12+
import { BlockedUserFilter } from "../../../src/auth/blocked-user-filter";
1313

14-
export const EMailDomainService = Symbol('EMailDomainService');
14+
export const EMailDomainService = Symbol("EMailDomainService");
1515
export interface EMailDomainService extends BlockedUserFilter {
1616
hasEducationalInstitutionSuffix(email: string): Promise<boolean>;
1717
}
@@ -39,27 +39,27 @@ export class EMailDomainServiceImpl implements EMailDomainService {
3939

4040
protected async checkDBForEducationalInstitutionSuffix(domain: string): Promise<boolean> {
4141
const entries = await this.eduDomainDb.readEducationalInstitutionDomains();
42-
const domains = entries.map(entry => entry.domain);
43-
return domains.some(d => domain === d);
42+
const domains = entries.map((entry) => entry.domain);
43+
return domains.some((d) => domain === d);
4444
}
4545

4646
protected async checkSwotJsForEducationalInstitutionSuffix(email: string): Promise<boolean> {
4747
const swotJs = await this.swotJsPromise;
4848
return !!swotJs.check(email);
4949
}
5050

51-
protected parseMail(email: string): { user: string, domain: string } {
52-
const parts = email.split('@');
51+
protected parseMail(email: string): { user: string; domain: string } {
52+
const parts = email.split("@");
5353
if (parts.length !== 2) {
54-
throw new Error('Invalid E-Mail address: ' + email);
54+
throw new Error("Invalid E-Mail address: " + email);
5555
}
5656
return { user: parts[0], domain: parts[1].toLowerCase() };
5757
}
5858

5959
protected initSwotJs(): Promise<any> {
6060
return new Promise((resolve, reject) => {
6161
const swotCallback = () => resolve(result);
62-
const result = new SwotJs(swotCallback)
62+
const result = new SwotJs(swotCallback);
6363
});
6464
}
6565
}

components/server/ee/src/auth/host-container-mapping.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ import { gitHubContainerModuleEE } from "../github/container-module";
1212

1313
@injectable()
1414
export class HostContainerMappingEE extends HostContainerMapping {
15-
1615
public get(type: string): interfaces.ContainerModule[] | undefined {
1716
let modules = super.get(type) || [];
1817

1918
switch (type) {
20-
case "GitLab":
21-
return (modules || []).concat([gitlabContainerModuleEE]);
22-
case "Bitbucket":
23-
return (modules || []).concat([bitbucketContainerModuleEE]);
24-
// case "BitbucketServer":
19+
case "GitLab":
20+
return (modules || []).concat([gitlabContainerModuleEE]);
21+
case "Bitbucket":
22+
return (modules || []).concat([bitbucketContainerModuleEE]);
23+
// case "BitbucketServer":
2524
// FIXME
2625
// return (modules || []).concat([bitbucketContainerModuleEE]);
27-
case "GitHub":
28-
return (modules || []).concat([gitHubContainerModuleEE]);
29-
default:
30-
return modules;
26+
case "GitHub":
27+
return (modules || []).concat([gitHubContainerModuleEE]);
28+
default:
29+
return modules;
3130
}
3231
}
33-
34-
}
32+
}

components/server/ee/src/bitbucket/bitbucket-app-support.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,57 @@ import { URL } from "url";
1212

1313
@injectable()
1414
export class BitbucketAppSupport {
15-
1615
@inject(TokenProvider) protected readonly tokenProvider: TokenProvider;
1716

18-
async getProviderRepositoriesForUser(params: { user: User, provider: AuthProviderInfo }): Promise<ProviderRepository[]> {
17+
async getProviderRepositoriesForUser(params: {
18+
user: User;
19+
provider: AuthProviderInfo;
20+
}): Promise<ProviderRepository[]> {
1921
const token = await this.tokenProvider.getTokenForHost(params.user, params.provider.host);
2022
const oauthToken = token.value;
2123

2224
const api = new Bitbucket({
2325
notice: false,
2426
baseUrl: `https://api.${params.provider.host}/2.0`,
2527
auth: {
26-
token: oauthToken
27-
}
28+
token: oauthToken,
29+
},
2830
});
2931

3032
const result: ProviderRepository[] = [];
3133
const ownersRepos: ProviderRepository[] = [];
3234

33-
const identity = params.user.identities.find(i => i.authProviderId === params.provider.authProviderId);
35+
const identity = params.user.identities.find((i) => i.authProviderId === params.provider.authProviderId);
3436
if (!identity) {
3537
return result;
3638
}
3739
const usersBitbucketAccount = identity.authName;
3840

39-
const workspaces = (await api.workspaces.getWorkspaces({ pagelen: 100 })).data.values?.map(w => w.slug!) || [];
41+
const workspaces =
42+
(await api.workspaces.getWorkspaces({ pagelen: 100 })).data.values?.map((w) => w.slug!) || [];
4043

41-
const reposPromise = Promise.all(workspaces.map(workspace => api.repositories.list({
42-
workspace,
43-
pagelen: 100,
44-
role: "admin" // installation of webhooks is allowed for admins only
45-
}).catch(e => {
46-
console.error(e)
47-
})));
44+
const reposPromise = Promise.all(
45+
workspaces.map((workspace) =>
46+
api.repositories
47+
.list({
48+
workspace,
49+
pagelen: 100,
50+
role: "admin", // installation of webhooks is allowed for admins only
51+
})
52+
.catch((e) => {
53+
console.error(e);
54+
}),
55+
),
56+
);
4857

4958
const reposInWorkspace = await reposPromise;
5059
for (const repos of reposInWorkspace) {
5160
if (repos) {
52-
for (const repo of (repos.data.values || [])) {
61+
for (const repo of repos.data.values || []) {
5362
let cloneUrl = repo.links!.clone!.find((x: any) => x.name === "https")!.href!;
5463
if (cloneUrl) {
5564
const url = new URL(cloneUrl);
56-
url.username = '';
65+
url.username = "";
5766
cloneUrl = url.toString();
5867
}
5968
const fullName = repo.full_name!;
@@ -67,7 +76,7 @@ export class BitbucketAppSupport {
6776
cloneUrl,
6877
updatedAt,
6978
accountAvatarUrl,
70-
})
79+
});
7180
}
7281
}
7382
}
@@ -76,5 +85,4 @@ export class BitbucketAppSupport {
7685
result.unshift(...ownersRepos);
7786
return result;
7887
}
79-
80-
}
88+
}

components/server/ee/src/container-module.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ import { MonitoringEndpointsAppEE } from "./monitoring-endpoint-ee";
3232
import { MonitoringEndpointsApp } from "../../src/monitoring-endpoints";
3333
import { WorkspaceHealthMonitoring } from "./workspace/workspace-health-monitoring";
3434
import { AccountService } from "@gitpod/gitpod-payment-endpoint/lib/accounting/account-service";
35-
import { AccountServiceImpl, SubscriptionService, TeamSubscriptionService } from "@gitpod/gitpod-payment-endpoint/lib/accounting";
36-
import { ChargebeeProvider, ChargebeeProviderOptions, UpgradeHelper } from "@gitpod/gitpod-payment-endpoint/lib/chargebee";
35+
import {
36+
AccountServiceImpl,
37+
SubscriptionService,
38+
TeamSubscriptionService,
39+
} from "@gitpod/gitpod-payment-endpoint/lib/accounting";
40+
import {
41+
ChargebeeProvider,
42+
ChargebeeProviderOptions,
43+
UpgradeHelper,
44+
} from "@gitpod/gitpod-payment-endpoint/lib/chargebee";
3745
import { ChargebeeCouponComputer } from "./user/coupon-computer";
3846
import { ChargebeeService } from "./user/chargebee-service";
3947
import { EligibilityService } from "./user/eligibility-service";
@@ -100,11 +108,13 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
100108

101109
// payment/billing
102110
bind(ChargebeeProvider).toSelf().inSingletonScope();
103-
bind(ChargebeeProviderOptions).toDynamicValue(ctx => {
104-
const config = ctx.container.get<Config>(Config);
105-
return config.chargebeeProviderOptions;
106-
}).inSingletonScope();
111+
bind(ChargebeeProviderOptions)
112+
.toDynamicValue((ctx) => {
113+
const config = ctx.container.get<Config>(Config);
114+
return config.chargebeeProviderOptions;
115+
})
116+
.inSingletonScope();
107117
bind(UpgradeHelper).toSelf().inSingletonScope();
108118
bind(ChargebeeCouponComputer).toSelf().inSingletonScope();
109119
bind(ChargebeeService).toSelf().inSingletonScope();
110-
});
120+
});

components/server/ee/src/github/container-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ import { GitHubService } from "../prebuilds/github-service";
1010

1111
export const gitHubContainerModuleEE = new ContainerModule((_bind, _unbind, _isBound, rebind) => {
1212
rebind(RepositoryService).to(GitHubService).inSingletonScope();
13-
});
13+
});

components/server/ee/src/github/github-app-support.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1515

1616
@injectable()
1717
export class GitHubAppSupport {
18-
1918
@inject(GithubApp) protected readonly githubApp: GithubApp;
2019
@inject(UserDB) protected readonly userDB: UserDB;
2120
@inject(TokenProvider) protected readonly tokenProvider: TokenProvider;
2221

23-
async getProviderRepositoriesForUser(params: { user: User, provider: string, hints?: object }): Promise<ProviderRepository[]> {
22+
async getProviderRepositoriesForUser(params: {
23+
user: User;
24+
provider: string;
25+
hints?: object;
26+
}): Promise<ProviderRepository[]> {
2427
const { user, provider, hints } = params;
2528
const result: ProviderRepository[] = [];
2629
const probot = this.githubApp.server?.probotApp;
@@ -31,7 +34,7 @@ export class GitHubAppSupport {
3134
return result; // Just GitHub.com for now
3235
}
3336

34-
const identity = user.identities.find(i => i.authProviderId === "Public-GitHub");
37+
const identity = user.identities.find((i) => i.authProviderId === "Public-GitHub");
3538
if (!identity) {
3639
return result;
3740
}
@@ -41,29 +44,33 @@ export class GitHubAppSupport {
4144

4245
const findInstallationForAccount = async (account: string) => {
4346
try {
44-
return await appApi.apps.getUserInstallation({ username: account })
47+
return await appApi.apps.getUserInstallation({ username: account });
4548
} catch (error: any) {
4649
if (error instanceof RequestError) {
4750
// ignore 404 - not found
4851
} else {
4952
log.debug(error);
5053
}
5154
}
52-
}
53-
const listReposForInstallation = async (installation: RestEndpointMethodTypes["apps"]["getUserInstallation"]["response"]) => {
55+
};
56+
const listReposForInstallation = async (
57+
installation: RestEndpointMethodTypes["apps"]["getUserInstallation"]["response"],
58+
) => {
5459
const sub = await probot.auth(installation.data.id);
5560
try {
5661
// it seems like `sub.paginate` flattens the result and the typings are off. We do the same with the typings to mimic the shape we get.
57-
const accessibleRepos = (await sub.paginate(sub.rest.apps.listReposAccessibleToInstallation, { per_page: 100 })) as any as RestEndpointMethodTypes["apps"]["listReposAccessibleToInstallation"]["response"]["data"]["repositories"];
58-
return accessibleRepos.map(r => {
62+
const accessibleRepos = (await sub.paginate(sub.rest.apps.listReposAccessibleToInstallation, {
63+
per_page: 100,
64+
})) as any as RestEndpointMethodTypes["apps"]["listReposAccessibleToInstallation"]["response"]["data"]["repositories"];
65+
return accessibleRepos.map((r) => {
5966
return <ProviderRepository>{
6067
name: r.name,
6168
cloneUrl: r.clone_url,
6269
account: r.owner?.login,
6370
accountAvatarUrl: r.owner?.avatar_url,
6471
updatedAt: r.updated_at,
6572
installationId: installation.data.id,
66-
installationUpdatedAt: installation.data.updated_at
73+
installationUpdatedAt: installation.data.updated_at,
6774
};
6875
});
6976
} catch (error: any) {
@@ -73,14 +80,14 @@ export class GitHubAppSupport {
7380
log.debug(error);
7481
}
7582
}
76-
}
83+
};
7784

7885
const listReposAccessibleToInstallation = async (account: string) => {
7986
const installation = await findInstallationForAccount(account);
8087
if (installation) {
8188
return await listReposForInstallation(installation);
8289
}
83-
}
90+
};
8491

8592
const ownRepos = await listReposAccessibleToInstallation(usersGitHubAccount);
8693
if (ownRepos) {
@@ -92,15 +99,15 @@ export class GitHubAppSupport {
9299
const token = await this.tokenProvider.getTokenForHost(user, provider);
93100
if (token.scopes.includes("read:org")) {
94101
const api = new Octokit({
95-
auth: token.value
102+
auth: token.value,
96103
});
97104
const { data } = await api.orgs.listMembershipsForAuthenticatedUser();
98-
organizations.push(...data.map(o => o.organization.login));
105+
organizations.push(...data.map((o) => o.organization.login));
99106
}
100-
} catch { }
107+
} catch {}
101108

102109
// Add Orgs we learned about from previous installations
103-
for (const org of (user.additionalData?.knownGitHubOrgs || [])) {
110+
for (const org of user.additionalData?.knownGitHubOrgs || []) {
104111
if (!organizations.includes(org)) {
105112
organizations.unshift(org);
106113
}
@@ -116,13 +123,13 @@ export class GitHubAppSupport {
116123
//
117124
const installationId = parseInt((hints as any)?.installationId, 10);
118125
if (!isNaN(installationId)) {
119-
if (!result.some(r => r.installationId === installationId)) {
120-
const installation = await appApi.apps.getInstallation({installation_id: installationId});
126+
if (!result.some((r) => r.installationId === installationId)) {
127+
const installation = await appApi.apps.getInstallation({ installation_id: installationId });
121128
if (installation) {
122129
const additional = await listReposForInstallation(installation);
123130
if (additional) {
124131
for (const repo of additional) {
125-
if (result.some(r => r.account === repo.account && r.name === repo.name)) {
132+
if (result.some((r) => r.account === repo.account && r.name === repo.name)) {
126133
continue; // avoid duplicates when switching between "selected repos" and "all repos"
127134
}
128135

@@ -132,8 +139,8 @@ export class GitHubAppSupport {
132139
// optionally store newly identified organization of a user,
133140
// just because the `listMembershipsForAuthenticatedUser` operation of the GH API
134141
// requires an extra permission of the org's maintainer.
135-
user.additionalData = user.additionalData || {}
136-
user.additionalData.knownGitHubOrgs = user.additionalData.knownGitHubOrgs || [ ];
142+
user.additionalData = user.additionalData || {};
143+
user.additionalData.knownGitHubOrgs = user.additionalData.knownGitHubOrgs || [];
137144
if (!user.additionalData.knownGitHubOrgs.includes(repo.account)) {
138145
user.additionalData.knownGitHubOrgs.push(repo.account);
139146
await this.userDB.updateUserPartial(user);
@@ -143,10 +150,9 @@ export class GitHubAppSupport {
143150
} else {
144151
log.debug(`Provided installationId appears to be invalid.`, { installationId });
145152
}
146-
147153
}
148154
}
149155

150156
return result;
151157
}
152-
}
158+
}

0 commit comments

Comments
 (0)