Skip to content

Enable git integrations of Bitbucket for self-hosted Gitpod #9894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { StartWorkspaceModal } from "./workspaces/StartWorkspaceModal";
import { parseProps } from "./start/StartWorkspace";
import SelectIDEModal from "./settings/SelectIDEModal";
import { StartPage, StartPhase } from "./start/StartPage";
import { isGitpodIo } from "./utils";

const Setup = React.lazy(() => import(/* webpackPrefetch: true */ "./Setup"));
const Workspaces = React.lazy(() => import(/* webpackPrefetch: true */ "./workspaces/Workspaces"));
Expand Down Expand Up @@ -86,15 +87,6 @@ function Loading() {
return <></>;
}

function isGitpodIo() {
return (
window.location.hostname === "gitpod.io" ||
window.location.hostname === "gitpod-staging.com" ||
window.location.hostname.endsWith("gitpod-dev.com") ||
window.location.hostname.endsWith("gitpod-io-dev.com")
);
}

function isWebsiteSlug(pathName: string) {
const slugs = [
"about",
Expand Down
5 changes: 1 addition & 4 deletions components/dashboard/src/admin/License.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ReactComponent as CheckSvg } from "../images/check.svg";
import { ReactComponent as LinkSvg } from "../images/external-link.svg";
import SolidCard from "../components/SolidCard";
import Card from "../components/Card";
import { isGitpodIo } from "../utils";

export default function License() {
const { license, setLicense } = useContext(LicenseContext);
Expand Down Expand Up @@ -212,7 +213,3 @@ function communityPlan(userCount: number, seats: number, fallbackAllowed: boolea

return [licenseLevel("Community"), additionalLicenseInfo("Free"), alertMessage(aboveLimit)];
}

function isGitpodIo() {
return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com";
}
5 changes: 1 addition & 4 deletions components/dashboard/src/admin/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getGitpodService } from "../service/service";
import { adminMenu } from "./admin-menu";
import { useEffect, useState } from "react";
import InfoBox from "../components/InfoBox";
import { isGitpodIo } from "../utils";

export default function Settings() {
const { adminSettings, setAdminSettings } = useContext(AdminContext);
Expand Down Expand Up @@ -69,7 +70,3 @@ export default function Settings() {
</div>
);
}

function isGitpodIo() {
return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com";
}
17 changes: 14 additions & 3 deletions components/dashboard/src/settings/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PaymentContext } from "../payment-context";
import { openAuthorizeWindow } from "../provider-utils";
import { getGitpodService, gitpodHostUrl } from "../service/service";
import { UserContext } from "../user-context";
import { isGitpodIo } from "../utils";
import { SelectAccountModal } from "./SelectAccountModal";
import getSettingsMenu from "./settings-menu";

Expand Down Expand Up @@ -553,6 +554,13 @@ export function GitIntegrationModal(
validate();
}, [clientId, clientSecret, type]);

// "bitbucket.org" is set as host value whenever "Bitbucket" is selected
useEffect(() => {
if (props.mode === "new") {
updateHostValue(type === "Bitbucket" ? "bitbucket.org" : "");
}
}, [type]);

const onClose = () => props.onClose && props.onClose();
const onUpdate = () => props.onUpdate && props.onUpdate();

Expand Down Expand Up @@ -696,11 +704,11 @@ export function GitIntegrationModal(
return (
<span>
Use this redirect URL to update the OAuth application. Go to{" "}
<a href={`https://${settingsUrl}`} target="_blank" rel="noopener" className="gp-link">
<a href={`https://${settingsUrl}`} target="_blank" rel="noreferrer noopener" className="gp-link">
developer settings
</a>{" "}
and setup the OAuth application.&nbsp;
<a href={docsUrl} target="_blank" rel="noopener" className="gp-link">
<a href={docsUrl} target="_blank" rel="noreferrer noopener" className="gp-link">
Learn more
</a>
.
Expand All @@ -716,6 +724,8 @@ export function GitIntegrationModal(
return "gitlab.example.com";
case "BitbucketServer":
return "bitbucket.example.com";
case "Bitbucket":
return "bitbucket.org";
default:
return "";
}
Expand Down Expand Up @@ -762,6 +772,7 @@ export function GitIntegrationModal(
>
<option value="GitHub">GitHub</option>
<option value="GitLab">GitLab</option>
{!isGitpodIo() && <option value="Bitbucket">Bitbucket</option>}
<option value="BitbucketServer">Bitbucket Server</option>
</select>
</div>
Expand All @@ -785,7 +796,7 @@ export function GitIntegrationModal(
</label>
<input
name="hostName"
disabled={mode === "edit"}
disabled={mode === "edit" || type === "Bitbucket"}
type="text"
placeholder={getPlaceholderForIntegrationType(type)}
value={host}
Expand Down
9 changes: 9 additions & 0 deletions components/dashboard/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ export const poll = async <T>(
}
}
};

export function isGitpodIo() {
return (
window.location.hostname === "gitpod.io" ||
window.location.hostname === "gitpod-staging.com" ||
window.location.hostname.endsWith("gitpod-dev.com") ||
window.location.hostname.endsWith("gitpod-io-dev.com")
);
}
4 changes: 4 additions & 0 deletions components/server/src/auth/auth-provider-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { v4 as uuidv4 } from "uuid";
import { oauthUrls as githubUrls } from "../github/github-urls";
import { oauthUrls as gitlabUrls } from "../gitlab/gitlab-urls";
import { oauthUrls as bbsUrls } from "../bitbucket-server/bitbucket-server-urls";
import { oauthUrls as bbUrls } from "../bitbucket/bitbucket-urls";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";

@injectable()
Expand Down Expand Up @@ -123,6 +124,9 @@ export class AuthProviderService {
case "BitbucketServer":
urls = bbsUrls(host);
break;
case "Bitbucket":
urls = bbUrls(host);
break;
}
if (!urls) {
throw new Error("Unexpected service type.");
Expand Down
15 changes: 15 additions & 0 deletions components/server/src/bitbucket/bitbucket-urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

// cf. https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/
//
export function oauthUrls(host: string) {
return {
authorizationUrl: `https://${host}/site/oauth2/authorize`,
tokenUrl: `https://${host}/site/oauth2/access_token`,
settingsUrl: `https://${host}/account/settings/app-authorizations/`,
};
}