@@ -83,69 +83,65 @@ export class RecentAnalyzer extends Analyzer {
8383 entry . head = head //Update with latest head
8484 }
8585
86- //Fetch commit details via REST API
87- const patches = [ ]
88- for ( const [ key , { repo, ref, head, shas} ] of commitsByRepo ) {
86+ //Fetch commits from repos and filter patches
87+ const commitUrls = [ ]
88+ for ( const { repo, ref} of commitsByRepo . values ( ) ) {
89+ const [ owner , repoName ] = repo . split ( "/" )
90+ const branch = ref . replace ( "refs/heads/" , "" )
91+ //Fetch commit list for this repo/branch
8992 try {
90- const [ owner , repoName ] = repo . split ( "/" )
91- //Fetch commits for this repo/ref combination
92- let foundCommits = 0
93- for ( let page = 1 ; foundCommits < Math . min ( 100 , this . load ) ; page ++ ) {
94- const { data : commits } = await this . rest . repos . listCommits ( {
95- owner,
96- repo : repoName ,
97- sha : ref . replace ( "refs/heads/" , "" ) ,
98- per_page : 20 ,
99- page,
100- } )
101-
102- if ( ! commits . length ) break
103-
104- for ( const commit of commits ) {
105- //Filter by authoring
106- if ( ! commit . author || ! filters . text ( commit . author ?. email || commit . commit . author ?. email , this . authoring , { debug : false } ) ) {
107- continue
108- }
109-
110- //Skip merge commits
111- if ( commit . parents ?. length > 1 ) continue
112-
113- foundCommits ++
114- patches . push ( {
115- sha : commit . sha ,
116- name : `${ commit . commit . message } (authored by ${ commit . commit . author . name } on ${ commit . commit . author . date } )` ,
117- verified : commit . verification ?. verified ?? null ,
118- editions : ( commit . files ?? [ ] ) . map ( ( { filename, patch = "" } ) => {
119- const edition = {
120- path : filename ,
121- added : { lines : 0 , bytes : 0 } ,
122- deleted : { lines : 0 , bytes : 0 } ,
123- patch,
124- }
125- for ( const line of patch . split ( "\n" ) ) {
126- if ( ( ! / ^ [ - + ] / . test ( line ) ) || ( ! line . trim ( ) . length ) )
127- continue
128- if ( this . markers . line . test ( line ) ) {
129- const { op = "+" , content = "" } = line . match ( this . markers . line ) ?. groups ?? { }
130- const size = Buffer . byteLength ( content , "utf-8" )
131- edition [ { "+" : "added" , "-" : "deleted" } [ op ] ] . bytes += size
132- edition [ { "+" : "added" , "-" : "deleted" } [ op ] ] . lines ++
133- continue
134- }
135- }
136- return edition
137- } ) ,
138- } )
139-
140- if ( foundCommits >= this . load ) break
93+ const { data : commits } = await this . rest . request ( `GET /repos/{owner}/{repo}/commits` , {
94+ owner,
95+ repo : repoName ,
96+ sha : branch ,
97+ per_page : 100 ,
98+ } )
99+ //Filter by authoring and collect URLs
100+ for ( const commit of commits ) {
101+ const email = commit . author ?. email || commit . commit . author ?. email
102+ if ( email && filters . text ( email , this . authoring , { debug : false } ) && commit . parents ?. length <= 1 ) {
103+ commitUrls . push ( commit . url )
141104 }
142105 }
143- }
144- catch ( error ) {
145- this . debug ( `failed to fetch commits for ${ repo } on ${ ref } : ${ error } ` )
106+ } catch ( error ) {
107+ this . debug ( `failed to fetch commits for ${ repo } : ${ error } ` )
146108 }
147109 }
148110
111+ //Fetch full commit details with patches
112+ const patches = [
113+ ...await Promise . allSettled (
114+ commitUrls . map ( async url => ( await this . rest . request ( url ) ) . data ) ,
115+ ) ,
116+ ]
117+ . filter ( ( { status} ) => status === "fulfilled" )
118+ . map ( ( { value} ) => value )
119+ . map ( ( { sha, commit : { message, author} , verification, files} ) => ( {
120+ sha,
121+ name : `${ message } (authored by ${ author . name } on ${ author . date } )` ,
122+ verified : verification ?. verified ?? null ,
123+ editions : files . map ( ( { filename, patch = "" } ) => {
124+ const edition = {
125+ path : filename ,
126+ added : { lines : 0 , bytes : 0 } ,
127+ deleted : { lines : 0 , bytes : 0 } ,
128+ patch,
129+ }
130+ for ( const line of patch . split ( "\n" ) ) {
131+ if ( ( ! / ^ [ - + ] / . test ( line ) ) || ( ! line . trim ( ) . length ) )
132+ continue
133+ if ( this . markers . line . test ( line ) ) {
134+ const { op = "+" , content = "" } = line . match ( this . markers . line ) ?. groups ?? { }
135+ const size = Buffer . byteLength ( content , "utf-8" )
136+ edition [ { "+" : "added" , "-" : "deleted" } [ op ] ] . bytes += size
137+ edition [ { "+" : "added" , "-" : "deleted" } [ op ] ] . lines ++
138+ continue
139+ }
140+ }
141+ return edition
142+ } ) ,
143+ } ) )
144+
149145 return patches
150146 }
151147
0 commit comments