Skip to content

Commit 76d4211

Browse files
authored
feat: link to release tag (#707)
1 parent 1bf7f3f commit 76d4211

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/utils/helpers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('utils/helpers.ts', () => {
5959
it('should generate the GitHub url - non enterprise - (release)', () =>
6060
testGenerateUrl(
6161
`${URL.normal.api}/releases/3988077`,
62-
`${URL.normal.default}/releases?${notificationReferrerId}`,
62+
`${URL.normal.default}/releases/3988077?${notificationReferrerId}`,
6363
));
6464

6565
it('should generate the GitHub url - non enterprise - (discussion)', () =>
@@ -83,7 +83,7 @@ describe('utils/helpers.ts', () => {
8383
it('should generate the GitHub url - enterprise - (release)', () =>
8484
testGenerateUrl(
8585
`${URL.enterprise.api}/releases/1`,
86-
`${URL.enterprise.default}/releases?${notificationReferrerId}`,
86+
`${URL.enterprise.default}/releases/1?${notificationReferrerId}`,
8787
));
8888

8989
it('should generate the GitHub url - enterprise - (discussion)', () =>

src/utils/helpers.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ export function generateGitHubWebUrl(
5050
newUrl = newUrl.replace('/pulls/', '/pull/');
5151
}
5252

53-
if (newUrl.indexOf('/releases/') !== -1) {
54-
newUrl = newUrl.replace('/repos', '');
55-
newUrl = newUrl.substring(0, newUrl.lastIndexOf('/'));
56-
}
57-
5853
if (userId) {
5954
const notificationReferrerId = generateNotificationReferrerId(
6055
notificationId,
@@ -73,6 +68,14 @@ const addHours = (date: string, hours: number) =>
7368
const queryString = (repo: string, title: string, lastUpdated: string) =>
7469
`${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`;
7570

71+
async function getReleaseTagWebUrl(notification: Notification, token: string) {
72+
const response = await apiRequestAuth(notification.subject.url, 'GET', token);
73+
74+
return {
75+
url: response.data.html_url,
76+
};
77+
}
78+
7679
async function getDiscussionUrl(
7780
notification: Notification,
7881
token: string,
@@ -155,16 +158,15 @@ export async function openInBrowser(
155158
notification: Notification,
156159
accounts: AuthState,
157160
) {
158-
if (notification.subject.url) {
159-
const latestCommentId = getCommentId(
160-
notification.subject.latest_comment_url,
161-
);
162-
openExternalLink(
163-
generateGitHubWebUrl(
164-
notification.subject.url,
165-
notification.id,
166-
accounts.user?.id,
167-
latestCommentId ? '#issuecomment-' + latestCommentId : undefined,
161+
if (notification.subject.type === 'Release') {
162+
getReleaseTagWebUrl(notification, accounts.token).then(({ url }) =>
163+
openExternalLink(
164+
generateGitHubWebUrl(
165+
url,
166+
notification.id,
167+
accounts.user?.id,
168+
undefined,
169+
),
168170
),
169171
);
170172
} else if (notification.subject.type === 'Discussion') {
@@ -181,5 +183,17 @@ export async function openInBrowser(
181183
),
182184
),
183185
);
186+
} else if (notification.subject.url) {
187+
const latestCommentId = getCommentId(
188+
notification.subject.latest_comment_url,
189+
);
190+
openExternalLink(
191+
generateGitHubWebUrl(
192+
notification.subject.url,
193+
notification.id,
194+
accounts.user?.id,
195+
latestCommentId ? '#issuecomment-' + latestCommentId : undefined,
196+
),
197+
);
184198
}
185199
}

0 commit comments

Comments
 (0)