Repository: gitify-app/gitify
Pull request #859 (2024-03-06 20:48:57)

feat: link workflow run notifications to actions
Closes https://github.com/gitify-app/gitify/issues/526


Patch:
diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts
index 2ccdbe9b..20353d6d 100644
--- a/src/utils/helpers.ts
+++ b/src/utils/helpers.ts
@@ -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,
@@ -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,
@@ -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;


Test patch:
diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts
index 8cef1c3c..c4473f22 100644
--- a/src/utils/helpers.test.ts
+++ b/src/utils/helpers.test.ts
@@ -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',