11import linguist from "linguist-js"
22
33/**Indepth analyzer */
4- export async function indepth ( { login, data, imports, repositories} , { skipped, categories, timeout} ) {
4+ export async function indepth ( { login, data, imports, repositories, gpg } , { skipped, categories, timeout} ) {
55 return new Promise ( async ( solve , reject ) => {
66 //Timeout
77 if ( Number . isFinite ( timeout ) ) {
88 console . debug ( `metrics/compute/${ login } /plugins > languages > timeout set to ${ timeout } m` )
99 setTimeout ( ( ) => reject ( `Reached maximum execution time of ${ timeout } m for analysis` ) , timeout * 60 * 1000 )
1010 }
1111
12+ //GPG keys imports
13+ for ( const { id, pub} of gpg ) {
14+ const path = imports . paths . join ( imports . os . tmpdir ( ) , `${ data . user . databaseId } .${ id } .gpg` )
15+ console . debug ( `metrics/compute/${ login } /plugins > languages > saving gpg ${ id } to ${ path } ` )
16+ try {
17+ await imports . fs . writeFile ( path , pub )
18+ if ( process . env . GITHUB_ACTIONS ) {
19+ console . debug ( `metrics/compute/${ login } /plugins > languages > importing gpg ${ id } ` )
20+ await imports . run ( `gpg --import ${ path } ` )
21+ }
22+ else
23+ console . debug ( `metrics/compute/${ login } /plugins > languages > skipping import of gpg ${ id } ` )
24+ }
25+ catch ( error ) {
26+ console . debug ( `metrics/compute/${ login } /plugins > languages > indepth > an error occured while importing gpg ${ id } , skipping...` )
27+ }
28+ finally {
29+ //Cleaning
30+ console . debug ( `metrics/compute/${ login } /plugins > languages > indepth > cleaning ${ path } ` )
31+ await imports . fs . rm ( path , { recursive :true , force :true } )
32+ }
33+ }
34+
1235 //Compute repositories stats from fetched repositories
13- const results = { total :0 , lines :{ } , stats :{ } , colors :{ } , commits :0 , files :0 , missed :0 }
36+ const results = { total :0 , lines :{ } , stats :{ } , colors :{ } , commits :0 , files :0 , missed :0 , verified : { signature : 0 } }
1437 for ( const repository of repositories ) {
1538 //Skip repository if asked
1639 if ( ( skipped . includes ( repository . name . toLocaleLowerCase ( ) ) ) || ( skipped . includes ( `${ repository . owner . login } /${ repository . name } ` . toLocaleLowerCase ( ) ) ) ) {
@@ -170,6 +193,7 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
170193 console . debug ( `metrics/compute/${ login } /plugins > languages > indepth > repo seems empty or impossible to git log, skipping` )
171194 return
172195 }
196+ const pending = [ ]
173197 for ( let page = 0 ; ; page ++ ) {
174198 try {
175199 console . debug ( `metrics/compute/${ login } /plugins > languages > indepth > processing commits ${ page * per_page } from ${ ( page + 1 ) * per_page } ` )
@@ -182,6 +206,14 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
182206 empty = false
183207 //Commits counter
184208 if ( / ^ c o m m i t [ 0 - 9 a - f ] { 40 } $ / . test ( line ) ) {
209+ if ( results . verified ) {
210+ const sha = line . match ( / [ 0 - 9 a - f ] { 40 } / ) ?. [ 0 ]
211+ if ( sha ) {
212+ pending . push ( imports . run ( `git verify-commit ${ sha } ` , { cwd :path , env :{ LANG :"en_GB" } } , { log :false , prefixed :false } )
213+ . then ( ( ) => results . verified . signature ++ )
214+ . catch ( ( ) => null ) )
215+ }
216+ }
185217 results . commits ++
186218 return
187219 }
@@ -223,6 +255,7 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
223255 results . missed += per_page
224256 }
225257 }
258+ await Promise . allSettled ( pending )
226259 results . files += edited . size
227260}
228261
0 commit comments