Skip to content
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
8 changes: 8 additions & 0 deletions src/constants.integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const supportedOrderedCloudIntegrationIds = [
HostingIntegrationId.GitLab,
SelfHostedIntegrationId.CloudGitLabSelfHosted,
HostingIntegrationId.AzureDevOps,
HostingIntegrationId.Bitbucket,
IssueIntegrationId.Jira,
];

Expand Down Expand Up @@ -84,6 +85,13 @@ export const supportedCloudIntegrationDescriptors: IntegrationDescriptor[] = [
supports: ['prs', 'issues'],
requiresPro: true,
},
{
id: HostingIntegrationId.Bitbucket,
name: 'Bitbucket',
icon: 'gl-provider-bitbucket',
supports: ['prs'],
requiresPro: false,
},
{
id: IssueIntegrationId.Jira,
name: 'Jira',
Expand Down
118 changes: 2 additions & 116 deletions src/plus/integrations/authentication/bitbucket.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,8 @@
import type { Disposable, QuickInputButton } from 'vscode';
import { env, ThemeIcon, Uri, window } from 'vscode';
import { HostingIntegrationId } from '../../../constants.integrations';
import { base64 } from '../../../system/string';
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider';
import { LocalIntegrationAuthenticationProvider } from './integrationAuthenticationProvider';
import type { ProviderAuthenticationSession } from './models';
import { CloudIntegrationAuthenticationProvider } from './integrationAuthenticationProvider';

export class BitbucketAuthenticationProvider extends LocalIntegrationAuthenticationProvider<HostingIntegrationId.Bitbucket> {
export class BitbucketAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.Bitbucket> {
protected override get authProviderId(): HostingIntegrationId.Bitbucket {
return HostingIntegrationId.Bitbucket;
}

override async createSession(
descriptor: IntegrationAuthenticationSessionDescriptor,
): Promise<ProviderAuthenticationSession | undefined> {
let bitbucketUsername: string | undefined = descriptor.username as string | undefined;
if (!bitbucketUsername) {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open the Bitbucket Settings Page',
};

const usernameInput = window.createInputBox();
usernameInput.ignoreFocusOut = true;
const usernameInputDisposables: Disposable[] = [];
try {
bitbucketUsername = await new Promise<string | undefined>(resolve => {
usernameInputDisposables.push(
usernameInput.onDidHide(() => resolve(undefined)),
usernameInput.onDidChangeValue(() => (usernameInput.validationMessage = undefined)),
usernameInput.onDidAccept(() => {
const value = usernameInput.value.trim();
if (!value) {
usernameInput.validationMessage = 'A Bitbucket username is required';
return;
}

resolve(value);
}),
usernameInput.onDidTriggerButton(e => {
if (e === infoButton) {
void env.openExternal(Uri.parse(`https://${descriptor.domain}/account/settings/`));
}
}),
);

usernameInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`;
usernameInput.placeholder = 'Username';
usernameInput.prompt = `Enter your [Bitbucket Username](https://${descriptor.domain}/account/settings/ "Get your Bitbucket App Password")`;
usernameInput.show();
});
} finally {
usernameInput.dispose();
usernameInputDisposables.forEach(d => void d.dispose());
}
}

if (!bitbucketUsername) return undefined;

const appPasswordInput = window.createInputBox();
appPasswordInput.ignoreFocusOut = true;

const disposables: Disposable[] = [];

let appPassword;
try {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open the Bitbucket App Passwords Page',
};

appPassword = await new Promise<string | undefined>(resolve => {
disposables.push(
appPasswordInput.onDidHide(() => resolve(undefined)),
appPasswordInput.onDidChangeValue(() => (appPasswordInput.validationMessage = undefined)),
appPasswordInput.onDidAccept(() => {
const value = appPasswordInput.value.trim();
if (!value) {
appPasswordInput.validationMessage = 'An app password is required';
return;
}

resolve(value);
}),
appPasswordInput.onDidTriggerButton(e => {
if (e === infoButton) {
void env.openExternal(
Uri.parse(`https://${descriptor.domain}/account/settings/app-passwords/`),
);
}
}),
);

appPasswordInput.password = true;
appPasswordInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`;
appPasswordInput.placeholder = `Requires ${descriptor.scopes.join(', ')} scopes`;
appPasswordInput.prompt = `Paste your [Bitbucket App Password](https://${descriptor.domain}/account/settings/app-passwords/ "Get your Bitbucket App Password")`;
appPasswordInput.buttons = [infoButton];

appPasswordInput.show();
});
} finally {
appPasswordInput.dispose();
disposables.forEach(d => void d.dispose());
}

if (!appPassword) return undefined;

return {
id: this.configuredIntegrationService.getSessionId(descriptor),
accessToken: base64(`${bitbucketUsername}:${appPassword}`),
scopes: descriptor.scopes,
account: {
id: '',
label: '',
},
cloud: false,
domain: descriptor.domain,
};
}
}
11 changes: 8 additions & 3 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import type {
SupportedSelfHostedIntegrationIds,
} from './integration';
import { isAzureCloudDomain } from './providers/azureDevOps';
import { isBitbucketCloudDomain } from './providers/bitbucket';
import {
isCloudSelfHostedIntegrationId,
isGitHubDotCom,
Expand Down Expand Up @@ -680,14 +681,16 @@ export class IntegrationService implements Disposable {
const get = getOrGetCached.bind(this);

switch (remote.provider.id) {
// TODO: Uncomment when we support these integrations
// case 'bitbucket':
// return get(HostingIntegrationId.Bitbucket) as RT;
case 'azure-devops':
if (isAzureCloudDomain(remote.provider.domain)) {
return get(HostingIntegrationId.AzureDevOps) as RT;
}
return (getOrGetCached === this.get ? Promise.resolve(undefined) : undefined) as RT;
case 'bitbucket':
if (isBitbucketCloudDomain(remote.provider.domain)) {
return get(HostingIntegrationId.Bitbucket) as RT;
}
return (getOrGetCached === this.get ? Promise.resolve(undefined) : undefined) as RT;
case 'github':
if (remote.provider.domain != null && !isGitHubDotCom(remote.provider.domain)) {
return get(
Expand Down Expand Up @@ -1049,6 +1052,8 @@ export function remoteProviderIdToIntegrationId(
switch (remoteProviderId) {
case 'azure-devops':
return HostingIntegrationId.AzureDevOps;
case 'bitbucket':
return HostingIntegrationId.Bitbucket;
case 'github':
return HostingIntegrationId.GitHub;
case 'gitlab':
Expand Down
5 changes: 5 additions & 0 deletions src/plus/integrations/providers/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,8 @@ export class BitbucketIntegration extends HostingIntegration<
return Promise.resolve(undefined);
}
}

const bitbucketCloudDomainRegex = /^bitbucket\.org$/i;
export function isBitbucketCloudDomain(domain: string | undefined): boolean {
return domain != null && bitbucketCloudDomainRegex.test(domain);
}