Skip to content

feat: link workflow run notifications to actions #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,75 @@ describe('utils/helpers.ts', () => {
);
});

describe('Workflow Run URLs', () => {
it('approval requested', async () => {
const subject = {
title: 'some-user requested your review to deploy to an environment',
url: null,
latest_comment_url: null,
type: 'WorkflowRun' as SubjectType,
};

const result = await generateGitHubWebUrl(
{
...mockedSingleNotification,
subject: subject,
},
mockAccounts,
);

expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
expect(result).toBe(
`https://github.com/manosim/notifications-test/actions?query=is%3Awaiting&${mockedNotificationReferrer}`,
);
});

it('unhandled status/action scenario', async () => {
const subject = {
title:
'some-user requested your unhandled-action to deploy to an environment',
url: null,
latest_comment_url: null,
type: 'WorkflowRun' as SubjectType,
};

const result = await generateGitHubWebUrl(
{
...mockedSingleNotification,
subject: subject,
},
mockAccounts,
);

expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
expect(result).toBe(
`https://github.com/manosim/notifications-test/actions?${mockedNotificationReferrer}`,
);
});

it('unhandled workflow scenario', async () => {
const subject = {
title: 'some unhandled scenario',
url: null,
latest_comment_url: null,
type: 'WorkflowRun' as SubjectType,
};

const result = await generateGitHubWebUrl(
{
...mockedSingleNotification,
subject: subject,
},
mockAccounts,
);

expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
expect(result).toBe(
`https://github.com/manosim/notifications-test/actions?${mockedNotificationReferrer}`,
);
});
});

it('defaults to repository url', async () => {
const subject = {
title: 'generate github web url unit tests',
Expand Down
21 changes: 21 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { apiRequestAuth } from '../utils/api-requests';
import { openExternalLink } from '../utils/comms';
import { Constants } from './constants';
import { getWorkflowRunAttributes } from './state';

export function getEnterpriseAccountToken(
hostname: string,
Expand Down Expand Up @@ -70,6 +71,23 @@ export async function getHtmlUrl(url: string, token: string): Promise<string> {
return response.data.html_url;
}

export function getWorkflowRunUrl(notification: Notification) {
let url = `${notification.repository.html_url}/actions`;
let filters = [];

const workflowRunAttributes = getWorkflowRunAttributes(notification);

if (workflowRunAttributes?.status) {
filters.push(`is:${workflowRunAttributes.status}`);
}

if (filters.length > 0) {
url += `?query=${filters.join('+')}`;
}

return url;
}

async function getDiscussionUrl(
notification: Notification,
token: string,
Expand Down Expand Up @@ -167,6 +185,9 @@ export async function generateGitHubWebUrl(
case 'RepositoryInvitation':
url = `${notification.repository.html_url}/invitations`;
break;
case 'WorkflowRun':
url = getWorkflowRunUrl(notification);
break;
default:
url = notification.repository.html_url;
break;
Expand Down