@@ -133,7 +133,6 @@ export async function enrichNotifications(
133133 if ( ! settings . detailedNotifications ) {
134134 return notifications ;
135135 }
136- type NotificationKind = 'PullRequest' | 'Issue' | 'Discussion' ;
137136
138137 const selections : string [ ] = [ ] ;
139138 const variableDefinitions : string [ ] = [ ] ;
@@ -143,8 +142,8 @@ export async function enrichNotifications(
143142 const fragments = new Map < string , string > ( ) ;
144143 const targets : Array < {
145144 alias : string ;
146- kind : NotificationKind ;
147145 notification : Notification ;
146+ handler : ReturnType < typeof createNotificationHandler > ;
148147 } > = [ ] ;
149148
150149 const collectFragments = ( doc : string ) => {
@@ -166,54 +165,46 @@ export async function enrichNotifications(
166165 } ;
167166
168167 let index = 0 ;
169-
170168 for ( const notification of notifications ) {
171169 const handler = createNotificationHandler ( notification ) ;
172- const kind = notification . subject . type as NotificationKind ;
173170 const config = handler . mergeQueryConfig ( ) ;
174-
175171 if ( ! config ) {
176172 continue ;
177173 }
178174
179175 const org = notification . repository . owner . login ;
180176 const repo = notification . repository . name ;
181177 const number = getNumberFromUrl ( notification . subject . url ) ;
182-
183178 const alias = `node${ index } ` ;
184179 const queryFragment = config . queryFragment . replaceAll (
185180 'INDEX' ,
186181 index . toString ( ) ,
187182 ) ;
188-
189183 selections . push ( queryFragment ) ;
190184 variableDefinitions . push (
191185 `$owner${ index } : String!, $name${ index } : String!, $number${ index } : Int!` ,
192186 ) ;
193187 variableValues [ `owner${ index } ` ] = org ;
194188 variableValues [ `name${ index } ` ] = repo ;
195189 variableValues [ `number${ index } ` ] = number ;
196- targets . push ( { alias, kind, notification } ) ;
197-
190+ targets . push ( { alias, notification, handler } ) ;
198191 for ( const extra of config . extras ) {
199192 if ( ! extraVariableDefinitions . has ( extra . name ) ) {
200193 extraVariableDefinitions . set ( extra . name , extra . type ) ;
201194 extraVariableValues [ extra . name ] = extra . defaultValue ;
202195 }
203196 }
204-
205197 collectFragments ( config . responseFragment ) ;
206-
207198 index += 1 ;
208199 }
209200
210201 if ( selections . length === 0 ) {
211- const enrichedNotifications = await Promise . all (
212- notifications . map ( async ( notification : Notification ) => {
213- return enrichNotification ( notification , settings ) ;
214- } ) ,
202+ // No handlers with mergeQueryConfig, just enrich individually
203+ return Promise . all (
204+ notifications . map ( ( notification ) =>
205+ enrichNotification ( notification , settings ) ,
206+ ) ,
215207 ) ;
216- return enrichedNotifications ;
217208 }
218209
219210 const combinedVariableDefinitions = [
@@ -267,26 +258,23 @@ export async function enrichNotifications(
267258
268259 const enrichedNotifications = await Promise . all (
269260 notifications . map ( async ( notification : Notification ) => {
270- const handler = createNotificationHandler ( notification ) ;
271-
272261 const target = targets . find ( ( item ) => item . notification === notification ) ;
273-
274262 if ( mergedData && target ) {
263+ // Try to find the first defined property in the repoData (pullRequest, issue, discussion, etc.)
275264 const repoData = mergedData [ target . alias ] as
276- | { pullRequest ?: unknown ; issue ?: unknown ; discussion ?: unknown }
265+ | Record < string , unknown >
277266 | undefined ;
278-
279267 let fragment : unknown ;
280- if ( target . kind === 'PullRequest' ) {
281- fragment = repoData ?. pullRequest ;
282- } else if ( target . kind === 'Issue' ) {
283- fragment = repoData ?. issue ;
284- } else if ( target . kind === 'Discussion' ) {
285- fragment = repoData ?. discussion ;
268+ if ( repoData ) {
269+ for ( const value of Object . values ( repoData ) ) {
270+ if ( value !== undefined ) {
271+ fragment = value ;
272+ break ;
273+ }
274+ }
286275 }
287-
288276 if ( fragment ) {
289- const details = await handler . enrich (
277+ const details = await target . handler . enrich (
290278 notification ,
291279 settings ,
292280 fragment ,
@@ -300,11 +288,9 @@ export async function enrichNotifications(
300288 } ;
301289 }
302290 }
303-
304- const fetchedDetails = await handler . fetchAndEnrich (
305- notification ,
306- settings ,
307- ) ;
291+ // fallback
292+ const handler = createNotificationHandler ( notification ) ;
293+ const fetchedDetails = await handler . enrich ( notification , settings ) ;
308294 return {
309295 ...notification ,
310296 subject : {
@@ -314,7 +300,6 @@ export async function enrichNotifications(
314300 } ;
315301 } ) ,
316302 ) ;
317-
318303 return enrichedNotifications ;
319304}
320305
@@ -333,10 +318,7 @@ export async function enrichNotification(
333318
334319 try {
335320 const handler = createNotificationHandler ( notification ) ;
336- additionalSubjectDetails = await handler . fetchAndEnrich (
337- notification ,
338- settings ,
339- ) ;
321+ additionalSubjectDetails = await handler . enrich ( notification , settings ) ;
340322 } catch ( err ) {
341323 rendererLogError (
342324 'enrichNotification' ,
0 commit comments