File tree Expand file tree Collapse file tree 8 files changed +60
-20
lines changed Expand file tree Collapse file tree 8 files changed +60
-20
lines changed Original file line number Diff line number Diff line change 1
1
import type React from 'react' ;
2
2
import { useState } from 'react' ;
3
3
4
- import { FeedPersonIcon , MarkGithubIcon } from '@primer/octicons-react' ;
5
4
import { Avatar , Stack , Truncate } from '@primer/react' ;
6
5
7
6
import { type Link , Size } from '../../types' ;
8
7
import type { UserType } from '../../typesGitHub' ;
9
- import { isNonHumanUser } from '../../utils/helpers' ;
8
+ import { getDefaultUserIcon } from '../../utils/icons' ;
9
+ import { isNonHumanUser } from '../../utils/notifications/filters/userType' ;
10
10
11
11
export interface IAvatarWithFallback {
12
12
src ?: Link ;
@@ -26,7 +26,7 @@ export const AvatarWithFallback: React.FC<IAvatarWithFallback> = ({
26
26
const [ isBroken , setIsBroken ] = useState ( false ) ;
27
27
28
28
const isNonHuman = isNonHumanUser ( userType ) ;
29
- const DefaultUserIcon = isNonHuman ? MarkGithubIcon : FeedPersonIcon ;
29
+ const DefaultUserIcon = getDefaultUserIcon ( userType ) ;
30
30
31
31
// TODO explore using AnchoredOverlay component (https://primer.style/components/anchored-overlay/react/alpha) to render Avatar Card on hover
32
32
return (
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ import {
23
23
getChevronDetails ,
24
24
getPlatformFromHostname ,
25
25
isEnterpriseServerHost ,
26
- isNonHumanUser ,
27
26
} from './helpers' ;
28
27
29
28
describe ( 'renderer/utils/helpers.ts' , ( ) => {
@@ -553,12 +552,4 @@ describe('renderer/utils/helpers.ts', () => {
553
552
} ) ;
554
553
} ) ;
555
554
} ) ;
556
-
557
- it ( 'isNonHumanUser' , ( ) => {
558
- expect ( isNonHumanUser ( 'User' ) ) . toBe ( false ) ;
559
- expect ( isNonHumanUser ( 'EnterpriseUserAccount' ) ) . toBe ( false ) ;
560
- expect ( isNonHumanUser ( 'Bot' ) ) . toBe ( true ) ;
561
- expect ( isNonHumanUser ( 'Organization' ) ) . toBe ( true ) ;
562
- expect ( isNonHumanUser ( 'Mannequin' ) ) . toBe ( true ) ;
563
- } ) ;
564
555
} ) ;
Original file line number Diff line number Diff line change 6
6
7
7
import { logError , logWarn } from '../../shared/logger' ;
8
8
import type { Chevron , Hostname , Link } from '../types' ;
9
- import type { Notification , UserType } from '../typesGitHub' ;
9
+ import type { Notification } from '../typesGitHub' ;
10
10
import { getHtmlUrl , getLatestDiscussion } from './api/client' ;
11
11
import type { PlatformType } from './auth/types' ;
12
12
import { Constants } from './constants' ;
@@ -210,7 +210,3 @@ export function getChevronDetails(
210
210
label : `Show ${ type } notifications` ,
211
211
} ;
212
212
}
213
-
214
- export function isNonHumanUser ( type : UserType ) : boolean {
215
- return type === 'Bot' || type === 'Organization' || type === 'Mannequin' ;
216
- }
Original file line number Diff line number Diff line change 1
- import { CheckIcon , CommentIcon , FileDiffIcon } from '@primer/octicons-react' ;
1
+ import {
2
+ CheckIcon ,
3
+ CommentIcon ,
4
+ FeedPersonIcon ,
5
+ FileDiffIcon ,
6
+ MarkGithubIcon ,
7
+ OrganizationIcon ,
8
+ } from '@primer/octicons-react' ;
2
9
import { IconColor } from '../types' ;
3
10
import type {
4
11
GitifyPullRequestReview ,
@@ -8,6 +15,7 @@ import type {
8
15
} from '../typesGitHub' ;
9
16
import {
10
17
getAuthMethodIcon ,
18
+ getDefaultUserIcon ,
11
19
getNotificationTypeIcon ,
12
20
getNotificationTypeIconColor ,
13
21
getPlatformIcon ,
@@ -412,6 +420,14 @@ describe('renderer/utils/icons.ts', () => {
412
420
413
421
expect ( getPlatformIcon ( 'GitHub Enterprise Server' ) ) . toMatchSnapshot ( ) ;
414
422
} ) ;
423
+
424
+ describe ( 'getDefaultUserIcon' , ( ) => {
425
+ expect ( getDefaultUserIcon ( 'Bot' ) ) . toBe ( MarkGithubIcon ) ;
426
+ expect ( getDefaultUserIcon ( 'EnterpriseUserAccount' ) ) . toBe ( FeedPersonIcon ) ;
427
+ expect ( getDefaultUserIcon ( 'Mannequin' ) ) . toBe ( MarkGithubIcon ) ;
428
+ expect ( getDefaultUserIcon ( 'Organization' ) ) . toBe ( OrganizationIcon ) ;
429
+ expect ( getDefaultUserIcon ( 'User' ) ) . toBe ( FeedPersonIcon ) ;
430
+ } ) ;
415
431
} ) ;
416
432
417
433
function createSubjectMock ( mocks : {
Original file line number Diff line number Diff line change 7
7
DiscussionClosedIcon ,
8
8
DiscussionDuplicateIcon ,
9
9
DiscussionOutdatedIcon ,
10
+ FeedPersonIcon ,
10
11
FileDiffIcon ,
11
12
GitCommitIcon ,
12
13
GitMergeIcon ,
@@ -21,6 +22,7 @@ import {
21
22
MailIcon ,
22
23
MarkGithubIcon ,
23
24
type OcticonProps ,
25
+ OrganizationIcon ,
24
26
PersonIcon ,
25
27
QuestionIcon ,
26
28
RocketIcon ,
@@ -32,7 +34,11 @@ import {
32
34
} from '@primer/octicons-react' ;
33
35
import type { FC } from 'react' ;
34
36
import { IconColor , type PullRequestApprovalIcon } from '../types' ;
35
- import type { GitifyPullRequestReview , Subject } from '../typesGitHub' ;
37
+ import type {
38
+ GitifyPullRequestReview ,
39
+ Subject ,
40
+ UserType ,
41
+ } from '../typesGitHub' ;
36
42
import type { AuthMethod , PlatformType } from './auth/types' ;
37
43
38
44
export function getNotificationTypeIcon ( subject : Subject ) : FC < OcticonProps > {
@@ -180,3 +186,15 @@ export function getPlatformIcon(
180
186
return MarkGithubIcon ;
181
187
}
182
188
}
189
+
190
+ export function getDefaultUserIcon ( userType : UserType ) {
191
+ switch ( userType ) {
192
+ case 'Bot' :
193
+ case 'Mannequin' :
194
+ return MarkGithubIcon ;
195
+ case 'Organization' :
196
+ return OrganizationIcon ;
197
+ default :
198
+ return FeedPersonIcon ;
199
+ }
200
+ }
Original file line number Diff line number Diff line change
1
+ import { isNonHumanUser } from './userType' ;
2
+
3
+ describe ( 'renderer/utils/notifications/filters/userType.ts' , ( ) => {
4
+ afterEach ( ( ) => {
5
+ jest . clearAllMocks ( ) ;
6
+ } ) ;
7
+
8
+ it ( 'isNonHumanUser' , ( ) => {
9
+ expect ( isNonHumanUser ( 'User' ) ) . toBe ( false ) ;
10
+ expect ( isNonHumanUser ( 'EnterpriseUserAccount' ) ) . toBe ( false ) ;
11
+ expect ( isNonHumanUser ( 'Bot' ) ) . toBe ( true ) ;
12
+ expect ( isNonHumanUser ( 'Organization' ) ) . toBe ( true ) ;
13
+ expect ( isNonHumanUser ( 'Mannequin' ) ) . toBe ( true ) ;
14
+ } ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change @@ -60,3 +60,7 @@ export function filterNotificationByUserType(
60
60
61
61
return notification . subject ?. user ?. type === userType ;
62
62
}
63
+
64
+ export function isNonHumanUser ( type : UserType ) : boolean {
65
+ return type === 'Bot' || type === 'Organization' || type === 'Mannequin' ;
66
+ }
Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ export async function getLatestReviewForReviewers(
297
297
298
298
// Find the most recent review for each reviewer
299
299
const latestReviews : PullRequestReview [ ] = [ ] ;
300
- const sortedReviews = prReviews . data . reverse ( ) ;
300
+ const sortedReviews = prReviews . data . reverse ( ) ;
301
301
for ( const prReview of sortedReviews ) {
302
302
const reviewerFound = latestReviews . find (
303
303
( review ) => review . user . login === prReview . user . login ,
You can’t perform that action at this time.
0 commit comments