Skip to content

Commit 3fcc1f3

Browse files
committed
feat: add bitbucket cloud support
Signed-off-by: Adam Setch <[email protected]>
1 parent 4cb2136 commit 3fcc1f3

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

src/utils/api/client.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
} from '../../typesGitHub';
2525
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions';
2626
import { formatAsGitHubSearchSyntax } from './graphql/utils';
27-
import { apiRequestAuth } from './request';
27+
import { apiRequestAuth, apiRequestBitbucket } from './request';
2828
import { getGitHubAPIBaseUrl, getGitHubGraphQLUrl } from './utils';
2929

3030
/**
@@ -69,6 +69,24 @@ export function listNotificationsForAuthenticatedUser(
6969
return apiRequestAuth(url.toString() as Link, 'GET', account.token);
7070
}
7171

72+
/**
73+
* List all notifications for the current user, sorted by most recently updated.
74+
*
75+
* Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#list-notifications-for-the-authenticated-user
76+
*/
77+
export function listBitbucketWork(
78+
account: Account,
79+
): AxiosPromise<Notification[]> {
80+
const url = `${account.hostname}/overview-view-state?fields=pullRequestFilters.*,pullRequests.authored.links.html,-pullRequests.authored.extra.*`;
81+
82+
return apiRequestBitbucket(
83+
url.toString() as Link,
84+
'GET',
85+
account.user.login,
86+
account.token,
87+
);
88+
}
89+
7290
/**
7391
* Marks a thread as "read." Marking a thread as "read" is equivalent to
7492
* clicking a notification in your notification inbox on GitHub.

src/utils/api/request.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ export function apiRequestAuth(
2424
axios.defaults.headers.common['Content-Type'] = 'application/json';
2525
return axios({ method, url, data });
2626
}
27+
28+
export function apiRequestBitbucket(
29+
url: Link,
30+
method: Method,
31+
username: string,
32+
token: Token,
33+
data = {},
34+
): AxiosPromise | null {
35+
axios.defaults.headers.common.Accept = 'application/json';
36+
axios.defaults.headers.common.Authorization = `Basic ${btoa(`${username}:${token}`)}`;
37+
axios.defaults.headers.common['Cache-Control'] = 'no-cache';
38+
axios.defaults.headers.common['Content-Type'] = 'application/json';
39+
return axios({ method, url, data });
40+
}

src/utils/notifications.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import type {
55
SettingsState,
66
} from '../types';
77
import { Notification } from '../typesGitHub';
8-
import { listNotificationsForAuthenticatedUser } from './api/client';
8+
import {
9+
listBitbucketWork,
10+
listNotificationsForAuthenticatedUser,
11+
} from './api/client';
912
import { determineFailureType } from './api/errors';
1013
import { getAccountUUID } from './auth/utils';
1114
import { hideWindow, showWindow, updateTrayIcon } from './comms';
@@ -116,7 +119,7 @@ function getNotifications(state: GitifyState) {
116119
account,
117120
notifications:
118121
account.platform === 'Bitbucket Cloud'
119-
? null
122+
? listBitbucketWork(account)
120123
: listNotificationsForAuthenticatedUser(account, state.settings),
121124
};
122125
});
@@ -132,22 +135,28 @@ export async function getAllNotifications(
132135
.filter((response) => !!response)
133136
.map(async (accountNotifications) => {
134137
try {
135-
let notifications = (
136-
await accountNotifications.notifications
137-
).data.map((notification: Notification) => ({
138-
...notification,
139-
account: accountNotifications.account,
140-
}));
141-
142-
notifications = await enrichNotifications(notifications, state);
143-
144-
notifications = filterNotifications(notifications, state.settings);
145-
146-
return {
147-
account: accountNotifications.account,
148-
notifications: notifications,
149-
error: null,
150-
};
138+
if (accountNotifications.account.platform === 'Bitbucket Cloud') {
139+
console.log(
140+
JSON.stringify(await accountNotifications.notifications),
141+
);
142+
} else {
143+
let notifications = (
144+
await accountNotifications.notifications
145+
).data.map((notification: Notification) => ({
146+
...notification,
147+
account: accountNotifications.account,
148+
}));
149+
150+
notifications = await enrichNotifications(notifications, state);
151+
152+
notifications = filterNotifications(notifications, state.settings);
153+
154+
return {
155+
account: accountNotifications.account,
156+
notifications: notifications,
157+
error: null,
158+
};
159+
}
151160
} catch (error) {
152161
log.error(
153162
'Error occurred while fetching account notifications',

0 commit comments

Comments
 (0)