Skip to content

Commit f4e7781

Browse files
committed
Connects BitbucketServer cloud integration displays among connected integrations on the Home View
(#4107, #4146)
1 parent 7329ca9 commit f4e7781

File tree

11 files changed

+110
-14
lines changed

11 files changed

+110
-14
lines changed

docs/telemetry-events.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ or
378378
```typescript
379379
{
380380
'hostingProvider.key': string,
381-
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
381+
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
382382
}
383383
```
384384

@@ -389,7 +389,7 @@ or
389389
```typescript
390390
{
391391
'hostingProvider.key': string,
392-
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
392+
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
393393
}
394394
```
395395

@@ -400,7 +400,7 @@ or
400400
```typescript
401401
{
402402
'issueProvider.key': string,
403-
'issueProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
403+
'issueProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
404404
}
405405
```
406406

@@ -411,7 +411,7 @@ or
411411
```typescript
412412
{
413413
'issueProvider.key': string,
414-
'issueProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
414+
'issueProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
415415
}
416416
```
417417

@@ -432,7 +432,7 @@ or
432432
433433
```typescript
434434
{
435-
'integration.id': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
435+
'integration.id': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted'
436436
}
437437
```
438438

@@ -1553,7 +1553,7 @@ void
15531553
```typescript
15541554
{
15551555
'hostingProvider.key': string,
1556-
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted',
1556+
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted',
15571557
// @deprecated: true
15581558
'remoteProviders.key': string
15591559
}
@@ -1566,7 +1566,7 @@ void
15661566
```typescript
15671567
{
15681568
'hostingProvider.key': string,
1569-
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted',
1569+
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'bitbucket-server' | 'github-enterprise' | 'cloud-github-enterprise' | 'cloud-gitlab-self-hosted' | 'gitlab-self-hosted',
15701570
// @deprecated: true
15711571
'remoteProviders.key': string
15721572
}

src/constants.integrations.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum HostingIntegrationId {
66
}
77

88
export enum SelfHostedIntegrationId {
9+
BitbucketServer = 'bitbucket-server',
910
GitHubEnterprise = 'github-enterprise',
1011
CloudGitHubEnterprise = 'cloud-github-enterprise',
1112
CloudGitLabSelfHosted = 'cloud-gitlab-self-hosted',
@@ -14,6 +15,7 @@ export enum SelfHostedIntegrationId {
1415

1516
export type CloudSelfHostedIntegrationId =
1617
| SelfHostedIntegrationId.CloudGitHubEnterprise
18+
| SelfHostedIntegrationId.BitbucketServer
1719
| SelfHostedIntegrationId.CloudGitLabSelfHosted;
1820

1921
export enum IssueIntegrationId {
@@ -31,6 +33,7 @@ export const supportedOrderedCloudIntegrationIds = [
3133
SelfHostedIntegrationId.CloudGitLabSelfHosted,
3234
HostingIntegrationId.AzureDevOps,
3335
HostingIntegrationId.Bitbucket,
36+
SelfHostedIntegrationId.BitbucketServer,
3437
IssueIntegrationId.Jira,
3538
];
3639

@@ -92,6 +95,13 @@ export const supportedCloudIntegrationDescriptors: IntegrationDescriptor[] = [
9295
supports: ['prs', 'issues'],
9396
requiresPro: false,
9497
},
98+
{
99+
id: SelfHostedIntegrationId.BitbucketServer,
100+
name: 'Bitbucket Data Center',
101+
icon: 'gl-provider-bitbucket',
102+
supports: ['prs'],
103+
requiresPro: true,
104+
},
95105
{
96106
id: IssueIntegrationId.Jira,
97107
name: 'Jira',

src/git/remotes/remoteProviders.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ const builtInProviders: RemoteProviders = [
7676
},
7777
];
7878

79+
const cloudRemotesMap: { [key: string]: typeof GitHubRemote | typeof GitLabRemote | typeof BitbucketServerRemote } = {
80+
[SelfHostedIntegrationId.CloudGitHubEnterprise]: GitHubRemote,
81+
[SelfHostedIntegrationId.CloudGitLabSelfHosted]: GitLabRemote,
82+
[SelfHostedIntegrationId.BitbucketServer]: BitbucketServerRemote,
83+
};
84+
7985
export function loadRemoteProviders(
8086
cfg: RemotesConfig[] | null | undefined,
8187
configuredIntegrations?: ConfiguredIntegrationDescriptor[],
@@ -107,10 +113,8 @@ export function loadRemoteProviders(
107113
for (const ci of configuredIntegrations) {
108114
if (isCloudSelfHostedIntegrationId(ci.integrationId) && ci.domain) {
109115
const matcher = ci.domain.toLocaleLowerCase();
110-
const providerCreator = (_container: Container, domain: string, path: string) =>
111-
ci.integrationId === SelfHostedIntegrationId.CloudGitHubEnterprise
112-
? new GitHubRemote(domain, path)
113-
: new GitLabRemote(domain, path);
116+
const providerCreator = (_container: Container, domain: string, path: string): RemoteProvider =>
117+
new cloudRemotesMap[ci.integrationId](domain, path);
114118
const provider = {
115119
custom: false,
116120
matcher: matcher,
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { HostingIntegrationId } from '../../../constants.integrations';
1+
import { HostingIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
22
import { CloudIntegrationAuthenticationProvider } from './integrationAuthenticationProvider';
33

44
export class BitbucketAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.Bitbucket> {
55
protected override get authProviderId(): HostingIntegrationId.Bitbucket {
66
return HostingIntegrationId.Bitbucket;
77
}
88
}
9+
10+
export class BitbucketServerAuthenticationProvider extends CloudIntegrationAuthenticationProvider<SelfHostedIntegrationId.BitbucketServer> {
11+
protected override get authProviderId(): SelfHostedIntegrationId.BitbucketServer {
12+
return SelfHostedIntegrationId.BitbucketServer;
13+
}
14+
}

src/plus/integrations/authentication/integrationAuthenticationService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export class IntegrationAuthenticationService implements Disposable {
6868
await import(/* webpackChunkName: "integrations" */ './bitbucket')
6969
).BitbucketAuthenticationProvider(this.container, this, this.configuredIntegrationService);
7070
break;
71+
case SelfHostedIntegrationId.BitbucketServer:
72+
provider = new (
73+
await import(/* webpackChunkName: "integrations" */ './bitbucket')
74+
).BitbucketServerAuthenticationProvider(this.container, this, this.configuredIntegrationService);
75+
break;
7176
case HostingIntegrationId.GitHub:
7277
provider = isSupportedCloudIntegrationId(HostingIntegrationId.GitHub)
7378
? new (

src/plus/integrations/authentication/models.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type CloudIntegrationType =
4747
| 'gitlab'
4848
| 'github'
4949
| 'bitbucket'
50+
| 'bitbucketServer'
5051
| 'azure'
5152
| 'githubEnterprise'
5253
| 'gitlabSelfHosted';
@@ -73,6 +74,7 @@ export const toIntegrationId: { [key in CloudIntegrationType]: IntegrationId } =
7374
githubEnterprise: SelfHostedIntegrationId.CloudGitHubEnterprise,
7475
gitlabSelfHosted: SelfHostedIntegrationId.CloudGitLabSelfHosted,
7576
bitbucket: HostingIntegrationId.Bitbucket,
77+
bitbucketServer: SelfHostedIntegrationId.BitbucketServer,
7678
azure: HostingIntegrationId.AzureDevOps,
7779
};
7880

@@ -85,6 +87,7 @@ export const toCloudIntegrationType: { [key in IntegrationId]: CloudIntegrationT
8587
[HostingIntegrationId.AzureDevOps]: 'azure',
8688
[SelfHostedIntegrationId.CloudGitHubEnterprise]: 'githubEnterprise',
8789
[SelfHostedIntegrationId.CloudGitLabSelfHosted]: 'gitlabSelfHosted',
90+
[SelfHostedIntegrationId.BitbucketServer]: 'bitbucketServer',
8891
[SelfHostedIntegrationId.GitHubEnterprise]: undefined,
8992
[SelfHostedIntegrationId.GitLabSelfHosted]: undefined,
9093
};

src/plus/integrations/integrationService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ export function remoteProviderIdToIntegrationId(
10511051
case 'gitlab':
10521052
return HostingIntegrationId.GitLab;
10531053
case 'bitbucket-server':
1054+
return SelfHostedIntegrationId.BitbucketServer;
10541055
default:
10551056
return undefined;
10561057
}

src/plus/integrations/providers/models.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
AzureProject,
88
AzureSetPullRequestInput,
99
Bitbucket,
10+
BitbucketServer,
1011
BitbucketWorkspaceStub,
1112
EnterpriseOptions,
1213
GetRepoInput,
@@ -83,6 +84,7 @@ const selfHostedIntegrationIds: SelfHostedIntegrationId[] = [
8384
SelfHostedIntegrationId.GitHubEnterprise,
8485
SelfHostedIntegrationId.CloudGitLabSelfHosted,
8586
SelfHostedIntegrationId.GitLabSelfHosted,
87+
SelfHostedIntegrationId.BitbucketServer,
8688
] as const;
8789

8890
export const supportedIntegrationIds: IntegrationId[] = [
@@ -109,7 +111,11 @@ export function isHostingIntegrationId(id: IntegrationId): id is HostingIntegrat
109111
}
110112

111113
export function isCloudSelfHostedIntegrationId(id: IntegrationId): id is CloudSelfHostedIntegrationId {
112-
return id === SelfHostedIntegrationId.CloudGitHubEnterprise || id === SelfHostedIntegrationId.CloudGitLabSelfHosted;
114+
return (
115+
id === SelfHostedIntegrationId.CloudGitHubEnterprise ||
116+
id === SelfHostedIntegrationId.CloudGitLabSelfHosted ||
117+
id === SelfHostedIntegrationId.BitbucketServer
118+
);
113119
}
114120

115121
export const enum PullRequestFilter {
@@ -357,14 +363,24 @@ export type GetBitbucketPullRequestsAuthoredByUserForWorkspaceFn = (
357363
};
358364
data: GitPullRequest[];
359365
}>;
366+
export type GetBitbucketServerPullRequestsForCurrentUserFn = (
367+
input: NumberedPageInput,
368+
options?: EnterpriseOptions,
369+
) => Promise<{
370+
pageInfo: {
371+
hasNextPage: boolean;
372+
nextPage: number | null;
373+
};
374+
data: GitPullRequest[];
375+
}>;
360376
export type GetIssuesForProjectFn = Jira['getIssuesForProject'];
361377
export type GetIssuesForResourceForCurrentUserFn = (
362378
input: { resourceId: string },
363379
options?: EnterpriseOptions,
364380
) => Promise<{ data: ProviderIssue[] }>;
365381

366382
export interface ProviderInfo extends ProviderMetadata {
367-
provider: GitHub | GitLab | Bitbucket | Jira | Trello | AzureDevOps;
383+
provider: GitHub | GitLab | Bitbucket | BitbucketServer | Jira | Trello | AzureDevOps;
368384
getPullRequestsForReposFn?: GetPullRequestsForReposFn;
369385
getPullRequestsForRepoFn?: GetPullRequestsForRepoFn;
370386
getPullRequestsForUserFn?: GetPullRequestsForUserFn;
@@ -380,6 +396,7 @@ export interface ProviderInfo extends ProviderMetadata {
380396
getAzureResourcesForUserFn?: GetAzureResourcesForUserFn;
381397
getBitbucketResourcesForUserFn?: GetBitbucketResourcesForUserFn;
382398
getBitbucketPullRequestsAuthoredByUserForWorkspaceFn?: GetBitbucketPullRequestsAuthoredByUserForWorkspaceFn;
399+
getBitbucketServerPullRequestsForCurrentUserFn?: GetBitbucketServerPullRequestsForCurrentUserFn;
383400
getJiraProjectsForResourcesFn?: GetJiraProjectsForResourcesFn;
384401
getAzureProjectsForResourceFn?: GetAzureProjectsForResourceFn;
385402
getIssuesForProjectFn?: GetIssuesForProjectFn;
@@ -527,6 +544,15 @@ export const providersMetadata: ProvidersMetadata = {
527544
supportedPullRequestFilters: [PullRequestFilter.Author],
528545
scopes: ['account:read', 'repository:read', 'pullrequest:read', 'issue:read'],
529546
},
547+
[SelfHostedIntegrationId.BitbucketServer]: {
548+
domain: '',
549+
id: SelfHostedIntegrationId.BitbucketServer,
550+
name: 'Bitbucket Data Center',
551+
type: 'hosting',
552+
iconKey: SelfHostedIntegrationId.BitbucketServer,
553+
supportedPullRequestFilters: [PullRequestFilter.Author, PullRequestFilter.ReviewRequested],
554+
scopes: ['Project (Read)', 'Repository (Write)'],
555+
},
530556
[HostingIntegrationId.AzureDevOps]: {
531557
domain: 'dev.azure.com',
532558
id: HostingIntegrationId.AzureDevOps,

src/plus/integrations/providers/providersApi.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ export class ProvidersApi {
217217
providerApis.bitbucket,
218218
) as MergePullRequestFn,
219219
},
220+
[SelfHostedIntegrationId.BitbucketServer]: {
221+
...providersMetadata[SelfHostedIntegrationId.BitbucketServer],
222+
provider: providerApis.bitbucketServer,
223+
getCurrentUserFn: providerApis.bitbucketServer.getCurrentUser.bind(
224+
providerApis.bitbucketServer,
225+
) as GetCurrentUserFn,
226+
getBitbucketServerPullRequestsForCurrentUserFn:
227+
providerApis.bitbucketServer.getPullRequestsForCurrentUser.bind(providerApis.bitbucketServer),
228+
getPullRequestsForReposFn: providerApis.bitbucketServer.getPullRequestsForRepos.bind(
229+
providerApis.bitbucketServer,
230+
) as GetPullRequestsForReposFn,
231+
getPullRequestsForRepoFn: providerApis.bitbucketServer.getPullRequestsForRepo.bind(
232+
providerApis.bitbucketServer,
233+
) as GetPullRequestsForRepoFn,
234+
mergePullRequestFn: providerApis.bitbucketServer.mergePullRequest.bind(
235+
providerApis.bitbucketServer,
236+
) as MergePullRequestFn,
237+
},
220238
[HostingIntegrationId.AzureDevOps]: {
221239
...providersMetadata[HostingIntegrationId.AzureDevOps],
222240
provider: providerApis.azureDevOps,
@@ -592,6 +610,21 @@ export class ProvidersApi {
592610
}
593611
}
594612

613+
async getBitbucketServerPullRequestsForCurrentUser(options?: {
614+
accessToken?: string;
615+
}): Promise<ProviderPullRequest[] | undefined> {
616+
const { provider, token } = await this.ensureProviderTokenAndFunction(
617+
SelfHostedIntegrationId.BitbucketServer,
618+
'getBitbucketServerPullRequestsForCurrentUserFn',
619+
options?.accessToken,
620+
);
621+
try {
622+
return (await provider.getBitbucketServerPullRequestsForCurrentUserFn?.({}, { token: token }))?.data;
623+
} catch (e) {
624+
return this.handleProviderError(SelfHostedIntegrationId.BitbucketServer, token, e);
625+
}
626+
}
627+
595628
async getJiraProjectsForResources(
596629
resourceIds: string[],
597630
options?: { accessToken?: string },

src/plus/integrations/providers/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export function getProviderIdFromEntityIdentifier(
107107
return HostingIntegrationId.AzureDevOps;
108108
case EntityIdentifierProviderType.Bitbucket:
109109
return HostingIntegrationId.Bitbucket;
110+
case EntityIdentifierProviderType.BitbucketServer:
111+
return isGitConfigEntityIdentifier(entityIdentifier) && entityIdentifier.metadata.isCloudEnterprise
112+
? SelfHostedIntegrationId.BitbucketServer
113+
: undefined;
110114
default:
111115
return undefined;
112116
}
@@ -130,6 +134,8 @@ function fromStringToEntityIdentifierProviderType(str: string): EntityIdentifier
130134
return EntityIdentifierProviderType.Azure;
131135
case 'bitbucket':
132136
return EntityIdentifierProviderType.Bitbucket;
137+
case 'bitbucket-server':
138+
return EntityIdentifierProviderType.BitbucketServer;
133139
default:
134140
throw new Error(`Unknown provider type '${str}'`);
135141
}
@@ -231,6 +237,7 @@ export async function getIssueFromGitConfigEntityIdentifier(
231237
identifier.provider !== EntityIdentifierProviderType.GithubEnterprise &&
232238
identifier.provider !== EntityIdentifierProviderType.GitlabSelfHosted &&
233239
identifier.provider !== EntityIdentifierProviderType.Bitbucket &&
240+
identifier.provider !== EntityIdentifierProviderType.BitbucketServer &&
234241
identifier.provider !== EntityIdentifierProviderType.Azure
235242
) {
236243
return undefined;

0 commit comments

Comments
 (0)