@@ -3,28 +3,39 @@ import { OwnedFile } from './lib/OwnedFile';
33import { OwnershipEngine } from './lib/OwnershipEngine' ;
44import { readDirRecursively } from './lib/readDirRecursively' ;
55import { readTrackedGitFiles } from './lib/readTrackedGitFiles' ;
6+ import { countLinesInFile } from './lib/countLinesInFile' ;
67
78export const getFileOwnership = async ( options : { codeowners : string , dir : string , onlyGit : boolean , root ?: string } ) : Promise < OwnedFile [ ] > => {
9+ const filePaths = await getFilePaths ( options . dir , options . onlyGit , options . root ) ;
10+
811 const engine = OwnershipEngine . FromCodeownersFile ( options . codeowners ) ;
912
13+ const files : OwnedFile [ ] = [ ] ;
14+
15+ for ( const filePath of filePaths ) {
16+ const owners = engine . calcFileOwnership ( filePath ) ;
17+ const lines = await countLinesInFile ( filePath ) ;
18+
19+ files . push ( new OwnedFile ( { path : filePath , owners, lines } ) ) ;
20+ }
21+
22+ return files ;
23+ } ;
24+
25+ const getFilePaths = async ( dir : string , onlyGit : boolean , root ?: string ) => {
1026 let filePaths ;
11- if ( options . onlyGit ) {
12- filePaths = await readTrackedGitFiles ( options . dir ) ;
27+
28+ if ( onlyGit ) {
29+ filePaths = await readTrackedGitFiles ( dir ) ;
1330 } else {
14- filePaths = await readDirRecursively ( options . dir , [ '.git' ] ) ;
31+ filePaths = await readDirRecursively ( dir , [ '.git' ] ) ;
1532 }
1633
17- if ( options . root ) { // We need to re-add the root so that later ops can find the file
18- filePaths = filePaths . map ( filePath => path . join ( < string > options . root , filePath ) ) ;
34+ if ( root ) { // We need to re-add the root so that later ops can find the file
35+ filePaths = filePaths . map ( filePath => path . join ( root , filePath ) ) ;
1936 }
2037
2138 filePaths . sort ( ) ;
2239
23- const files : OwnedFile [ ] = [ ] ;
24-
25- for ( const filePath of filePaths ) {
26- files . push ( await OwnedFile . FromPath ( filePath , engine ) ) ;
27- }
28-
29- return files ;
40+ return filePaths ;
3041} ;
0 commit comments