Skip to content

Commit d660e96

Browse files
committed
[WIP][server] Allow creating Projects from GitHub Enterprise repositories
1 parent 0c83914 commit d660e96

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import { BlockedUserFilter } from "../../src/auth/blocked-user-filter";
4545
import { EMailDomainService, EMailDomainServiceImpl } from "./auth/email-domain-service";
4646
import { UserDeletionServiceEE } from "./user/user-deletion-service";
4747
import { GitHubAppSupport } from "./github/github-app-support";
48+
import { GitHubRestApi } from "../../src/github/api";
49+
import { GitHubEnterpriseAppSupport } from "./github/github-enterprise-app-support";
4850
import { GitLabAppSupport } from "./gitlab/gitlab-app-support";
4951
import { Config } from "../../src/config";
5052
import { SnapshotService } from "./workspace/snapshot-service";
@@ -62,6 +64,8 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
6264
bind(IPrefixContextParser).to(StartIncrementalPrebuildContextParser).inSingletonScope();
6365
bind(GithubApp).toSelf().inSingletonScope();
6466
bind(GitHubAppSupport).toSelf().inSingletonScope();
67+
bind(GitHubRestApi).toSelf().inSingletonScope();
68+
bind(GitHubEnterpriseAppSupport).toSelf().inSingletonScope();
6569
bind(GithubAppRules).toSelf().inSingletonScope();
6670
bind(PrebuildStatusMaintainer).toSelf().inSingletonScope();
6771
bind(GitLabApp).toSelf().inSingletonScope();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the Gitpod Enterprise Source Code License,
4+
* See License.enterprise.txt in the project root folder.
5+
*/
6+
7+
import { inject, injectable } from "inversify";
8+
import { AuthProviderInfo, ProviderRepository, User } from "@gitpod/gitpod-protocol";
9+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
10+
import { GitHubRestApi } from "../../../src/github/api";
11+
import { TokenProvider } from "../../../src/user/token-provider";
12+
13+
@injectable()
14+
export class GitHubEnterpriseAppSupport {
15+
16+
@inject(TokenProvider) protected readonly tokenProvider: TokenProvider;
17+
@inject(GitHubRestApi) protected readonly gitHubApi: GitHubRestApi;
18+
19+
async getProviderRepositoriesForUser(params: { user: User, provider: AuthProviderInfo }): Promise<ProviderRepository[]> {
20+
const token = await this.tokenProvider.getTokenForHost(params.user, params.provider.host);
21+
const repositories = (await this.gitHubApi.run(token.value, gh => gh.repos.listForAuthenticatedUser({}))).data;
22+
log.info('GitHub Enterprise Repositories: ' + JSON.stringify(repositories, null, 2));
23+
return [];
24+
}
25+
26+
}

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { ChargebeeService } from "../user/chargebee-service";
3636
import { Chargebee as chargebee } from '@gitpod/gitpod-payment-endpoint/lib/chargebee';
3737

3838
import { GitHubAppSupport } from "../github/github-app-support";
39+
import { GitHubEnterpriseAppSupport } from "../github/github-enterprise-app-support";
3940
import { GitLabAppSupport } from "../gitlab/gitlab-app-support";
4041
import { Config } from "../../../src/config";
4142
import { SnapshotService, WaitForSnapshotOptions } from "./snapshot-service";
@@ -68,6 +69,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
6869
@inject(ChargebeeService) protected readonly chargebeeService: ChargebeeService;
6970

7071
@inject(GitHubAppSupport) protected readonly githubAppSupport: GitHubAppSupport;
72+
@inject(GitHubEnterpriseAppSupport) protected readonly gitHubEnterpriseAppSupport: GitHubEnterpriseAppSupport;
7173
@inject(GitLabAppSupport) protected readonly gitLabAppSupport: GitLabAppSupport;
7274
@inject(BitbucketAppSupport) protected readonly bitbucketAppSupport: BitbucketAppSupport;
7375

@@ -1476,6 +1478,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14761478

14771479
if (providerHost === "github.com") {
14781480
repositories.push(...(await this.githubAppSupport.getProviderRepositoriesForUser({ user, ...params })));
1481+
} else if (provider?.authProviderType === "GitHub") {
1482+
repositories.push(...(await this.gitHubEnterpriseAppSupport.getProviderRepositoriesForUser({ user, provider })));
14791483
} else if (providerHost === "bitbucket.org" && provider) {
14801484
repositories.push(...(await this.bitbucketAppSupport.getProviderRepositoriesForUser({ user, provider })));
14811485
} else if (provider?.authProviderType === "GitLab") {

0 commit comments

Comments
 (0)