From 61d50ae1a6b85db6cb6931679b787128373a1580 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Tue, 14 Nov 2023 11:52:38 +0000 Subject: [PATCH 1/3] [dashboard] compute `useIsGithubAppEnabled` on FE --- components/dashboard/src/data/git-providers/github-queries.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/dashboard/src/data/git-providers/github-queries.ts b/components/dashboard/src/data/git-providers/github-queries.ts index 2cd4dcfccaa03f..6a50b8c4e734b9 100644 --- a/components/dashboard/src/data/git-providers/github-queries.ts +++ b/components/dashboard/src/data/git-providers/github-queries.ts @@ -11,7 +11,8 @@ import { useCurrentUser } from "../../user-context"; export const useIsGithubAppEnabled = () => { return useQuery(["github-app-enabled"], async () => { - return await getGitpodService().server.isGitHubAppEnabled(); + // similar to `isGitpodio`, but the GH App is only configured on Cloud. + return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com"; }); }; From 523df41c7a59ac499cd02c3e0673c67960172fc9 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 15 Nov 2023 06:34:58 +0000 Subject: [PATCH 2/3] [dashboard] update Install GitHub App --- .../src/projects/InstallGitHubApp.tsx | 100 +----------------- 1 file changed, 5 insertions(+), 95 deletions(-) diff --git a/components/dashboard/src/projects/InstallGitHubApp.tsx b/components/dashboard/src/projects/InstallGitHubApp.tsx index 356110c32b0cf8..8f4ef8cd7becdb 100644 --- a/components/dashboard/src/projects/InstallGitHubApp.tsx +++ b/components/dashboard/src/projects/InstallGitHubApp.tsx @@ -4,64 +4,10 @@ * See License.AGPL.txt in the project root for license information. */ -import { useLocation } from "react-router"; import InfoBox from "../components/InfoBox"; -import Modal from "../components/Modal"; -import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred"; -import { getGitpodService, gitpodHostUrl } from "../service/service"; -import { useState } from "react"; -import { openAuthorizeWindow } from "../provider-utils"; - -async function registerApp(installationId: string, setModal: (modal: "done" | string | undefined) => void) { - try { - await getGitpodService().server.registerGithubApp(installationId); - - const result = new Deferred(1000 * 60 * 10 /* 10 min */); - - openAuthorizeWindow({ - host: "github.com", - scopes: ["repo"], - onSuccess: () => { - setModal("done"); - result.resolve(); - }, - onError: (payload) => { - let errorMessage: string; - if (typeof payload === "string") { - errorMessage = payload; - } else { - errorMessage = payload.description ? payload.description : `Error: ${payload.error}`; - } - setModal(errorMessage); - }, - }); - - return result.promise; - } catch (e) { - setModal(e.message); - } -} +import { gitpodHostUrl } from "../service/service"; export default function InstallGitHubApp() { - const location = useLocation(); - const [modal, setModal] = useState<"done" | string | undefined>(); - const params = new URLSearchParams(location.search); - const installationId = params.get("installation_id") || undefined; - if (!installationId) { - return ( -
-
-
-

No Installation ID Found

-
- Did you come here from the GitHub app's page? -
-
-
-
- ); - } - const goToApp = () => (window.location.href = gitpodHostUrl.toString()); return ( @@ -69,53 +15,17 @@ export default function InstallGitHubApp() {
-

Install GitHub App

+

GitHub App 🌅

- You are about to install the GitHub app for Gitpod. + You likely tried to install the GitHub App for Gitpod.
- - This action will also allow Gitpod to access private repositories. You can edit Git provider - permissions later in user settings. - + Gitpod no longer requires to install the GitHub App on repositories.
- - +
- Go to Dashboard} - > -
- The GitHub app was installed successfully. Have a look at the{" "} - - documentation - {" "} - to find out how to configure it. -
-
- - Cancel - , - , - ]} - > -
Could not install the GitHub app.
- {modal} -
); } From c84ca73f63c44aece2960cb0730dd003096591bb Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 15 Nov 2023 06:36:42 +0000 Subject: [PATCH 3/3] [server] make GH App methods no-op (compat) --- .../gitpod-protocol/src/gitpod-service.ts | 2 ++ .../src/workspace/gitpod-server-impl.ts | 21 ++----------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index 83806d376504ba..768e0e52d22f4b 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -214,7 +214,9 @@ export interface GitpodServer extends JsonRpcServer, AdminServer, deleteGitpodToken(tokenHash: string): Promise; // misc + /** @deprecated always returns false */ isGitHubAppEnabled(): Promise; + /** @deprecated this is a no-op */ registerGithubApp(installationId: string): Promise; /** diff --git a/components/server/src/workspace/gitpod-server-impl.ts b/components/server/src/workspace/gitpod-server-impl.ts index 9a16b008d61ea5..9b38d740077acc 100644 --- a/components/server/src/workspace/gitpod-server-impl.ts +++ b/components/server/src/workspace/gitpod-server-impl.ts @@ -5,7 +5,6 @@ */ import { - AppInstallationDB, UserDB, WorkspaceDB, DBWithTracing, @@ -224,8 +223,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { @inject(LinkedInService) private readonly linkedInService: LinkedInService, - @inject(AppInstallationDB) private readonly appInstallationDB: AppInstallationDB, - @inject(AuthProviderService) private readonly authProviderService: AuthProviderService, @inject(GitTokenScopeGuesser) private readonly gitTokenScopeGuesser: GitTokenScopeGuesser, @@ -1849,24 +1846,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { } async isGitHubAppEnabled(ctx: TraceContext): Promise { - await this.checkAndBlockUser(); - return !!this.config.githubApp?.enabled; + return false; } - async registerGithubApp(ctx: TraceContext, installationId: string): Promise { - traceAPIParams(ctx, { installationId }); - - const user = await this.checkAndBlockUser(); - - if (!this.config.githubApp?.enabled) { - throw new ApplicationError( - ErrorCodes.NOT_FOUND, - "No GitHub app enabled for this installation. Please talk to your administrator.", - ); - } - - await this.appInstallationDB.recordNewInstallation("github", "user", installationId, user.id); - } + async registerGithubApp(ctx: TraceContext, installationId: string): Promise {} async takeSnapshot(ctx: TraceContext, options: GitpodServer.TakeSnapshotOptions): Promise { traceAPIParams(ctx, { options });