@@ -10,9 +10,9 @@ import {
1010 GitHubIssueOrPullRequest ,
1111 GitHubLabel ,
1212 GitHubNotification ,
13- GitHubNotificationReason ,
1413 GitHubNotificationSubjectType ,
1514 GitHubPullRequest ,
15+ GitHubUser ,
1616 NotificationPayloadEnhancement ,
1717 ThemeColors ,
1818 UserPlan ,
@@ -36,7 +36,9 @@ import {
3636 getRepoFullNameFromObject ,
3737} from './url'
3838
39- export const notificationReasons : GitHubNotificationReason [ ] = [
39+ export const notificationReasons : Array <
40+ EnhancedGitHubNotification [ 'reason' ]
41+ > = [
4042 'assign' ,
4143 'author' ,
4244 'comment' ,
@@ -48,6 +50,7 @@ export const notificationReasons: GitHubNotificationReason[] = [
4850 'state_change' ,
4951 'subscribed' ,
5052 'team_mention' ,
53+ 'team_review_requested' ,
5154]
5255
5356export const notificationSubjectTypes : GitHubNotificationSubjectType [ ] = [
@@ -60,7 +63,7 @@ export const notificationSubjectTypes: GitHubNotificationSubjectType[] = [
6063]
6164
6265export function getNotificationSubjectType (
63- notification : GitHubNotification ,
66+ notification : Pick < GitHubNotification , 'subject' > ,
6467) : GitHubNotificationSubjectType | null {
6568 if ( ! ( notification && notification . subject && notification . subject . type ) )
6669 return null
@@ -69,7 +72,7 @@ export function getNotificationSubjectType(
6972}
7073
7174export function getNotificationIconAndColor (
72- notification : GitHubNotification ,
75+ notification : Pick < GitHubNotification , 'subject' > ,
7376 payload : GitHubIssueOrPullRequest | undefined ,
7477) : { icon : GitHubIcon ; color ?: keyof ThemeColors ; tooltip : string } {
7578 const { subject } = notification
@@ -105,7 +108,7 @@ export function getNotificationIconAndColor(
105108}
106109
107110export function getNotificationReasonMetadata <
108- T extends GitHubNotificationReason
111+ T extends EnhancedGitHubNotification [ 'reason' ]
109112> (
110113 reason : T ,
111114) : {
@@ -201,12 +204,22 @@ export function getNotificationReasonMetadata<
201204 case 'review_requested' :
202205 return {
203206 reason,
204- color : 'yellow ' ,
207+ color : 'orange ' ,
205208 fullDescription : 'Someone requested your review in the pull request' ,
206209 // smallDescription: 'Review requested',
207210 label : 'Review requested' ,
208211 }
209212
213+ case 'team_review_requested' :
214+ return {
215+ reason,
216+ color : 'yellow' ,
217+ fullDescription :
218+ "Someone requested your team's review in the pull request" ,
219+ // smallDescription: 'Team review requested',
220+ label : 'Team review requested' ,
221+ }
222+
210223 case 'security_alert' :
211224 return {
212225 reason,
@@ -274,7 +287,9 @@ export function mergeNotificationPreservingEnhancement(
274287 newItem . last_unsaved_at ,
275288 ] ) ,
276289 pullRequest : existingItem . pullRequest ,
290+ reason : existingItem . reason ,
277291 release : existingItem . release ,
292+ requestedMyReview : existingItem . requestedMyReview ,
278293 updated_at : _ . max ( [ existingItem . updated_at , newItem . updated_at ] ) ! ,
279294 }
280295
@@ -307,15 +322,19 @@ export async function getNotificationsEnhancementMap(
307322 cache = new Map ( ) ,
308323 getGitHubPrivateTokenForRepo,
309324 githubToken : _githubToken ,
325+ githubLogin : _githubLogin ,
310326 } : {
311327 cache : EnhancementCache | undefined | undefined
312328 getGitHubPrivateTokenForRepo : (
313329 owner : string | undefined ,
314330 repo : string | undefined ,
315331 ) => string | undefined
316332 githubToken : string
333+ githubLogin : string
317334 } ,
318335) : Promise < Record < string , NotificationPayloadEnhancement > > {
336+ const githubLogin = `${ _githubLogin || '' } ` . toLowerCase ( ) . trim ( )
337+
319338 const promises = notifications . map ( async notification => {
320339 if ( ! ( notification . repository && notification . repository . full_name ) ) return
321340
@@ -376,6 +395,30 @@ export async function getNotificationsEnhancementMap(
376395 if ( ! enhance . enhanced ) enhance . enhanced = false
377396 return
378397 }
398+
399+ // if (
400+ // subjectField === 'pullRequest' &&
401+ // enhance.pullRequest &&
402+ // notification.reason === 'review_requested' &&
403+ // !enhance.requestedMyReview
404+ // ) {
405+ // try {
406+ // const { data } = await axios.get(
407+ // `${notification.subject.url}/reviews?access_token=${githubToken}`,
408+ // )
409+
410+ // if (data && data.length) {
411+ // enhance.requestedMyReview = !!data.find(
412+ // (item: { user?: GitHubUser }) =>
413+ // item &&
414+ // item.user &&
415+ // githubLogin === `${item.user.login || ''}`.toLowerCase().trim(),
416+ // )
417+ // }
418+ // } catch (error) {
419+ // //
420+ // }
421+ // }
379422 } else if ( hasSubjectCache ) {
380423 if ( subjectCache && subjectCache . data ) {
381424 enhance [ subjectField ] = subjectCache . data
@@ -413,6 +456,25 @@ export async function getNotificationsEnhancementMap(
413456 } else if ( ! enhance . enhanced ) enhance . enhanced = false
414457 }
415458
459+ if (
460+ githubLogin &&
461+ enhance . pullRequest &&
462+ enhance . pullRequest . requested_reviewers
463+ ) {
464+ if ( ! enhance . requestedMyReview ) {
465+ enhance . requestedMyReview = ! ! enhance . pullRequest . requested_reviewers . find (
466+ u => githubLogin === `${ u . login || '' } ` . toLowerCase ( ) . trim ( ) ,
467+ )
468+ }
469+ }
470+
471+ if (
472+ notification . reason === 'review_requested' &&
473+ enhance . requestedMyReview === false
474+ ) {
475+ enhance . reason = 'team_review_requested'
476+ }
477+
416478 if ( ! Object . keys ( enhance ) . length ) return
417479
418480 return { id : notification . id , enhance }
0 commit comments