Skip to content

Commit fdfa570

Browse files
authored
feat: support repository invitation links (#812)
1 parent 41d6d3f commit fdfa570

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/utils/helpers.test.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('utils/helpers.ts', () => {
152152
describe('generateGitHubWebUrl', () => {
153153
const mockedHtmlUrl = 'https://github.com/gitify-app/gitify/issues/785';
154154
const mockedNotificationReferrer =
155-
'?notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D';
155+
'notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D';
156156
const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth');
157157

158158
afterEach(() => {
@@ -192,7 +192,7 @@ describe('utils/helpers.ts', () => {
192192
'GET',
193193
mockAccounts.token,
194194
);
195-
expect(result).toBe(`${mockedHtmlUrl}${mockedNotificationReferrer}`);
195+
expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`);
196196
});
197197

198198
it('Subject Url: when no latest comment url available, fetch subject html url', async () => {
@@ -227,7 +227,7 @@ describe('utils/helpers.ts', () => {
227227
'GET',
228228
mockAccounts.token,
229229
);
230-
expect(result).toBe(`${mockedHtmlUrl}${mockedNotificationReferrer}`);
230+
expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`);
231231
});
232232

233233
it('Discussions: when no subject urls and no discussions found via query, default to linking to repository discussions', async () => {
@@ -256,7 +256,7 @@ describe('utils/helpers.ts', () => {
256256

257257
expect(apiRequestAuthMock).toHaveBeenCalledTimes(1);
258258
expect(result).toBe(
259-
`${mockedSingleNotification.repository.html_url}/discussions${mockedNotificationReferrer}`,
259+
`${mockedSingleNotification.repository.html_url}/discussions?${mockedNotificationReferrer}`,
260260
);
261261
});
262262

@@ -268,8 +268,6 @@ describe('utils/helpers.ts', () => {
268268
type: 'Discussion' as SubjectType,
269269
};
270270

271-
// const latestDiscussionCommentId = 12345;
272-
273271
const requestPromise = new Promise((resolve) =>
274272
resolve(mockedGraphQLResponse as AxiosResponse),
275273
) as AxiosPromise;
@@ -286,7 +284,29 @@ describe('utils/helpers.ts', () => {
286284

287285
expect(apiRequestAuthMock).toHaveBeenCalledTimes(1);
288286
expect(result).toBe(
289-
'https://github.com/manosim/notifications-test/discussions/612?notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D#discussioncomment-2300902',
287+
`https://github.com/manosim/notifications-test/discussions/612?${mockedNotificationReferrer}#discussioncomment-2300902`,
288+
);
289+
});
290+
291+
it('Repository Invitation url', async () => {
292+
const subject = {
293+
title: 'Invitation to join manosim/notifications-test from unit-tests',
294+
url: null,
295+
latest_comment_url: null,
296+
type: 'RepositoryInvitation' as SubjectType,
297+
};
298+
299+
const result = await generateGitHubWebUrl(
300+
{
301+
...mockedSingleNotification,
302+
subject: subject,
303+
},
304+
mockAccounts,
305+
);
306+
307+
expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
308+
expect(result).toBe(
309+
`https://github.com/manosim/notifications-test/invitations?${mockedNotificationReferrer}`,
290310
);
291311
});
292312

@@ -308,7 +328,7 @@ describe('utils/helpers.ts', () => {
308328

309329
expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
310330
expect(result).toBe(
311-
`${mockedSingleNotification.repository.html_url}${mockedNotificationReferrer}`,
331+
`${mockedSingleNotification.repository.html_url}?${mockedNotificationReferrer}`,
312332
);
313333
});
314334
});

src/utils/helpers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ export async function generateGitHubWebUrl(
167167
case 'Discussion':
168168
url = await getDiscussionUrl(notification, accounts.token);
169169
break;
170+
case 'RepositoryInvitation':
171+
url = `${notification.repository.html_url}/invitations`;
172+
break;
170173
default:
171174
url = notification.repository.html_url;
172175
break;

0 commit comments

Comments
 (0)