@@ -7,32 +7,38 @@ export default async function({login, q, imports, data, graphql, queries, accoun
77 return null
88
99 //Load inputs
10- let { limit :_limit1 , "limit.issues" :_limit2 , days, details, display, ignored} = imports . metadata . plugins . reactions . inputs ( { data, account, q} )
10+ let { limit :_limit1 , "limit.issues" :_limit2 , "limit.discussions" : _limit3 , "limit.discussions.comments" : _limit4 , days, details, display, ignored} = imports . metadata . plugins . reactions . inputs ( { data, account, q} )
1111
1212 //Load issue comments
1313 const comments = [ ]
14- for ( const { type, limit} of [ { type :"issueComments" , limit :_limit1 } , { type :"issues" , limit :_limit2 } ] . filter ( ( { limit} ) => limit ) ) {
14+ for ( const { type, limit} of [ { type :"issueComments" , limit :_limit1 } , { type :"issues" , limit :_limit2 } , { type : "repositoryDiscussionComments" , limit : _limit3 } , { type : "repositoryDiscussions" , limit : _limit4 } ] . filter ( ( { limit} ) => limit ) ) {
1515 let cursor = null , pushed = 0
1616 const fetched = [ ]
17- do {
18- //Load issue comments
19- console . debug ( `metrics/compute/${ login } /plugins > reactions > retrieving ${ type } after ${ cursor } ` )
20- const { user :{ [ type ] :{ edges} } } = await graphql ( queries . reactions ( { login, type, after :cursor ? `after: "${ cursor } "` : "" } ) )
21- cursor = edges ?. [ edges ?. length - 1 ] ?. cursor
22- //Save issue comments
23- const filtered = edges
24- . flatMap ( ( { node :{ createdAt :created , reactions :{ nodes :reactions } } } ) => ( { created :new Date ( created ) , reactions :reactions . filter ( ( { user = { } } ) => ! ignored . includes ( user . login ) ) . map ( ( { content} ) => content ) } ) )
25- . filter ( comment => Number . isFinite ( days ) ? comment . created < new Date ( Date . now ( ) - days * 24 * 60 * 60 * 1000 ) : true )
26- pushed = filtered . length
27- fetched . push ( ...filtered )
28- console . debug ( `metrics/compute/${ login } /plugins > reactions > currently at ${ fetched . length } ${ type } comments` )
29- //Applying limit
30- if ( ( fetched . length >= limit ) || ( filtered . length < edges . length ) ) {
31- fetched . splice ( limit )
32- console . debug ( `metrics/compute/${ login } /plugins > reactions > keeping only ${ fetched . length } ${ type } comments` )
33- }
34- } while ( ( cursor ) && ( pushed ) && ( fetched . length < limit ) )
35- comments . push ( ...fetched )
17+ try {
18+ do {
19+ //Load issue comments
20+ console . debug ( `metrics/compute/${ login } /plugins > reactions > retrieving ${ type } before ${ cursor } ` )
21+ const { user :{ [ type ] :{ edges} } } = await graphql ( queries . reactions ( { login, type, before :cursor ? `before: "${ cursor } "` : "" } ) )
22+ cursor = edges ?. [ 0 ] ?. cursor
23+ //Save issue comments
24+ const filtered = edges
25+ . flatMap ( ( { node :{ createdAt :created , reactions :{ nodes :reactions } } } ) => ( { created :new Date ( created ) , reactions :reactions . filter ( ( { user = { } } ) => ! ignored . includes ( user . login ) ) . map ( ( { content} ) => content ) } ) )
26+ . filter ( comment => Number . isFinite ( days ) ? comment . created < new Date ( Date . now ( ) - days * 24 * 60 * 60 * 1000 ) : true )
27+ pushed = filtered . length
28+ fetched . push ( ...filtered )
29+ console . debug ( `metrics/compute/${ login } /plugins > reactions > currently at ${ fetched . length } ${ type } comments` )
30+ //Applying limit
31+ if ( ( fetched . length >= limit ) || ( filtered . length < edges . length ) ) {
32+ fetched . splice ( limit )
33+ console . debug ( `metrics/compute/${ login } /plugins > reactions > keeping only ${ fetched . length } ${ type } comments` )
34+ }
35+ } while ( ( cursor ) && ( pushed ) && ( fetched . length < limit ) )
36+ comments . push ( ...fetched )
37+ }
38+ catch ( error ) {
39+ console . debug ( error )
40+ console . debug ( `metrics/compute/${ login } /plugins > reactions > an error occured while retrieving ${ type } ` )
41+ }
3642 }
3743 console . debug ( `metrics/compute/${ login } /plugins > reactions > fetched ${ comments . length } comments` )
3844
0 commit comments