Skip to content

Commit 24887d6

Browse files
authored
feat: link workflow run notifications to actions (#859)
1 parent aaf0107 commit 24887d6

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/utils/helpers.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,75 @@ describe('utils/helpers.ts', () => {
310310
);
311311
});
312312

313+
describe('Workflow Run URLs', () => {
314+
it('approval requested', async () => {
315+
const subject = {
316+
title: 'some-user requested your review to deploy to an environment',
317+
url: null,
318+
latest_comment_url: null,
319+
type: 'WorkflowRun' as SubjectType,
320+
};
321+
322+
const result = await generateGitHubWebUrl(
323+
{
324+
...mockedSingleNotification,
325+
subject: subject,
326+
},
327+
mockAccounts,
328+
);
329+
330+
expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
331+
expect(result).toBe(
332+
`https://github.com/manosim/notifications-test/actions?query=is%3Awaiting&${mockedNotificationReferrer}`,
333+
);
334+
});
335+
336+
it('unhandled status/action scenario', async () => {
337+
const subject = {
338+
title:
339+
'some-user requested your unhandled-action to deploy to an environment',
340+
url: null,
341+
latest_comment_url: null,
342+
type: 'WorkflowRun' as SubjectType,
343+
};
344+
345+
const result = await generateGitHubWebUrl(
346+
{
347+
...mockedSingleNotification,
348+
subject: subject,
349+
},
350+
mockAccounts,
351+
);
352+
353+
expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
354+
expect(result).toBe(
355+
`https://github.com/manosim/notifications-test/actions?${mockedNotificationReferrer}`,
356+
);
357+
});
358+
359+
it('unhandled workflow scenario', async () => {
360+
const subject = {
361+
title: 'some unhandled scenario',
362+
url: null,
363+
latest_comment_url: null,
364+
type: 'WorkflowRun' as SubjectType,
365+
};
366+
367+
const result = await generateGitHubWebUrl(
368+
{
369+
...mockedSingleNotification,
370+
subject: subject,
371+
},
372+
mockAccounts,
373+
);
374+
375+
expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
376+
expect(result).toBe(
377+
`https://github.com/manosim/notifications-test/actions?${mockedNotificationReferrer}`,
378+
);
379+
});
380+
});
381+
313382
it('defaults to repository url', async () => {
314383
const subject = {
315384
title: 'generate github web url unit tests',

src/utils/helpers.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { apiRequestAuth } from '../utils/api-requests';
99
import { openExternalLink } from '../utils/comms';
1010
import { Constants } from './constants';
11+
import { getWorkflowRunAttributes } from './state';
1112

1213
export function getEnterpriseAccountToken(
1314
hostname: string,
@@ -70,6 +71,23 @@ export async function getHtmlUrl(url: string, token: string): Promise<string> {
7071
return response.data.html_url;
7172
}
7273

74+
export function getWorkflowRunUrl(notification: Notification) {
75+
let url = `${notification.repository.html_url}/actions`;
76+
let filters = [];
77+
78+
const workflowRunAttributes = getWorkflowRunAttributes(notification);
79+
80+
if (workflowRunAttributes?.status) {
81+
filters.push(`is:${workflowRunAttributes.status}`);
82+
}
83+
84+
if (filters.length > 0) {
85+
url += `?query=${filters.join('+')}`;
86+
}
87+
88+
return url;
89+
}
90+
7391
async function getDiscussionUrl(
7492
notification: Notification,
7593
token: string,
@@ -167,6 +185,9 @@ export async function generateGitHubWebUrl(
167185
case 'RepositoryInvitation':
168186
url = `${notification.repository.html_url}/invitations`;
169187
break;
188+
case 'WorkflowRun':
189+
url = getWorkflowRunUrl(notification);
190+
break;
170191
default:
171192
url = notification.repository.html_url;
172193
break;

0 commit comments

Comments
 (0)