Skip to content

Commit 70a8733

Browse files
authored
Launchpad: add Bitbucket Server support (#44)
* Add support for Bitbucket Server to Launchpad * Update provider-apis package to use PR converter util function
1 parent a847d42 commit 70a8733

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"watch:firefox": "yarn run set-manifest:firefox:force && yarn watch"
4949
},
5050
"dependencies": {
51-
"@gitkraken/provider-apis": "0.22.7",
51+
"@gitkraken/provider-apis": "0.22.8",
5252
"@tanstack/query-async-storage-persister": "5.32.0",
5353
"@tanstack/react-query": "5.32.0",
5454
"@tanstack/react-query-persist-client": "5.32.0",

src/popup/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const useFocusViewConnectedProviders = (userId: string) => {
3737
connection.provider === 'gitlab' ||
3838
connection.provider === 'gitlabSelfHosted' ||
3939
connection.provider === 'bitbucket' ||
40+
connection.provider === 'bitbucketServer' ||
4041
connection.provider === 'azure',
4142
)
4243
.map(connection => connection.provider as FocusViewSupportedProvider);

src/providers.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import type { Account } from '@gitkraken/provider-apis';
12
import {
23
AzureDevOps,
34
Bitbucket,
5+
BitbucketServerUtils,
46
EntityIdentifierProviderType,
57
EntityIdentifierUtils,
68
EntityType,
79
GitHub,
810
GitLab,
911
} from '@gitkraken/provider-apis';
1012
import { fetchProviderToken } from './gkApi';
13+
import { GKDotDevUrl } from './shared';
1114
import type { FocusViewData, FocusViewSupportedProvider, Provider, ProviderToken } from './types';
1215

1316
export const ProviderMeta: Record<FocusViewSupportedProvider, { name: string; iconSrc: string }> = {
@@ -16,6 +19,7 @@ export const ProviderMeta: Record<FocusViewSupportedProvider, { name: string; ic
1619
gitlab: { name: 'GitLab', iconSrc: 'img/gitlab-color.svg' },
1720
gitlabSelfHosted: { name: 'GitLab Self-Managed', iconSrc: 'img/gitlab-color.svg' },
1821
bitbucket: { name: 'Bitbucket', iconSrc: 'img/bitbucket-color.svg' },
22+
bitbucketServer: { name: 'Bitbucket Server', iconSrc: 'img/bitbucket-color.svg' },
1923
azure: { name: 'Azure DevOps', iconSrc: 'img/azuredevops-color.svg' },
2024
};
2125

@@ -57,6 +61,7 @@ const fetchGitLabFocusViewData = async (token: ProviderToken) => {
5761

5862
const { data: pullRequests } = await gitlab.getPullRequestsAssociatedWithUser({
5963
username: providerUser.username,
64+
includeFromArchivedRepos: false,
6065
});
6166

6267
return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uuid: '' })) };
@@ -74,6 +79,34 @@ const fetchBitbucketFocusViewData = async (token: ProviderToken) => {
7479
return { providerUser: providerUser, pullRequests: pullRequests.map(pr => ({ ...pr, uuid: '' })) };
7580
};
7681

82+
const fetchBitbucketServerFocusViewData = async (token: ProviderToken) => {
83+
// Bitbucket Server does not have the CORS header set to be able to make requests from the browser,
84+
// so we proxy the request through the API.
85+
const res = await fetch(`${GKDotDevUrl}/api/provider/bitbucket-server/proxy`, {
86+
headers: {
87+
Authorization: `Bearer ${token.accessToken}`,
88+
XDestination: `${token.domain}/rest/api/latest/dashboard/pull-requests`,
89+
},
90+
});
91+
92+
if (!res.ok) {
93+
throw new Error('Failed to fetch Bitbucket Server pull requests');
94+
}
95+
96+
const data = await res.json();
97+
98+
return {
99+
providerUser: data.user as Account,
100+
pullRequests: (data.body.values as any[]).map(pullRequest => ({
101+
...BitbucketServerUtils.restApiPullRequestToCommonPullRequest(pullRequest),
102+
// Bitbucket Server PR ids are just the number, they are not unique across repos, so instead
103+
// we use the PR url as the id.
104+
id: pullRequest.links.self[0].href,
105+
uuid: '',
106+
})),
107+
};
108+
};
109+
77110
const fetchAzureFocusViewData = async (token: ProviderToken) => {
78111
const azureDevOps = new AzureDevOps({ token: token.accessToken });
79112

@@ -109,6 +142,8 @@ export const fetchFocusViewData = async (provider: FocusViewSupportedProvider):
109142
return fetchGitLabFocusViewData(providerToken);
110143
case 'bitbucket':
111144
return fetchBitbucketFocusViewData(providerToken);
145+
case 'bitbucketServer':
146+
return fetchBitbucketServerFocusViewData(providerToken);
112147
case 'azure':
113148
return fetchAzureFocusViewData(providerToken);
114149
default:

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ export type Provider =
2121
| 'jira'
2222
| 'trello'
2323
| 'githubEnterprise'
24-
| 'gitlabSelfHosted';
24+
| 'gitlabSelfHosted'
25+
| 'bitbucketServer';
2526

2627
export type FocusViewSupportedProvider =
2728
| 'github'
2829
| 'githubEnterprise'
2930
| 'gitlab'
3031
| 'gitlabSelfHosted'
3132
| 'bitbucket'
33+
| 'bitbucketServer'
3234
| 'azure';
3335

3436
export type PullRequestDraftCounts = Record<string, { count: number } | undefined>;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@
285285
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af"
286286
integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==
287287

288-
"@gitkraken/[email protected].7":
289-
version "0.22.7"
290-
resolved "https://registry.npmjs.org/@gitkraken/provider-apis/-/provider-apis-0.22.7.tgz#f217e1d275b578c33a38ce03564a10ee6b6b3e2c"
291-
integrity sha512-twLjzIahStD4FkI10UxxikLLocE0r9IkX2qPjZiBfhyZbGKVdnFEdYdbZaeKOxTt87T6LyTPhdGnRLMrZfCWpA==
288+
"@gitkraken/[email protected].8":
289+
version "0.22.8"
290+
resolved "https://registry.npmjs.org/@gitkraken/provider-apis/-/provider-apis-0.22.8.tgz#5e70e00b94a386275b141fb42b055c7124adce15"
291+
integrity sha512-i2/+gC1j940zjS8rn124HYPLXa7O8t3i5PbLNNB6Xp+wFCTmLeILkcuIFAV1xH1291KoqaWY0HJMZlsmpdo7ww==
292292
dependencies:
293293
js-base64 "3.7.5"
294294
node-fetch "2.7.0"

0 commit comments

Comments
 (0)