@@ -210,6 +210,11 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
210210 const processedReplies = [ ]
211211
212212 for ( const reply of replies ) {
213+ // Filter out bot comments
214+ if ( reply . author && reply . author . login . endsWith ( '[bot]' ) ) {
215+ continue
216+ }
217+
213218 const processedReply = {
214219 id : reply . id ,
215220 url : reply . url ,
@@ -228,6 +233,18 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
228233 }
229234
230235 processedReplies . push ( processedReply )
236+
237+ // 递归处理子回复
238+ if ( reply . replies && reply . replies . nodes && reply . replies . nodes . length > 0 ) {
239+ const childReplies = processReplies (
240+ reply . replies . nodes ,
241+ reply . id ,
242+ discussionId ,
243+ discussionTitle ,
244+ level + 1
245+ )
246+ processedReplies . push ( ...childReplies )
247+ }
231248 }
232249
233250 return processedReplies
@@ -236,9 +253,12 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
236253async function main ( ) {
237254 try {
238255 const discussions = await fetchAllDiscussions ( )
239- const allComments = [ ]
256+ const allComments = discussions . flatMap ( ( discussion ) => {
257+ // Filter out bot discussions if necessary (though Giscus usually comments, not creates discussions)
258+ if ( discussion . author && discussion . author . login . endsWith ( '[bot]' ) ) {
259+ return [ ]
260+ }
240261
241- for ( const discussion of discussions ) {
242262 // Map the main discussion post
243263 const mainComment = {
244264 id : discussion . id ,
@@ -257,25 +277,25 @@ async function main() {
257277 type : 'discussion'
258278 }
259279
260- allComments . push ( mainComment )
261-
262280 // 处理顶级评论
263- const topLevelComments = discussion . comments . nodes . map ( ( comment ) => ( {
264- id : comment . id ,
265- url : comment . url ,
266- createdAt : comment . createdAt ,
267- author : comment . author ,
268- bodyHTML : comment . bodyHTML ,
269- reactionGroups : comment . reactionGroups ,
270- isDiscussion : false ,
271- title : discussion . title ,
272- discussionId : discussion . id ,
273- parentId : discussion . id , // 顶级评论的父级是 discussion
274- replyToId : comment . replyTo ? comment . replyTo . id : null ,
275- replyToAuthor : comment . replyTo ? comment . replyTo . author . login : null ,
276- level : 1 ,
277- type : 'comment'
278- } ) )
281+ const topLevelComments = discussion . comments . nodes
282+ . filter ( comment => ! comment . author || ! comment . author . login . endsWith ( '[bot]' ) ) // Filter out bot comments
283+ . map ( ( comment ) => ( {
284+ id : comment . id ,
285+ url : comment . url ,
286+ createdAt : comment . createdAt ,
287+ author : comment . author ,
288+ bodyHTML : comment . bodyHTML ,
289+ reactionGroups : comment . reactionGroups ,
290+ isDiscussion : false ,
291+ title : discussion . title ,
292+ discussionId : discussion . id ,
293+ parentId : discussion . id , // 顶级评论的父级是 discussion
294+ replyToId : comment . replyTo ? comment . replyTo . id : null ,
295+ replyToAuthor : comment . replyTo ? comment . replyTo . author . login : null ,
296+ level : 1 ,
297+ type : 'comment'
298+ } ) )
279299
280300 allComments . push ( ...topLevelComments )
281301
0 commit comments