@@ -52,18 +52,22 @@ async function commit(octokit, owner, repo, commitInfo, treeSHA, latestCommitSHA
5252 tree : treeData ,
5353 } )
5454
55+ const date = new Date ( submission . timestamp * 1000 ) . toISOString ( ) ;
5556 const commitResponse = await octokit . git . createCommit ( {
5657 owner : owner ,
5758 repo : repo ,
5859 message : `${ COMMIT_MESSAGE } - ${ submission . title } (${ submission . lang } )` ,
5960 tree : treeResponse . data . sha ,
6061 parents : [ latestCommitSHA ] ,
62+ author : {
63+ email : commitInfo . email ,
64+ name : commitInfo . name ,
65+ date : date ,
66+ } ,
6167 committer : {
6268 email : commitInfo . email ,
6369 name : commitInfo . name ,
64- email : '' ,
65- name : '' ,
66- date : new Date ( submission . timestamp * 1000 ) . toISOString ( ) ,
70+ date : date ,
6771 } ,
6872 } )
6973
@@ -117,10 +121,15 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
117121 } ) ;
118122
119123 let lastTimestamp = 0 ;
124+ // commitInfo is used to get the original name / email to use for the author / committer.
125+ // Since we need to modify the commit time, we can't use the default settings for the
126+ // authenticated user.
127+ let commitInfo = commits . data [ commits . data . length - 1 ] . commit . author ;
120128 for ( const commit of commits . data ) {
121129 if ( ! commit . commit . message . startsWith ( COMMIT_MESSAGE ) ) {
122130 continue
123131 }
132+ commitInfo = commit . commit . author ;
124133 lastTimestamp = Date . parse ( commit . commit . committer . date ) / 1000 ;
125134 break ;
126135 }
@@ -159,7 +168,6 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
159168 // Write in reverse order (oldest first), so that if there's errors, the last sync time
160169 // is still valid.
161170 console . log ( `Syncing ${ submissions . length } submissions...` ) ;
162- const commitInfo = commits . data [ commits . data . length - 1 ] . commit . committer ;
163171 let latestCommitSHA = commits . data [ 0 ] . sha ;
164172 let treeSHA = commits . data [ 0 ] . commit . tree . sha ;
165173 for ( i = submissions . length - 1 ; i >= 0 ; i -- ) {
@@ -178,4 +186,5 @@ async function main() {
178186
179187 sync ( githubToken , owner , repo , filterDuplicateSecs , leetcodeCSRFToken , leetcodeSession ) ;
180188}
189+
181190main ( ) . catch ( error => core . setFailed ( error ) ) ;
0 commit comments