Skip to content

Commit feb9fa2

Browse files
authored
🌇 GitHub App in Dashboard (#19070)
* [dashboard] compute `useIsGithubAppEnabled` on FE * [dashboard] update Install GitHub App * [server] make GH App methods no-op (compat)
1 parent 0907ff5 commit feb9fa2

File tree

4 files changed

+11
-115
lines changed

4 files changed

+11
-115
lines changed

components/dashboard/src/data/git-providers/github-queries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { useCurrentUser } from "../../user-context";
1111

1212
export const useIsGithubAppEnabled = () => {
1313
return useQuery(["github-app-enabled"], async () => {
14-
return await getGitpodService().server.isGitHubAppEnabled();
14+
// similar to `isGitpodio`, but the GH App is only configured on Cloud.
15+
return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com";
1516
});
1617
};
1718

components/dashboard/src/projects/InstallGitHubApp.tsx

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,118 +4,28 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { useLocation } from "react-router";
87
import InfoBox from "../components/InfoBox";
9-
import Modal from "../components/Modal";
10-
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
11-
import { getGitpodService, gitpodHostUrl } from "../service/service";
12-
import { useState } from "react";
13-
import { openAuthorizeWindow } from "../provider-utils";
14-
15-
async function registerApp(installationId: string, setModal: (modal: "done" | string | undefined) => void) {
16-
try {
17-
await getGitpodService().server.registerGithubApp(installationId);
18-
19-
const result = new Deferred<void>(1000 * 60 * 10 /* 10 min */);
20-
21-
openAuthorizeWindow({
22-
host: "github.com",
23-
scopes: ["repo"],
24-
onSuccess: () => {
25-
setModal("done");
26-
result.resolve();
27-
},
28-
onError: (payload) => {
29-
let errorMessage: string;
30-
if (typeof payload === "string") {
31-
errorMessage = payload;
32-
} else {
33-
errorMessage = payload.description ? payload.description : `Error: ${payload.error}`;
34-
}
35-
setModal(errorMessage);
36-
},
37-
});
38-
39-
return result.promise;
40-
} catch (e) {
41-
setModal(e.message);
42-
}
43-
}
8+
import { gitpodHostUrl } from "../service/service";
449

4510
export default function InstallGitHubApp() {
46-
const location = useLocation();
47-
const [modal, setModal] = useState<"done" | string | undefined>();
48-
const params = new URLSearchParams(location.search);
49-
const installationId = params.get("installation_id") || undefined;
50-
if (!installationId) {
51-
return (
52-
<div className="app-container flex flex-col space-y-2">
53-
<div className="px-6 py-3 flex justify-between space-x-2 text-gray-400 border-t border-gray-200 dark:border-gray-800 h-96">
54-
<div className="flex flex-col items-center w-96 m-auto">
55-
<h3 className="text-center pb-3 text-gray-500 dark:text-gray-400">No Installation ID Found</h3>
56-
<div className="text-center pb-6 text-gray-500">
57-
Did you come here from the GitHub app's page?
58-
</div>
59-
</div>
60-
</div>
61-
</div>
62-
);
63-
}
64-
6511
const goToApp = () => (window.location.href = gitpodHostUrl.toString());
6612

6713
return (
6814
<>
6915
<div className="app-container flex flex-col space-y-2">
7016
<div className="px-6 py-3 flex justify-between space-x-2 text-gray-400">
7117
<div className="flex flex-col items-center m-auto max-w-lg mt-40">
72-
<h3 className="text-center pb-3 text-gray-500">Install GitHub App</h3>
18+
<h3 className="text-center pb-3 text-gray-500">GitHub App 🌅</h3>
7319
<div className="text-center pb-6 text-gray-500">
74-
You are about to install the GitHub app for Gitpod.
20+
You likely tried to install the GitHub App for Gitpod.
7521
</div>
76-
<InfoBox>
77-
This action will also allow Gitpod to access private repositories. You can edit Git provider
78-
permissions later in user settings.
79-
</InfoBox>
22+
<InfoBox>Gitpod no longer requires to install the GitHub App on repositories.</InfoBox>
8023
<div className="mt-6">
81-
<button className="secondary">Cancel</button>
82-
<button className="ml-2" onClick={() => registerApp(installationId, setModal)}>
83-
Install App
84-
</button>
24+
<button onClick={goToApp}>Go to Dashboard</button>
8525
</div>
8626
</div>
8727
</div>
8828
</div>
89-
<Modal
90-
title="Installation Successful"
91-
visible={modal === "done"}
92-
onClose={goToApp}
93-
buttons={<button onClick={goToApp}>Go to Dashboard</button>}
94-
>
95-
<div className="pb-6 text-gray-500">
96-
The GitHub app was installed successfully. Have a look at the{" "}
97-
<a className="text-blue-500" href="https://www.gitpod.io/docs/prebuilds/" rel="noopener">
98-
documentation
99-
</a>{" "}
100-
to find out how to configure it.
101-
</div>
102-
</Modal>
103-
<Modal
104-
title="Failed to Install"
105-
visible={!!modal && modal !== "done"}
106-
onClose={goToApp}
107-
buttons={[
108-
<button className="secondary" onClick={goToApp}>
109-
Cancel
110-
</button>,
111-
<button className="" onClick={() => registerApp(installationId, setModal)}>
112-
Try Again
113-
</button>,
114-
]}
115-
>
116-
<div className="pb-6 text-gray-500">Could not install the GitHub app.</div>
117-
<InfoBox>{modal}</InfoBox>
118-
</Modal>
11929
</>
12030
);
12131
}

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
211211
deleteGitpodToken(tokenHash: string): Promise<void>;
212212

213213
// misc
214+
/** @deprecated always returns false */
214215
isGitHubAppEnabled(): Promise<boolean>;
216+
/** @deprecated this is a no-op */
215217
registerGithubApp(installationId: string): Promise<void>;
216218

217219
/**

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {
8-
AppInstallationDB,
98
UserDB,
109
WorkspaceDB,
1110
DBWithTracing,
@@ -223,8 +222,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
223222

224223
@inject(LinkedInService) private readonly linkedInService: LinkedInService,
225224

226-
@inject(AppInstallationDB) private readonly appInstallationDB: AppInstallationDB,
227-
228225
@inject(AuthProviderService) private readonly authProviderService: AuthProviderService,
229226

230227
@inject(GitTokenScopeGuesser) private readonly gitTokenScopeGuesser: GitTokenScopeGuesser,
@@ -1725,24 +1722,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
17251722
}
17261723

17271724
async isGitHubAppEnabled(ctx: TraceContext): Promise<boolean> {
1728-
await this.checkAndBlockUser();
1729-
return !!this.config.githubApp?.enabled;
1725+
return false;
17301726
}
17311727

1732-
async registerGithubApp(ctx: TraceContext, installationId: string): Promise<void> {
1733-
traceAPIParams(ctx, { installationId });
1734-
1735-
const user = await this.checkAndBlockUser();
1736-
1737-
if (!this.config.githubApp?.enabled) {
1738-
throw new ApplicationError(
1739-
ErrorCodes.NOT_FOUND,
1740-
"No GitHub app enabled for this installation. Please talk to your administrator.",
1741-
);
1742-
}
1743-
1744-
await this.appInstallationDB.recordNewInstallation("github", "user", installationId, user.id);
1745-
}
1728+
async registerGithubApp(ctx: TraceContext, installationId: string): Promise<void> {}
17461729

17471730
async takeSnapshot(ctx: TraceContext, options: GitpodServer.TakeSnapshotOptions): Promise<string> {
17481731
traceAPIParams(ctx, { options });

0 commit comments

Comments
 (0)