@@ -5,26 +5,79 @@ const execPromisified = util.promisify(exec);
5
5
6
6
async function gitCommitLogHandler ( repoId ) {
7
7
const repoPath = fetchRepopath . getRepoPath ( repoId ) ;
8
- return await execPromisified ( `git log --pretty=format:"%h||%an||%ad||%s"` , {
9
- cwd : repoPath ,
10
- windowsHide : true ,
11
- } ) . then ( ( res ) => {
12
- const { stdout, stderr } = res ;
13
-
14
- if ( stdout && ! stderr ) {
15
- let commits = stdout . trim ( ) ;
16
- let commitArray = commits . split ( "\n" ) . map ( ( commit ) => {
17
- return commitModel ( commit ) ;
18
- } ) ;
19
- return {
20
- commits : commitArray ,
21
- } ;
22
- } else {
8
+ return await execPromisified (
9
+ `git log --pretty=format:"%h||%an||%ad||%s" --date=short` ,
10
+ {
11
+ cwd : repoPath ,
12
+ windowsHide : true ,
13
+ }
14
+ )
15
+ . then ( async ( res ) => {
16
+ const { stdout, stderr } = res ;
17
+
18
+ if ( stdout && ! stderr ) {
19
+ let commits = stdout . trim ( ) ;
20
+
21
+ let commitRelativeTime = await execPromisified (
22
+ `git log --pretty=format:"%ad" --date=relative` ,
23
+ { cwd : repoPath , windowsHide : true }
24
+ )
25
+ . then ( ( { stdout, stderr } ) => {
26
+ if ( stdout ) {
27
+ return stdout . trim ( ) . split ( "\n" ) ;
28
+ } else {
29
+ console . log ( stderr ) ;
30
+ return [ ] ;
31
+ }
32
+ } )
33
+ . catch ( ( err ) => {
34
+ console . log ( err ) ;
35
+ return [ ] ;
36
+ } ) ;
37
+
38
+ let commitArray = commits . split ( "\n" ) . map ( async ( commit , index ) => {
39
+ commit += "||" + commitRelativeTime [ index ] ;
40
+ const commitFilesCount = await execPromisified (
41
+ `git diff-tree --no-commit-id --name-only -r ${
42
+ commit . split ( "||" ) [ 0 ]
43
+ } `,
44
+ { cwd : repoPath , windowsHide : true }
45
+ )
46
+ . then ( ( { stdout, stderr } ) => {
47
+ if ( stdout ) {
48
+ return stdout . trim ( ) . split ( "\n" ) . length ;
49
+ } else {
50
+ console . log ( "Error occurred!" ) ;
51
+ return 0 ;
52
+ }
53
+ } )
54
+ . catch ( ( err ) => {
55
+ console . log ( "Error occurred!" ) ;
56
+ return 0 ;
57
+ } ) ;
58
+ commit += "||" + commitFilesCount ;
59
+ return commitModel ( commit ) ;
60
+ } ) ;
61
+ return {
62
+ commits : commitArray ,
63
+ } ;
64
+ } else {
65
+ return {
66
+ commits : [ ] ,
67
+ } ;
68
+ }
69
+ } )
70
+ . catch ( ( err ) => {
71
+ console . log ( "ERROR : Commit log collection Error!" ) ;
23
72
return {
24
- commits : [ ] ,
73
+ hash : "" ,
74
+ author : "" ,
75
+ commitTime : "" ,
76
+ commitMessage : "" ,
77
+ commitRelativeTime : "" ,
78
+ commitFilesCount : 0 ,
25
79
} ;
26
- }
27
- } ) ;
80
+ } ) ;
28
81
}
29
82
30
83
function commitModel ( commit ) {
@@ -33,6 +86,8 @@ function commitModel(commit) {
33
86
author : "" ,
34
87
commitTime : "" ,
35
88
commitMessage : "" ,
89
+ commitRelativeTime : "" ,
90
+ commitFilesCount : 0 ,
36
91
} ;
37
92
38
93
let commitSplit = commit . split ( "||" ) ;
@@ -41,6 +96,8 @@ function commitModel(commit) {
41
96
commitObject . author = commitSplit [ 1 ] ;
42
97
commitObject . commitTime = commitSplit [ 2 ] ;
43
98
commitObject . commitMessage = commitSplit [ 3 ] ;
99
+ commitObject . commitRelativeTime = commitSplit [ 4 ] ;
100
+ commitObject . commitFilesCount = commitSplit [ 5 ] ;
44
101
45
102
return commitObject ;
46
103
}
0 commit comments