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 11import type React from 'react' ;
22import { useState } from 'react' ;
33
4- import { FeedPersonIcon , MarkGithubIcon } from '@primer/octicons-react' ;
54import { Avatar , Stack , Truncate } from '@primer/react' ;
65
76import { type Link , Size } from '../../types' ;
87import type { UserType } from '../../typesGitHub' ;
9- import { isNonHumanUser } from '../../utils/helpers' ;
8+ import { getDefaultUserIcon } from '../../utils/icons' ;
9+ import { isNonHumanUser } from '../../utils/notifications/filters/userType' ;
1010
1111export interface IAvatarWithFallback {
1212 src ?: Link ;
@@ -26,7 +26,7 @@ export const AvatarWithFallback: React.FC<IAvatarWithFallback> = ({
2626 const [ isBroken , setIsBroken ] = useState ( false ) ;
2727
2828 const isNonHuman = isNonHumanUser ( userType ) ;
29- const DefaultUserIcon = isNonHuman ? MarkGithubIcon : FeedPersonIcon ;
29+ const DefaultUserIcon = getDefaultUserIcon ( userType ) ;
3030
3131 // TODO explore using AnchoredOverlay component (https://primer.style/components/anchored-overlay/react/alpha) to render Avatar Card on hover
3232 return (
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ import {
2323 getChevronDetails ,
2424 getPlatformFromHostname ,
2525 isEnterpriseServerHost ,
26- isNonHumanUser ,
2726} from './helpers' ;
2827
2928describe ( 'renderer/utils/helpers.ts' , ( ) => {
@@ -553,12 +552,4 @@ describe('renderer/utils/helpers.ts', () => {
553552 } ) ;
554553 } ) ;
555554 } ) ;
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- } ) ;
564555} ) ;
Original file line number Diff line number Diff line change 66
77import { logError , logWarn } from '../../shared/logger' ;
88import type { Chevron , Hostname , Link } from '../types' ;
9- import type { Notification , UserType } from '../typesGitHub' ;
9+ import type { Notification } from '../typesGitHub' ;
1010import { getHtmlUrl , getLatestDiscussion } from './api/client' ;
1111import type { PlatformType } from './auth/types' ;
1212import { Constants } from './constants' ;
@@ -210,7 +210,3 @@ export function getChevronDetails(
210210 label : `Show ${ type } notifications` ,
211211 } ;
212212}
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' ;
29import { IconColor } from '../types' ;
310import type {
411 GitifyPullRequestReview ,
@@ -8,6 +15,7 @@ import type {
815} from '../typesGitHub' ;
916import {
1017 getAuthMethodIcon ,
18+ getDefaultUserIcon ,
1119 getNotificationTypeIcon ,
1220 getNotificationTypeIconColor ,
1321 getPlatformIcon ,
@@ -412,6 +420,14 @@ describe('renderer/utils/icons.ts', () => {
412420
413421 expect ( getPlatformIcon ( 'GitHub Enterprise Server' ) ) . toMatchSnapshot ( ) ;
414422 } ) ;
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+ } ) ;
415431} ) ;
416432
417433function createSubjectMock ( mocks : {
Original file line number Diff line number Diff line change 77 DiscussionClosedIcon ,
88 DiscussionDuplicateIcon ,
99 DiscussionOutdatedIcon ,
10+ FeedPersonIcon ,
1011 FileDiffIcon ,
1112 GitCommitIcon ,
1213 GitMergeIcon ,
@@ -21,6 +22,7 @@ import {
2122 MailIcon ,
2223 MarkGithubIcon ,
2324 type OcticonProps ,
25+ OrganizationIcon ,
2426 PersonIcon ,
2527 QuestionIcon ,
2628 RocketIcon ,
@@ -32,7 +34,11 @@ import {
3234} from '@primer/octicons-react' ;
3335import type { FC } from 'react' ;
3436import { IconColor , type PullRequestApprovalIcon } from '../types' ;
35- import type { GitifyPullRequestReview , Subject } from '../typesGitHub' ;
37+ import type {
38+ GitifyPullRequestReview ,
39+ Subject ,
40+ UserType ,
41+ } from '../typesGitHub' ;
3642import type { AuthMethod , PlatformType } from './auth/types' ;
3743
3844export function getNotificationTypeIcon ( subject : Subject ) : FC < OcticonProps > {
@@ -180,3 +186,15 @@ export function getPlatformIcon(
180186 return MarkGithubIcon ;
181187 }
182188}
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(
6060
6161 return notification . subject ?. user ?. type === userType ;
6262}
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(
297297
298298 // Find the most recent review for each reviewer
299299 const latestReviews : PullRequestReview [ ] = [ ] ;
300- const sortedReviews = prReviews . data . reverse ( ) ;
300+ const sortedReviews = prReviews . data . reverse ( ) ;
301301 for ( const prReview of sortedReviews ) {
302302 const reviewerFound = latestReviews . find (
303303 ( review ) => review . user . login === prReview . user . login ,
You can’t perform that action at this time.
0 commit comments