@@ -297,38 +297,22 @@ async function main() {
297297 type : 'comment'
298298 } ) )
299299
300- allComments . push ( ...topLevelComments )
301-
302- // 处理第一层回复
303- for ( const comment of discussion . comments . nodes ) {
300+ // 处理所有嵌套回复
301+ const allReplies = discussion . comments . nodes . flatMap ( ( comment ) => {
304302 if ( comment . replies && comment . replies . nodes && comment . replies . nodes . length > 0 ) {
305- const firstLevelReplies = comment . replies . nodes . map ( ( reply ) => ( {
306- id : reply . id ,
307- url : reply . url ,
308- createdAt : reply . createdAt ,
309- author : reply . author ,
310- bodyHTML : reply . bodyHTML ,
311- reactionGroups : reply . reactionGroups ,
312- isDiscussion : false ,
313- title : discussion . title ,
314- discussionId : discussion . id ,
315- parentId : comment . id ,
316- replyToId : reply . replyTo ? reply . replyTo . id : null ,
317- replyToAuthor : reply . replyTo ? reply . replyTo . author . login : null ,
318- level : 2 ,
319- type : 'reply'
320- } ) )
321-
322- allComments . push ( ...firstLevelReplies )
323-
324- // 获取更深层的回复
325- for ( const reply of comment . replies . nodes ) {
326- const deepReplies = await fetchDeepReplies ( reply . id , discussion . id , discussion . title , 3 )
327- allComments . push ( ...deepReplies )
328- }
303+ return processReplies (
304+ comment . replies . nodes ,
305+ comment . id ,
306+ discussion . id ,
307+ discussion . title ,
308+ 2
309+ )
329310 }
330- }
331- }
311+ return [ ]
312+ } )
313+
314+ return [ mainComment , ...topLevelComments , ...allReplies ]
315+ } )
332316
333317 // Sort all comments and replies together by date
334318 allComments . sort ( ( a , b ) => new Date ( b . createdAt ) - new Date ( a . createdAt ) )
0 commit comments