@@ -209,6 +209,11 @@ export async function enrichNotifications(
209209 const extraVariableDefinitions = new Map < string , string > ( ) ;
210210 const extraVariableValues : Record < string , number | boolean > = { } ;
211211 const fragments = new Map < string , string > ( ) ;
212+ const targets : Array < {
213+ alias : string ;
214+ kind : NotificationKind ;
215+ notification : Notification ;
216+ } > = [ ] ;
212217
213218 const collectFragments = ( doc : string ) => {
214219 const fragmentRegex =
@@ -242,13 +247,16 @@ export async function enrichNotifications(
242247 const repo = notification . repository . name ;
243248 const number = getNumberFromUrl ( notification . subject . url ) ;
244249
250+ const alias = `${ config . aliasPrefix } ${ index } ` ;
251+
245252 selections . push ( config . selection ( index ) ) ;
246253 variableDefinitions . push (
247254 `$owner${ index } : String!, $name${ index } : String!, $number${ index } : Int!` ,
248255 ) ;
249256 variableValues [ `owner${ index } ` ] = org ;
250257 variableValues [ `name${ index } ` ] = repo ;
251258 variableValues [ `number${ index } ` ] = number ;
259+ targets . push ( { alias, kind, notification } ) ;
252260
253261 for ( const extra of config . extras ) {
254262 if ( ! extraVariableDefinitions . has ( extra . name ) ) {
@@ -289,8 +297,7 @@ ${Array.from(fragments.values()).join('\n')}`;
289297 ...extraVariableValues ,
290298 } ;
291299
292- console . log ( 'MERGED QUERY ' , JSON . stringify ( mergedQuery , null , 2 ) ) ;
293- console . log ( 'MERGED ARGS ' , JSON . stringify ( queryVariables , null , 2 ) ) ;
300+ let mergedData : Record < string , unknown > | null = null ;
294301
295302 try {
296303 const url = getGitHubGraphQLUrl (
@@ -300,24 +307,73 @@ ${Array.from(fragments.values()).join('\n')}`;
300307
301308 const headers = await getHeaders ( url as Link , token ) ;
302309
303- axios ( {
310+ const response = await axios ( {
304311 method : 'POST' ,
305312 url,
306313 data : {
307314 query : mergedQuery ,
308315 variables : queryVariables ,
309316 } ,
310317 headers : headers ,
311- } ) . then ( ( response ) => {
312- console . log ( 'MERGED RESPONSE ' , JSON . stringify ( response , null , 2 ) ) ;
313318 } ) ;
319+
320+ mergedData =
321+ ( response . data as { data ?: Record < string , unknown > } ) ?. data ?? null ;
314322 } catch ( err ) {
315- console . error ( 'Failed to fetch merged notification details' , err ) ;
323+ rendererLogError (
324+ 'enrichNotifications' ,
325+ 'Failed to fetch merged notification details' ,
326+ err ,
327+ ) ;
316328 }
317329
318330 const enrichedNotifications = await Promise . all (
319331 notifications . map ( async ( notification : Notification ) => {
320- return enrichNotification ( notification , settings ) ;
332+ const handler = createNotificationHandler ( notification ) ;
333+
334+ const target = targets . find ( ( item ) => item . notification === notification ) ;
335+
336+ if ( mergedData && target ) {
337+ const repoData = mergedData [ target . alias ] as
338+ | { pullRequest ?: unknown ; issue ?: unknown ; discussion ?: unknown }
339+ | undefined ;
340+
341+ let fragment : unknown ;
342+ if ( target . kind === 'PullRequest' ) {
343+ fragment = repoData ?. pullRequest ;
344+ } else if ( target . kind === 'Issue' ) {
345+ fragment = repoData ?. issue ;
346+ } else if ( target . kind === 'Discussion' ) {
347+ fragment = repoData ?. discussion ;
348+ }
349+
350+ if ( fragment ) {
351+ const details = await handler . enrich (
352+ notification ,
353+ settings ,
354+ fragment ,
355+ ) ;
356+ return {
357+ ...notification ,
358+ subject : {
359+ ...notification . subject ,
360+ ...details ,
361+ } ,
362+ } ;
363+ }
364+ }
365+
366+ const fetchedDetails = await handler . fetchAndEnrich (
367+ notification ,
368+ settings ,
369+ ) ;
370+ return {
371+ ...notification ,
372+ subject : {
373+ ...notification . subject ,
374+ ...fetchedDetails ,
375+ } ,
376+ } ;
321377 } ) ,
322378 ) ;
323379
@@ -339,7 +395,10 @@ export async function enrichNotification(
339395
340396 try {
341397 const handler = createNotificationHandler ( notification ) ;
342- additionalSubjectDetails = await handler . enrich ( notification , settings ) ;
398+ additionalSubjectDetails = await handler . fetchAndEnrich (
399+ notification ,
400+ settings ,
401+ ) ;
343402 } catch ( err ) {
344403 rendererLogError (
345404 'enrichNotification' ,
0 commit comments