@@ -59,13 +59,13 @@ const getCommitData = (contents: CommitContent[]) => {
59
59
. chain ( contents )
60
60
. filter ( { type : 1 } )
61
61
. map ( ( x ) => {
62
- console . log ( { x } ) ;
62
+ console . debug ( { x } ) ;
63
63
64
64
const formattedContent = x . content . split ( '\n' ) ;
65
- console . log ( { formattedContent } ) ;
65
+ console . debug ( { formattedContent } ) ;
66
66
67
67
const parts = formattedContent . filter ( ( part ) => part . length > 0 ) ;
68
- console . log ( { parts } ) ;
68
+ console . debug ( { parts } ) ;
69
69
70
70
if ( ! parts || parts . length < 5 ) {
71
71
throw new Error ( 'Invalid commit data' ) ;
@@ -75,51 +75,50 @@ const getCommitData = (contents: CommitContent[]) => {
75
75
. find ( ( t ) => t . split ( ' ' ) [ 0 ] === 'tree' )
76
76
?. replace ( 'tree' , '' )
77
77
. trim ( ) ;
78
- console . log ( { tree } ) ;
78
+ console . debug ( { tree } ) ;
79
79
80
80
const parentValue = parts . find ( ( t ) => t . split ( ' ' ) [ 0 ] === 'parent' ) ;
81
- console . log ( { parentValue } ) ;
81
+ console . debug ( { parentValue } ) ;
82
82
83
83
const parent = parentValue
84
84
? parentValue . replace ( 'parent' , '' ) . trim ( )
85
85
: '0000000000000000000000000000000000000000' ;
86
- console . log ( { parent } ) ;
86
+ console . debug ( { parent } ) ;
87
87
88
- const author = parts
88
+ const authorStr = parts
89
89
. find ( ( t ) => t . split ( ' ' ) [ 0 ] === 'author' )
90
90
?. replace ( 'author' , '' )
91
91
. trim ( ) ;
92
- console . log ( { author } ) ;
93
-
94
- const committer = parts
92
+ // handle email-like author string: "UserName <[email protected] > 1746612538 +0100"
93
+ const author = authorStr ?. split ( '<' ) [ 0 ] . trim ( ) ;
94
+ // slice to trim start and end from `<[email protected] >`
95
+ const authorEmail = authorStr ?. split ( ' ' ) . reverse ( ) [ 2 ] . slice ( 1 , - 1 ) ;
96
+ console . debug ( { authorStr, author, authorEmail } ) ;
97
+
98
+ // handle email-like committer string: "UserName <[email protected] > 1746612538 +0100"
99
+ const committerStr = parts
95
100
. find ( ( t ) => t . split ( ' ' ) [ 0 ] === 'committer' )
96
101
?. replace ( 'committer' , '' )
97
102
. trim ( ) ;
98
- console . log ( { committer } ) ;
103
+ const committer = committerStr ?. split ( '<' ) [ 0 ] . trim ( ) ;
104
+ const committerArr = committerStr ?. split ( ' ' ) . reverse ( ) ?? [ ] ;
105
+ const commitTimestamp = committerArr [ 1 ] ;
106
+ // slice to trim start and end from `<[email protected] >`
107
+ const committerEmail = committerArr [ 2 ] ?. slice ( 1 , - 1 ) ;
108
+ console . debug ( { committerStr, committer, committerEmail, commitTimestamp } ) ;
99
109
100
110
const indexOfMessages = formattedContent . indexOf ( '' ) ;
101
- console . log ( { indexOfMessages } ) ;
102
-
103
111
const message = formattedContent
104
112
. slice ( indexOfMessages + 1 )
105
113
. join ( ' ' )
106
114
. trim ( ) ;
107
- console . log ( { message } ) ;
108
-
109
- const commitTimestamp = committer ?. split ( ' ' ) . reverse ( ) [ 1 ] ;
110
- console . log ( { commitTimestamp } ) ;
111
-
112
- const authorEmail = author ?. split ( ' ' ) . reverse ( ) [ 2 ] . slice ( 1 , - 1 ) ;
113
- console . log ( { authorEmail } ) ;
114
-
115
- const committerEmail = committer ?. split ( ' ' ) . reverse ( ) [ 2 ] . slice ( 1 , - 1 ) ;
116
- console . log ( { committerEmail } ) ;
115
+ console . debug ( { indexOfMessages, message } ) ;
117
116
118
117
console . log ( {
119
118
tree,
120
119
parent,
121
- author : author ?. split ( '<' ) [ 0 ] . trim ( ) ,
122
- committer : committer ?. split ( '<' ) [ 0 ] . trim ( ) ,
120
+ author,
121
+ committer,
123
122
commitTimestamp,
124
123
message,
125
124
authorEmail,
@@ -142,8 +141,8 @@ const getCommitData = (contents: CommitContent[]) => {
142
141
return {
143
142
tree,
144
143
parent,
145
- author : author . split ( '<' ) [ 0 ] . trim ( ) ,
146
- committer : committer . split ( '<' ) [ 0 ] . trim ( ) ,
144
+ author,
145
+ committer,
147
146
commitTimestamp,
148
147
message,
149
148
authorEmail,
0 commit comments