Skip to content

Commit dc5330c

Browse files
authored
feat(discussions): default to discussion author (#964)
* fix(discussions): default to discussion author when there are no comments/replies
1 parent 624594d commit dc5330c

File tree

8 files changed

+300
-324
lines changed

8 files changed

+300
-324
lines changed

src/__mocks__/mockedData.ts

+161-299
Large diffs are not rendered by default.

src/components/__snapshots__/NotificationRow.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ exports[`components/NotificationRow.tsx should render itself & its children with
207207
</div>
208208
<div
209209
className="flex-1 overflow-hidden"
210+
onClick={[Function]}
210211
>
211212
<div
212213
className="mb-1 text-sm whitespace-nowrap overflow-ellipsis overflow-hidden cursor-pointer"
213-
onClick={[Function]}
214214
role="main"
215215
title="I am a robot and this is a test!"
216216
>

src/hooks/useNotifications.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ describe('hooks/useNotifications.ts', () => {
280280
stateReason: null,
281281
isAnswered: true,
282282
url: 'https://github.com/manosim/notifications-test/discussions/612',
283+
author: {
284+
login: 'discussion-creator',
285+
url: 'https://github.com/discussion-creator',
286+
avatar_url:
287+
'https://avatars.githubusercontent.com/u/1?v=4',
288+
type: 'User',
289+
},
283290
comments: {
284291
nodes: [
285292
{
@@ -290,6 +297,7 @@ describe('hooks/useNotifications.ts', () => {
290297
url: 'https://github.com/comment-user',
291298
avatar_url:
292299
'https://avatars.githubusercontent.com/u/1?v=4',
300+
type: 'User',
293301
},
294302
replies: {
295303
nodes: [],

src/routes/__snapshots__/Notifications.test.tsx.snap

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ exports[`routes/Notifications.tsx should render itself & its children (show acco
9090
"title": "I am a robot and this is a test!",
9191
"type": "Issue",
9292
"url": "https://api.github.com/repos/manosim/notifications-test/issues/1",
93+
"user": {
94+
"avatar_url": "https://avatars0.githubusercontent.com/u/6333409?v=3",
95+
"html_url": "https://github.com/manosim",
96+
"login": "manosim",
97+
"type": "User",
98+
},
9399
},
94100
"subscription_url": "https://api.github.com/notifications/threads/138661096/subscription",
95101
"unread": true,

src/typesGithub.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export interface DiscussionAuthor {
146146
login: string;
147147
url: string;
148148
avatar_url: string;
149+
type: string;
149150
}
150151

151152
export interface Repository {
@@ -338,18 +339,18 @@ export interface Discussion {
338339
stateReason: DiscussionStateType;
339340
isAnswered: boolean;
340341
url: string;
341-
comments: {
342-
nodes: DiscussionComment[];
343-
};
342+
author: DiscussionAuthor;
343+
comments: DiscussionComments;
344+
}
345+
346+
export interface DiscussionComments {
347+
nodes: DiscussionComment[];
344348
}
345349

346350
export interface DiscussionComment {
347351
databaseId: string | number;
348352
createdAt: string;
349353
author: DiscussionAuthor;
350-
bot: {
351-
login?: string;
352-
};
353354
replies?: {
354355
nodes: DiscussionComment[];
355356
};

src/utils/helpers.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,18 @@ export async function fetchDiscussion(
164164
token,
165165
{
166166
query: `
167+
fragment AuthorFields on Actor {
168+
login
169+
url
170+
avatar_url: avatarUrl
171+
type: __typename
172+
}
173+
167174
fragment CommentFields on DiscussionComment {
168175
databaseId
169176
createdAt
170177
author {
171-
login
172-
url
173-
avatar_url: avatarUrl
174-
}
175-
bot: author {
176-
... on Bot {
177-
login
178-
avatar_url: avatarUrl
179-
}
178+
...AuthorFields
180179
}
181180
}
182181
@@ -195,6 +194,9 @@ export async function fetchDiscussion(
195194
stateReason
196195
isAnswered
197196
url
197+
author {
198+
...AuthorFields
199+
}
198200
comments(last: $lastComments){
199201
nodes {
200202
...CommentFields

src/utils/subject.test.ts

+98-7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ describe('utils/subject.ts', () => {
160160
viewerSubscription: 'SUBSCRIBED',
161161
stateReason: null,
162162
isAnswered: true,
163+
author: {
164+
login: 'discussion-creator',
165+
url: 'https://github.com/discussion-creator',
166+
avatar_url:
167+
'https://avatars.githubusercontent.com/u/583231?v=4',
168+
type: 'User',
169+
},
163170
comments: {
164171
nodes: [], //TODO - Update this to have real data
165172
},
@@ -175,7 +182,12 @@ describe('utils/subject.ts', () => {
175182
);
176183

177184
expect(result.state).toBe('ANSWERED');
178-
expect(result.user).toBe(null);
185+
expect(result.user).toEqual({
186+
login: 'discussion-creator',
187+
html_url: 'https://github.com/discussion-creator',
188+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
189+
type: 'User',
190+
});
179191
});
180192

181193
it('duplicate discussion state', async () => {
@@ -199,6 +211,13 @@ describe('utils/subject.ts', () => {
199211
viewerSubscription: 'SUBSCRIBED',
200212
stateReason: 'DUPLICATE',
201213
isAnswered: false,
214+
author: {
215+
login: 'discussion-creator',
216+
url: 'https://github.com/discussion-creator',
217+
avatar_url:
218+
'https://avatars.githubusercontent.com/u/583231?v=4',
219+
type: 'User',
220+
},
202221
comments: {
203222
nodes: [], //TODO - Update this to have real data
204223
},
@@ -214,7 +233,12 @@ describe('utils/subject.ts', () => {
214233
);
215234

216235
expect(result.state).toBe('DUPLICATE');
217-
expect(result.user).toBe(null);
236+
expect(result.user).toEqual({
237+
login: 'discussion-creator',
238+
html_url: 'https://github.com/discussion-creator',
239+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
240+
type: 'User',
241+
});
218242
});
219243

220244
it('open discussion state', async () => {
@@ -238,6 +262,13 @@ describe('utils/subject.ts', () => {
238262
viewerSubscription: 'SUBSCRIBED',
239263
stateReason: null,
240264
isAnswered: false,
265+
author: {
266+
login: 'discussion-creator',
267+
url: 'https://github.com/discussion-creator',
268+
avatar_url:
269+
'https://avatars.githubusercontent.com/u/583231?v=4',
270+
type: 'User',
271+
},
241272
comments: {
242273
nodes: [], //TODO - Update this to have real data
243274
},
@@ -253,7 +284,12 @@ describe('utils/subject.ts', () => {
253284
);
254285

255286
expect(result.state).toBe('OPEN');
256-
expect(result.user).toBe(null);
287+
expect(result.user).toEqual({
288+
login: 'discussion-creator',
289+
html_url: 'https://github.com/discussion-creator',
290+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
291+
type: 'User',
292+
});
257293
});
258294

259295
it('outdated discussion state', async () => {
@@ -277,6 +313,13 @@ describe('utils/subject.ts', () => {
277313
viewerSubscription: 'SUBSCRIBED',
278314
stateReason: 'OUTDATED',
279315
isAnswered: false,
316+
author: {
317+
login: 'discussion-creator',
318+
url: 'https://github.com/discussion-creator',
319+
avatar_url:
320+
'https://avatars.githubusercontent.com/u/583231?v=4',
321+
type: 'User',
322+
},
280323
comments: {
281324
nodes: [], //TODO - Update this to have real data
282325
},
@@ -292,7 +335,12 @@ describe('utils/subject.ts', () => {
292335
);
293336

294337
expect(result.state).toBe('OUTDATED');
295-
expect(result.user).toBe(null);
338+
expect(result.user).toEqual({
339+
login: 'discussion-creator',
340+
html_url: 'https://github.com/discussion-creator',
341+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
342+
type: 'User',
343+
});
296344
});
297345

298346
it('reopened discussion state', async () => {
@@ -316,6 +364,13 @@ describe('utils/subject.ts', () => {
316364
viewerSubscription: 'SUBSCRIBED',
317365
stateReason: 'REOPENED',
318366
isAnswered: false,
367+
author: {
368+
login: 'discussion-creator',
369+
url: 'https://github.com/discussion-creator',
370+
avatar_url:
371+
'https://avatars.githubusercontent.com/u/583231?v=4',
372+
type: 'User',
373+
},
319374
comments: {
320375
nodes: [], //TODO - Update this to have real data
321376
},
@@ -331,7 +386,12 @@ describe('utils/subject.ts', () => {
331386
);
332387

333388
expect(result.state).toBe('REOPENED');
334-
expect(result.user).toBe(null);
389+
expect(result.user).toEqual({
390+
login: 'discussion-creator',
391+
html_url: 'https://github.com/discussion-creator',
392+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
393+
type: 'User',
394+
});
335395
});
336396

337397
it('resolved discussion state', async () => {
@@ -355,6 +415,13 @@ describe('utils/subject.ts', () => {
355415
viewerSubscription: 'SUBSCRIBED',
356416
stateReason: 'RESOLVED',
357417
isAnswered: false,
418+
author: {
419+
login: 'discussion-creator',
420+
url: 'https://github.com/discussion-creator',
421+
avatar_url:
422+
'https://avatars.githubusercontent.com/u/583231?v=4',
423+
type: 'User',
424+
},
358425
comments: {
359426
nodes: [], //TODO - Update this to have real data
360427
},
@@ -370,7 +437,12 @@ describe('utils/subject.ts', () => {
370437
);
371438

372439
expect(result.state).toBe('RESOLVED');
373-
expect(result.user).toBe(null);
440+
expect(result.user).toEqual({
441+
login: 'discussion-creator',
442+
html_url: 'https://github.com/discussion-creator',
443+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
444+
type: 'User',
445+
});
374446
});
375447

376448
it('filtered response by subscribed', async () => {
@@ -394,6 +466,13 @@ describe('utils/subject.ts', () => {
394466
viewerSubscription: 'SUBSCRIBED',
395467
stateReason: null,
396468
isAnswered: false,
469+
author: {
470+
login: 'discussion-creator',
471+
url: 'https://github.com/discussion-creator',
472+
avatar_url:
473+
'https://avatars.githubusercontent.com/u/583231?v=4',
474+
type: 'User',
475+
},
397476
comments: {
398477
nodes: [], //TODO - Update this to have real data
399478
},
@@ -403,6 +482,13 @@ describe('utils/subject.ts', () => {
403482
viewerSubscription: 'IGNORED',
404483
stateReason: null,
405484
isAnswered: true,
485+
author: {
486+
login: 'discussion-creator',
487+
url: 'https://github.com/discussion-creator',
488+
avatar_url:
489+
'https://avatars.githubusercontent.com/u/583231?v=4',
490+
type: 'User',
491+
},
406492
comments: {
407493
nodes: [], //TODO - Update this to have real data
408494
},
@@ -418,7 +504,12 @@ describe('utils/subject.ts', () => {
418504
);
419505

420506
expect(result.state).toBe('OPEN');
421-
expect(result.user).toBe(null);
507+
expect(result.user).toEqual({
508+
login: 'discussion-creator',
509+
html_url: 'https://github.com/discussion-creator',
510+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
511+
type: 'User',
512+
});
422513
});
423514
});
424515

src/utils/subject.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,19 @@ async function getGitifySubjectForDiscussion(
111111
const latestDiscussionComment = getLatestDiscussionComment(
112112
discussion.comments.nodes,
113113
);
114-
let discussionUser: SubjectUser = null;
114+
115+
let discussionUser: SubjectUser = {
116+
login: discussion.author.login,
117+
html_url: discussion.author.url,
118+
avatar_url: discussion.author.avatar_url,
119+
type: discussion.author.type,
120+
};
115121
if (latestDiscussionComment) {
116122
discussionUser = {
117123
login: latestDiscussionComment.author.login,
118124
html_url: latestDiscussionComment.author.url,
119125
avatar_url: latestDiscussionComment.author.avatar_url,
120-
type: latestDiscussionComment.bot?.login ? 'Bot' : 'User',
126+
type: latestDiscussionComment.author.type,
121127
};
122128
}
123129

0 commit comments

Comments
 (0)