diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index 3564e7f29..f9a60b455 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -59,7 +59,7 @@ describe('utils/helpers.ts', () => { it('should generate the GitHub url - non enterprise - (release)', () => testGenerateUrl( `${URL.normal.api}/releases/3988077`, - `${URL.normal.default}/releases?${notificationReferrerId}`, + `${URL.normal.default}/releases/3988077?${notificationReferrerId}`, )); it('should generate the GitHub url - non enterprise - (discussion)', () => @@ -83,7 +83,7 @@ describe('utils/helpers.ts', () => { it('should generate the GitHub url - enterprise - (release)', () => testGenerateUrl( `${URL.enterprise.api}/releases/1`, - `${URL.enterprise.default}/releases?${notificationReferrerId}`, + `${URL.enterprise.default}/releases/1?${notificationReferrerId}`, )); it('should generate the GitHub url - enterprise - (discussion)', () => diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 31e97fb55..708aac3af 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -50,11 +50,6 @@ export function generateGitHubWebUrl( newUrl = newUrl.replace('/pulls/', '/pull/'); } - if (newUrl.indexOf('/releases/') !== -1) { - newUrl = newUrl.replace('/repos', ''); - newUrl = newUrl.substring(0, newUrl.lastIndexOf('/')); - } - if (userId) { const notificationReferrerId = generateNotificationReferrerId( notificationId, @@ -73,6 +68,14 @@ const addHours = (date: string, hours: number) => const queryString = (repo: string, title: string, lastUpdated: string) => `${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`; +async function getReleaseTagWebUrl(notification: Notification, token: string) { + const response = await apiRequestAuth(notification.subject.url, 'GET', token); + + return { + url: response.data.html_url, + }; +} + async function getDiscussionUrl( notification: Notification, token: string, @@ -155,16 +158,15 @@ export async function openInBrowser( notification: Notification, accounts: AuthState, ) { - if (notification.subject.url) { - const latestCommentId = getCommentId( - notification.subject.latest_comment_url, - ); - openExternalLink( - generateGitHubWebUrl( - notification.subject.url, - notification.id, - accounts.user?.id, - latestCommentId ? '#issuecomment-' + latestCommentId : undefined, + if (notification.subject.type === 'Release') { + getReleaseTagWebUrl(notification, accounts.token).then(({ url }) => + openExternalLink( + generateGitHubWebUrl( + url, + notification.id, + accounts.user?.id, + undefined, + ), ), ); } else if (notification.subject.type === 'Discussion') { @@ -181,5 +183,17 @@ export async function openInBrowser( ), ), ); + } else if (notification.subject.url) { + const latestCommentId = getCommentId( + notification.subject.latest_comment_url, + ); + openExternalLink( + generateGitHubWebUrl( + notification.subject.url, + notification.id, + accounts.user?.id, + latestCommentId ? '#issuecomment-' + latestCommentId : undefined, + ), + ); } }