@@ -29,7 +29,7 @@ function normalizeName(problemName) {
29
29
return problemName . toLowerCase ( ) . replace ( / \s / g, '_' ) ;
30
30
}
31
31
32
- async function commit ( octokit , owner , repo , commitInfo , treeSHA , latestCommitSHA , submission ) {
32
+ async function commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission ) {
33
33
const name = normalizeName ( submission . title ) ;
34
34
console . log ( `Committing solution for ${ name } ...` ) ;
35
35
@@ -75,7 +75,7 @@ async function commit(octokit, owner, repo, commitInfo, treeSHA, latestCommitSHA
75
75
owner : owner ,
76
76
repo : repo ,
77
77
sha : commitResponse . data . sha ,
78
- ref : 'heads/master' ,
78
+ ref : 'heads/' + defaultBranch ,
79
79
force : true
80
80
} ) ;
81
81
@@ -185,14 +185,21 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
185
185
} while ( response . data . has_next ) ;
186
186
187
187
// We have all submissions we want to write to GitHub now.
188
+ // First, get the default branch to write to.
189
+ const repoInfo = await octokit . repos . get ( {
190
+ owner : owner ,
191
+ repo : repo ,
192
+ } ) ;
193
+ const defaultBranch = repoInfo . data . default_branch ;
194
+ console . log ( `Default branch for ${ owner } /${ repo } : ${ defaultBranch } ` ) ;
188
195
// Write in reverse order (oldest first), so that if there's errors, the last sync time
189
196
// is still valid.
190
197
console . log ( `Syncing ${ submissions . length } submissions...` ) ;
191
198
let latestCommitSHA = commits . data [ 0 ] . sha ;
192
199
let treeSHA = commits . data [ 0 ] . commit . tree . sha ;
193
200
for ( i = submissions . length - 1 ; i >= 0 ; i -- ) {
194
201
submission = submissions [ i ] ;
195
- [ treeSHA , latestCommitSHA ] = await commit ( octokit , owner , repo , commitInfo , treeSHA , latestCommitSHA , submission ) ;
202
+ [ treeSHA , latestCommitSHA ] = await commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission ) ;
196
203
}
197
204
console . log ( 'Done syncing all submissions.' ) ;
198
205
}
0 commit comments