Skip to content

Commit

Permalink
Allow integrating with 'github.com' without a GitHub App
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes committed Apr 11, 2022
1 parent 91fbaad commit 6b5cffe
Showing 4 changed files with 6 additions and 12 deletions.
5 changes: 2 additions & 3 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
@@ -634,14 +634,13 @@ function GitProviders(props: {
setErrorMessage(undefined);

const token = await getGitpodService().server.getToken({ host: ap.host });
const isGitHubEnterprise = AuthProviderInfo.isGitHubEnterprise(ap);
if (token && !(isGitHubEnterprise && !token.scopes.includes("repo"))) {
if (token && !(ap.authProviderType === "GitHub" && !token.scopes.includes("repo"))) {
props.onHostSelected(ap.host);
return;
}
await openAuthorizeWindow({
host: ap.host,
scopes: isGitHubEnterprise ? ["repo"] : ap.requirements?.default,
scopes: ap.authProviderType === "GitHub" ? ["repo"] : ap.requirements?.default,
onSuccess: async () => {
props.onHostSelected(ap.host, true);
},
6 changes: 0 additions & 6 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1153,12 +1153,6 @@ export interface AuthProviderInfo {
};
}

export namespace AuthProviderInfo {
export function isGitHubEnterprise(info?: AuthProviderInfo): boolean {
return !!info && info.authProviderType === "GitHub" && info.host !== "github.com";
}
}

export interface AuthProviderEntry {
readonly id: string;
readonly type: AuthProviderEntry.Type;
2 changes: 1 addition & 1 deletion components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
@@ -1777,7 +1777,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
const providerHost = params.provider;
const provider = (await this.getAuthProviders(ctx)).find((ap) => ap.host === providerHost);

if (providerHost === "github.com") {
if (providerHost === "github.com" && this.config.githubApp?.enabled) {
repositories.push(...(await this.githubAppSupport.getProviderRepositoriesForUser({ user, ...params })));
} else if (provider?.authProviderType === "GitHub") {
const hostContext = this.hostContextProvider.get(providerHost);
5 changes: 3 additions & 2 deletions components/server/src/projects/projects-service.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
import { inject, injectable } from "inversify";
import { DBWithTracing, ProjectDB, TeamDB, TracedWorkspaceDB, UserDB, WorkspaceDB } from "@gitpod/gitpod-db/lib";
import {
AuthProviderInfo,
Branch,
PrebuildWithStatus,
CreateProjectParams,
@@ -20,6 +19,7 @@ import { HostContextProvider } from "../auth/host-context-provider";
import { RepoURL } from "../repohost";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { PartialProject } from "@gitpod/gitpod-protocol/src/teams-projects-protocol";
import { Config } from "../config";

@injectable()
export class ProjectsService {
@@ -28,6 +28,7 @@ export class ProjectsService {
@inject(UserDB) protected readonly userDB: UserDB;
@inject(TracedWorkspaceDB) protected readonly workspaceDb: DBWithTracing<WorkspaceDB>;
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
@inject(Config) protected readonly config: Config;

async getProject(projectId: string): Promise<Project | undefined> {
return this.projectDB.findProjectById(projectId);
@@ -154,7 +155,7 @@ export class ProjectsService {
type === "GitLab" ||
type === "Bitbucket" ||
type === "BitbucketServer" ||
AuthProviderInfo.isGitHubEnterprise(authProvider)
(type === "GitHub" && (authProvider?.host !== "github.com" || !this.config.githubApp?.enabled))
) {
const repositoryService = hostContext?.services?.repositoryService;
if (repositoryService) {

0 comments on commit 6b5cffe

Please sign in to comment.