From 59afabb37860a5d8afefe8c2eebd6a79bb754c25 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 30 May 2024 23:03:10 -0400 Subject: [PATCH 01/15] feat: labels indicator --- src/components/NotificationRow.tsx | 12 ++++++++++++ src/typesGitHub.ts | 23 +++++++++++++++++++++++ src/utils/api/__mocks__/response-mocks.ts | 10 ++++++++++ src/utils/api/graphql/discussions.ts | 5 +++++ src/utils/subject.test.ts | 1 + src/utils/subject.ts | 3 +++ 6 files changed, 54 insertions(+) diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index b322f0fe2..4f4449add 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -4,6 +4,7 @@ import { CommentIcon, FeedPersonIcon, ReadIcon, + TagIcon, } from '@primer/octicons-react'; import { type FC, @@ -90,6 +91,8 @@ export const NotificationRow: FC = ({ notification, hostname }) => { notification.subject.comments > 1 ? 'comments' : 'comment' }`; + const labelsLabel = notification.subject?.labels?.join('\n'); + return (
= ({ notification, hostname }) => { /> )} + {notification.subject?.labels?.length > 0 && ( + + + + )}
diff --git a/src/typesGitHub.ts b/src/typesGitHub.ts index ea86008b8..84379fc98 100644 --- a/src/typesGitHub.ts +++ b/src/typesGitHub.ts @@ -258,6 +258,7 @@ export interface GitifySubject { user?: SubjectUser; reviews?: GitifyPullRequestReview[]; comments?: number; + labels?: string[]; } export interface PullRequest { @@ -279,6 +280,8 @@ export interface PullRequest { closed_at: string | null; merged_at: string | null; merge_commit_sha: string | null; + labels: Labels[]; + milestone: string | null; draft: boolean; commits_url: string; review_comments_url: string; @@ -303,6 +306,16 @@ export interface GitifyPullRequestReview { users: string[]; } +export interface Labels { + id: number; + node_id: string; + url: string; + name: string; + color: string; + default: boolean; + description: string; +} + export interface PullRequestReview { id: number; node_id: string; @@ -408,6 +421,7 @@ export interface Issue { author_association: string; body: string; state_reason: IssueStateReasonType | null; + labels: Labels[]; } export interface IssueOrPullRequestComment { @@ -455,6 +469,15 @@ export interface Discussion { url: string; author: DiscussionAuthor; comments: DiscussionComments; + labels: DiscussionLabels; +} + +export interface DiscussionLabels { + nodes: DiscussionLabel[]; +} + +export interface DiscussionLabel { + name: string; } export interface DiscussionComments { diff --git a/src/utils/api/__mocks__/response-mocks.ts b/src/utils/api/__mocks__/response-mocks.ts index dcaf441b5..750f96af3 100644 --- a/src/utils/api/__mocks__/response-mocks.ts +++ b/src/utils/api/__mocks__/response-mocks.ts @@ -2,6 +2,7 @@ import type { Discussion, DiscussionAuthor, DiscussionComments, + DiscussionLabels, GraphQLSearch, Notification, Repository, @@ -385,6 +386,14 @@ export const mockDiscussionComments: DiscussionComments = { totalCount: 2, }; +export const mockDiscussionLabels: DiscussionLabels = { + nodes: [ + { + name: 'enhancement', + }, + ], +}; + export const mockGraphQLResponse: GraphQLSearch = { data: { search: { @@ -401,6 +410,7 @@ export const mockGraphQLResponse: GraphQLSearch = { type: 'User', }, comments: mockDiscussionComments, + labels: mockDiscussionLabels, }, ], }, diff --git a/src/utils/api/graphql/discussions.ts b/src/utils/api/graphql/discussions.ts index 7472f10a0..ab34a9001 100644 --- a/src/utils/api/graphql/discussions.ts +++ b/src/utils/api/graphql/discussions.ts @@ -49,6 +49,11 @@ export const QUERY_SEARCH_DISCUSSIONS = gql` } } } + labels { + nodes { + name + } + } } } } diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index df8930784..f29beb413 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -1164,5 +1164,6 @@ function mockDiscussionNode( nodes: [], totalCount: 0, }, + labels: null, }; } diff --git a/src/utils/subject.ts b/src/utils/subject.ts index d899e7eac..ee53d3eea 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -182,6 +182,7 @@ async function getGitifySubjectForDiscussion( state: discussionState, user: discussionUser, comments: discussion.comments.totalCount, + labels: discussion.labels?.nodes.map((label) => label.name), }; } @@ -228,6 +229,7 @@ async function getGitifySubjectForIssue( type: issueCommentUser?.type ?? issue.user.type, }, comments: issue.comments, + labels: issue.labels.map((label) => label.name), }; } @@ -271,6 +273,7 @@ async function getGitifySubjectForPullRequest( }, reviews: reviews, comments: pr.comments, + labels: pr.labels.map((label) => label.name), }; } From 20333ec354537ee17f558d8a33f1a9354a12f3c2 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 15:35:21 -0500 Subject: [PATCH 02/15] format as pill --- src/components/NotificationRow.tsx | 20 +++++++++++++------- src/utils/constants.ts | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index 4f4449add..6fc927b2e 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -18,6 +18,7 @@ import { AppContext } from '../context/App'; import { IconColor } from '../types'; import type { Notification } from '../typesGitHub'; import { openExternalLink } from '../utils/comms'; +import Constants from '../utils/constants'; import { formatForDisplay, formatNotificationUpdatedAt, @@ -91,7 +92,9 @@ export const NotificationRow: FC = ({ notification, hostname }) => { notification.subject.comments > 1 ? 'comments' : 'comment' }`; - const labelsLabel = notification.subject?.labels?.join('\n'); + const labelsPillDescription = `Labels:\n${notification.subject.labels + ?.map((label) => ` - ${label}`) + .join('\n')}`; return (
= ({ notification, hostname }) => { )} {notification.subject?.labels?.length > 0 && ( - - + + )} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index c6a92a41d..a7295819e 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -24,6 +24,9 @@ export const Constants = { READ_CLASS_NAME: 'opacity-50 dark:opacity-50', + PILL_CLASS_NAME: + 'rounded-full text-xs px-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700', + // GitHub Docs GITHUB_DOCS: { OAUTH_URL: From 4990f26b99e6c94807ced154f627c6bfb9de02ef Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 15:43:53 -0500 Subject: [PATCH 03/15] update tests --- src/utils/subject.test.ts | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index f29beb413..bd9006b22 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -257,6 +257,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); @@ -285,6 +286,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); @@ -313,6 +315,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); @@ -341,6 +344,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); @@ -369,6 +373,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); @@ -397,6 +402,7 @@ describe('utils/subject.ts', () => { type: mockDiscussionAuthor.type, }, comments: 0, + labels: [], }); }); }); @@ -416,7 +422,7 @@ describe('utils/subject.ts', () => { it('open issue state', async () => { nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/1') - .reply(200, { state: 'open', user: mockAuthor }); + .reply(200, { state: 'open', user: mockAuthor, labels: [] }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/comments/302888448') @@ -435,13 +441,14 @@ describe('utils/subject.ts', () => { avatar_url: mockCommenter.avatar_url, type: mockCommenter.type, }, + labels: [], }); }); it('closed issue state', async () => { nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/1') - .reply(200, { state: 'closed', user: mockAuthor }); + .reply(200, { state: 'closed', user: mockAuthor, labels: [] }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/comments/302888448') @@ -460,6 +467,7 @@ describe('utils/subject.ts', () => { avatar_url: mockCommenter.avatar_url, type: mockCommenter.type, }, + labels: [], }); }); @@ -470,6 +478,7 @@ describe('utils/subject.ts', () => { state: 'closed', state_reason: 'completed', user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -489,6 +498,7 @@ describe('utils/subject.ts', () => { avatar_url: mockCommenter.avatar_url, type: mockCommenter.type, }, + labels: [], }); }); @@ -499,6 +509,7 @@ describe('utils/subject.ts', () => { state: 'open', state_reason: 'not_planned', user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -518,6 +529,7 @@ describe('utils/subject.ts', () => { avatar_url: mockCommenter.avatar_url, type: mockCommenter.type, }, + labels: [], }); }); @@ -528,6 +540,7 @@ describe('utils/subject.ts', () => { state: 'open', state_reason: 'reopened', user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -547,6 +560,7 @@ describe('utils/subject.ts', () => { avatar_url: mockCommenter.avatar_url, type: mockCommenter.type, }, + labels: [], }); }); @@ -560,6 +574,7 @@ describe('utils/subject.ts', () => { draft: false, merged: false, user: mockAuthor, + labels: [], }); const result = await getGitifySubjectDetails( @@ -575,6 +590,7 @@ describe('utils/subject.ts', () => { avatar_url: mockAuthor.avatar_url, type: mockAuthor.type, }, + labels: [], }); }); }); @@ -600,6 +616,7 @@ describe('utils/subject.ts', () => { draft: false, merged: false, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -624,6 +641,7 @@ describe('utils/subject.ts', () => { type: mockCommenter.type, }, reviews: null, + labels: [], }); }); @@ -635,6 +653,7 @@ describe('utils/subject.ts', () => { draft: true, merged: false, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -659,6 +678,7 @@ describe('utils/subject.ts', () => { type: mockCommenter.type, }, reviews: null, + labels: [], }); }); @@ -670,6 +690,7 @@ describe('utils/subject.ts', () => { draft: false, merged: true, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -694,6 +715,7 @@ describe('utils/subject.ts', () => { type: mockCommenter.type, }, reviews: null, + labels: [], }); }); @@ -705,6 +727,7 @@ describe('utils/subject.ts', () => { draft: false, merged: false, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -729,6 +752,7 @@ describe('utils/subject.ts', () => { type: mockCommenter.type, }, reviews: null, + labels: [], }); }); @@ -743,6 +767,7 @@ describe('utils/subject.ts', () => { draft: false, merged: false, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -763,6 +788,7 @@ describe('utils/subject.ts', () => { type: mockAuthor.type, }, reviews: null, + labels: [], }); }); @@ -776,6 +802,7 @@ describe('utils/subject.ts', () => { draft: false, merged: false, user: mockAuthor, + labels: [], }); nock('https://api.github.com') @@ -796,6 +823,7 @@ describe('utils/subject.ts', () => { type: mockAuthor.type, }, reviews: null, + labels: [], }); }); @@ -1164,6 +1192,8 @@ function mockDiscussionNode( nodes: [], totalCount: 0, }, - labels: null, + labels: { + nodes: [], + }, }; } From 00929be793a010e17951d7e9c2d32989f643aa91 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 15:47:16 -0500 Subject: [PATCH 04/15] update tests --- src/utils/subject.test.ts | 4 +--- src/utils/subject.ts | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index bd9006b22..8e37f24e6 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -1192,8 +1192,6 @@ function mockDiscussionNode( nodes: [], totalCount: 0, }, - labels: { - nodes: [], - }, + labels: null, }; } diff --git a/src/utils/subject.ts b/src/utils/subject.ts index ee53d3eea..77c6f1f04 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -182,7 +182,9 @@ async function getGitifySubjectForDiscussion( state: discussionState, user: discussionUser, comments: discussion.comments.totalCount, - labels: discussion.labels?.nodes.map((label) => label.name), + labels: discussion.labels + ? discussion.labels.nodes.map((label) => label.name) + : [], }; } From d7ba8c55f661162a5cb3bc6f348549fe2ea37437 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 15:50:15 -0500 Subject: [PATCH 05/15] update tests --- src/components/NotificationRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index 6fc927b2e..f05f70201 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -93,7 +93,7 @@ export const NotificationRow: FC = ({ notification, hostname }) => { }`; const labelsPillDescription = `Labels:\n${notification.subject.labels - ?.map((label) => ` - ${label}`) + ?.map((label) => ` • ${label}`) .join('\n')}`; return ( From 1b93c6aad792f884ff443d755774652e01dc296a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 15:58:19 -0500 Subject: [PATCH 06/15] update tests --- src/components/NotificationRow.test.tsx | 19 + .../NotificationRow.test.tsx.snap | 535 ++++++++++++++++++ 2 files changed, 554 insertions(+) diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 7a2a05484..df2409eaf 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -117,6 +117,25 @@ describe('components/NotificationRow.tsx', () => { }); }); + describe('notification labels', () => { + it('should render labels metric when available', async () => { + jest + .spyOn(global.Date, 'now') + .mockImplementation(() => new Date('2024').valueOf()); + + const mockNotification = mockSingleNotification; + mockNotification.subject.labels = ['enhancement', 'good-first-issue']; + + const props = { + notification: mockNotification, + hostname: 'github.com', + }; + + const tree = render(); + expect(tree).toMatchSnapshot(); + }); + }); + describe('notification interactions', () => { it('should open a notification in the browser - click', () => { const removeNotificationFromState = jest.fn(); diff --git a/src/components/__snapshots__/NotificationRow.test.tsx.snap b/src/components/__snapshots__/NotificationRow.test.tsx.snap index 6b24aaae0..f11befe9c 100644 --- a/src/components/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/components/__snapshots__/NotificationRow.test.tsx.snap @@ -1,5 +1,540 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components/NotificationRow.tsx notification labels should render labels metric when available 1`] = ` +{ + "asFragment": [Function], + "baseElement": +
+
+
+ + + + +
+
+
+ I am a robot and this is a test! +
+
+ + + + + + + Updated + + + over 6 years ago + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+ , + "container":
+
+
+ + + + +
+
+
+ I am a robot and this is a test! +
+
+ + + + + + + Updated + + + over 6 years ago + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; + exports[`components/NotificationRow.tsx rendering for notification comments count should render when 1 comment 1`] = ` { "asFragment": [Function], From e20b3ae0164e1105c8e44962439fcbb624a04ad2 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 17:10:15 -0500 Subject: [PATCH 07/15] update tests --- src/utils/subject.test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index 8e37f24e6..c3ef32f18 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -405,6 +405,43 @@ describe('utils/subject.ts', () => { labels: [], }); }); + + it('discussion with labels', async () => { + const mockDiscussion = mockDiscussionNode(null, true); + mockDiscussion.labels = { + nodes: [ + { + name: 'enhancement', + }, + ], + }; + nock('https://api.github.com') + .post('/graphql') + .reply(200, { + data: { + search: { + nodes: [mockDiscussion], + }, + }, + }); + + const result = await getGitifySubjectDetails( + mockNotification, + mockAuth.token, + ); + + expect(result).toEqual({ + state: 'ANSWERED', + user: { + login: mockDiscussionAuthor.login, + html_url: mockDiscussionAuthor.url, + avatar_url: mockDiscussionAuthor.avatar_url, + type: mockDiscussionAuthor.type, + }, + comments: 0, + labels: ['enhancement'], + }); + }); }); describe('Issues', () => { From c0cb825130ed3f33049870d4e01c814eaece16e1 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 2 Jun 2024 17:13:25 -0500 Subject: [PATCH 08/15] update tests --- src/components/NotificationRow.tsx | 2 +- .../__snapshots__/NotificationRow.test.tsx.snap | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index f05f70201..289e06176 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -93,7 +93,7 @@ export const NotificationRow: FC = ({ notification, hostname }) => { }`; const labelsPillDescription = `Labels:\n${notification.subject.labels - ?.map((label) => ` • ${label}`) + ?.map((label) => `🏷️ ${label}`) .join('\n')}`; return ( diff --git a/src/components/__snapshots__/NotificationRow.test.tsx.snap b/src/components/__snapshots__/NotificationRow.test.tsx.snap index f11befe9c..7f92e1343 100644 --- a/src/components/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/components/__snapshots__/NotificationRow.test.tsx.snap @@ -142,8 +142,8 @@ exports[`components/NotificationRow.tsx notification labels should render labels - - - + + + + 1 + - - - + + + + 2 + - - - + + + + 1 + - - - + + + + 1 + - - - + + + + 2 + { }, }); - const result = await getGitifySubjectDetails( - mockNotification, - mockAuth.token, - ); + const result = await getGitifySubjectDetails(mockNotification); expect(result).toEqual({ state: 'ANSWERED', @@ -580,10 +577,7 @@ describe('utils/subject.ts', () => { .get('/repos/gitify-app/notifications-test/issues/comments/302888448') .reply(200, { user: mockCommenter }); - const result = await getGitifySubjectDetails( - mockNotification, - mockAuth.token, - ); + const result = await getGitifySubjectDetails(mockNotification); expect(result).toEqual({ state: 'open', @@ -889,10 +883,7 @@ describe('utils/subject.ts', () => { .get('/repos/gitify-app/notifications-test/pulls/1/reviews') .reply(200, []); - const result = await getGitifySubjectDetails( - mockNotification, - mockAuth.token, - ); + const result = await getGitifySubjectDetails(mockNotification); expect(result).toEqual({ state: 'open', From 24438432da86906f3f5bcc363f0ed7eaf22d4ae9 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 3 Jun 2024 19:59:30 -0400 Subject: [PATCH 12/15] Merge remote-tracking branch 'origin/main' into feature/labels-indicator --- src/typesGitHub.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/typesGitHub.ts b/src/typesGitHub.ts index ceb3acd6b..cf4c7177f 100644 --- a/src/typesGitHub.ts +++ b/src/typesGitHub.ts @@ -289,7 +289,6 @@ export interface PullRequest { merged_at: string | null; merge_commit_sha: string | null; labels: Labels[]; - milestone: string | null; draft: boolean; commits_url: string; review_comments_url: string; From a4b89bd94bcbae6e1489e43bda62f13358a43fac Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 3 Jun 2024 20:34:12 -0400 Subject: [PATCH 13/15] add null handling --- src/utils/subject.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/subject.ts b/src/utils/subject.ts index 451c13307..ffbc3736d 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -184,9 +184,7 @@ async function getGitifySubjectForDiscussion( state: discussionState, user: discussionUser, comments: discussion.comments.totalCount, - labels: discussion.labels - ? discussion.labels.nodes.map((label) => label.name) - : [], + labels: discussion.labels?.nodes.map((label) => label.name) ?? [], }; } @@ -234,7 +232,7 @@ async function getGitifySubjectForIssue( type: issueCommentUser?.type ?? issue.user.type, }, comments: issue.comments, - labels: issue.labels.map((label) => label.name), + labels: issue.labels?.map((label) => label.name) ?? [], }; } @@ -280,7 +278,7 @@ async function getGitifySubjectForPullRequest( }, reviews: reviews, comments: pr.comments, - labels: pr.labels.map((label) => label.name), + labels: pr.labels?.map((label) => label.name) ?? [], linkedIssues: linkedIssues, }; } From 7f512287e3db98db24aa9ff3a81c6e1ff58df8c5 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 3 Jun 2024 20:40:14 -0400 Subject: [PATCH 14/15] update mocks --- src/hooks/useNotifications.test.ts | 3 +++ src/typesGitHub.ts | 2 +- src/utils/subject.ts | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 7d55d3325..cf33a3b79 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -225,6 +225,7 @@ describe('hooks/useNotifications.ts', () => { }, ], }, + labels: null, }, ], }, @@ -237,6 +238,7 @@ describe('hooks/useNotifications.ts', () => { state: 'closed', merged: true, user: mockNotificationUser, + labels: [], }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/3/comments') @@ -249,6 +251,7 @@ describe('hooks/useNotifications.ts', () => { state: 'closed', merged: false, user: mockNotificationUser, + labels: [], }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/pulls/4/reviews') diff --git a/src/typesGitHub.ts b/src/typesGitHub.ts index cf4c7177f..316baee7c 100644 --- a/src/typesGitHub.ts +++ b/src/typesGitHub.ts @@ -476,7 +476,7 @@ export interface Discussion { url: string; author: DiscussionAuthor; comments: DiscussionComments; - labels: DiscussionLabels; + labels: DiscussionLabels | null; } export interface DiscussionLabels { diff --git a/src/utils/subject.ts b/src/utils/subject.ts index ffbc3736d..0f294d044 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -232,7 +232,7 @@ async function getGitifySubjectForIssue( type: issueCommentUser?.type ?? issue.user.type, }, comments: issue.comments, - labels: issue.labels?.map((label) => label.name) ?? [], + labels: issue.labels.map((label) => label.name), }; } @@ -278,7 +278,7 @@ async function getGitifySubjectForPullRequest( }, reviews: reviews, comments: pr.comments, - labels: pr.labels?.map((label) => label.name) ?? [], + labels: pr.labels.map((label) => label.name), linkedIssues: linkedIssues, }; } From c9ba9e0b551d1b13af761587034cf7eb6901fd05 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 3 Jun 2024 20:41:24 -0400 Subject: [PATCH 15/15] add null handling --- src/utils/subject.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/subject.ts b/src/utils/subject.ts index 0f294d044..ffbc3736d 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -232,7 +232,7 @@ async function getGitifySubjectForIssue( type: issueCommentUser?.type ?? issue.user.type, }, comments: issue.comments, - labels: issue.labels.map((label) => label.name), + labels: issue.labels?.map((label) => label.name) ?? [], }; } @@ -278,7 +278,7 @@ async function getGitifySubjectForPullRequest( }, reviews: reviews, comments: pr.comments, - labels: pr.labels.map((label) => label.name), + labels: pr.labels?.map((label) => label.name) ?? [], linkedIssues: linkedIssues, }; }