@@ -25,13 +25,17 @@ const LANG_TO_EXTENSION = {
25
25
26
26
const delay = ms => new Promise ( res => setTimeout ( res , ms ) ) ;
27
27
28
+ function log ( message ) {
29
+ console . log ( `[${ new Date ( ) . toUTCString ( ) } ] ${ message } ` ) ;
30
+ }
31
+
28
32
function normalizeName ( problemName ) {
29
33
return problemName . toLowerCase ( ) . replace ( / \s / g, '_' ) ;
30
34
}
31
35
32
36
async function commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission ) {
33
37
const name = normalizeName ( submission . title ) ;
34
- console . log ( `Committing solution for ${ name } ...` ) ;
38
+ log ( `Committing solution for ${ name } ...` ) ;
35
39
36
40
if ( ! LANG_TO_EXTENSION [ submission . lang ] ) {
37
41
throw `Language ${ submission . lang } does not have a registered extension.` ;
@@ -79,7 +83,7 @@ async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA,
79
83
force : true
80
84
} ) ;
81
85
82
- console . log ( `Committed solution for ${ name } ` ) ;
86
+ log ( `Committed solution for ${ name } ` ) ;
83
87
84
88
return [ treeResponse . data . sha , commitResponse . data . sha ] ;
85
89
}
@@ -152,18 +156,17 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
152
156
'Cookie' : `csrftoken=${ leetcodeCSRFToken } ;LEETCODE_SESSION=${ leetcodeSession } ;` ,
153
157
} ,
154
158
} ;
155
- console . log ( `Getting submission from LeetCode, offset ${ offset } ` ) ;
159
+ log ( `Getting submission from LeetCode, offset ${ offset } ` ) ;
156
160
157
161
const getSubmissions = async ( maxRetries , retryCount = 0 ) => {
158
162
try {
159
163
const response = await axios . get ( 'https://leetcode.com/api/submissions/' , config ) ;
160
164
return response ;
161
165
} catch ( exception ) {
162
166
if ( retryCount >= maxRetries ) {
163
- console . log ( exception ) ;
164
167
throw exception ;
165
168
}
166
- console . log ( 'Error fetching submissions, retrying in ' + 3 ** retryCount + ' seconds...' ) ;
169
+ log ( 'Error fetching submissions, retrying in ' + 3 ** retryCount + ' seconds...' ) ;
167
170
// There's a rate limit on LeetCode API, so wait with backoff before retrying.
168
171
await delay ( 3 ** retryCount * 1000 ) ;
169
172
return getSubmissions ( maxRetries , retryCount + 1 ) ;
@@ -191,17 +194,17 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
191
194
repo : repo ,
192
195
} ) ;
193
196
const defaultBranch = repoInfo . data . default_branch ;
194
- console . log ( `Default branch for ${ owner } /${ repo } : ${ defaultBranch } ` ) ;
197
+ log ( `Default branch for ${ owner } /${ repo } : ${ defaultBranch } ` ) ;
195
198
// Write in reverse order (oldest first), so that if there's errors, the last sync time
196
199
// is still valid.
197
- console . log ( `Syncing ${ submissions . length } submissions...` ) ;
200
+ log ( `Syncing ${ submissions . length } submissions...` ) ;
198
201
let latestCommitSHA = commits . data [ 0 ] . sha ;
199
202
let treeSHA = commits . data [ 0 ] . commit . tree . sha ;
200
203
for ( i = submissions . length - 1 ; i >= 0 ; i -- ) {
201
204
submission = submissions [ i ] ;
202
205
[ treeSHA , latestCommitSHA ] = await commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission ) ;
203
206
}
204
- console . log ( 'Done syncing all submissions.' ) ;
207
+ log ( 'Done syncing all submissions.' ) ;
205
208
}
206
209
207
210
async function main ( ) {
@@ -215,4 +218,8 @@ async function main() {
215
218
await sync ( githubToken , owner , repo , filterDuplicateSecs , leetcodeCSRFToken , leetcodeSession ) ;
216
219
}
217
220
218
- main ( ) . catch ( error => core . setFailed ( error ) ) ;
221
+ main ( ) . catch ( ( error ) => {
222
+ log ( error . stack ) ;
223
+ core . setFailed ( error )
224
+ } ) ;
225
+
0 commit comments