@@ -36,7 +36,19 @@ function normalizeName(problemName) {
3636 return problemName . toLowerCase ( ) . replace ( / \s / g, '_' ) ;
3737}
3838
39- async function commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission , destinationFolder ) {
39+ async function commit ( params ) {
40+ const {
41+ octokit,
42+ owner,
43+ repo,
44+ defaultBranch,
45+ commitInfo,
46+ treeSHA,
47+ latestCommitSHA,
48+ submission,
49+ destinationFolder
50+ } = params ;
51+
4052 const name = normalizeName ( submission . title ) ;
4153 log ( `Committing solution for ${ name } ...` ) ;
4254
@@ -92,7 +104,15 @@ async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA,
92104}
93105
94106// Returns false if no more submissions should be added.
95- function addToSubmissions ( response , lastTimestamp , filterDuplicateSecs , submissions_dict , submissions ) {
107+ function addToSubmissions ( params ) {
108+ const {
109+ response,
110+ lastTimestamp,
111+ filterDuplicateSecs,
112+ submissions_dict,
113+ submissions
114+ } = params ;
115+
96116 for ( const submission of response . data . submissions_dump ) {
97117 if ( submission . timestamp <= lastTimestamp ) {
98118 return false ;
@@ -115,7 +135,17 @@ function addToSubmissions(response, lastTimestamp, filterDuplicateSecs, submissi
115135 return true ;
116136}
117137
118- async function sync ( githubToken , owner , repo , filterDuplicateSecs , leetcodeCSRFToken , leetcodeSession , destinationFolder ) {
138+ async function sync ( inputs ) {
139+ const {
140+ githubToken,
141+ owner,
142+ repo,
143+ filterDuplicateSecs,
144+ leetcodeCSRFToken,
145+ leetcodeSession,
146+ destinationFolder
147+ } = inputs ;
148+
119149 const octokit = new Octokit ( {
120150 auth : githubToken ,
121151 userAgent : 'LeetCode sync to GitHub - GitHub Action' ,
@@ -183,7 +213,7 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
183213 await delay ( 1000 ) ;
184214 }
185215 response = await getSubmissions ( maxRetries ) ;
186- if ( ! addToSubmissions ( response , lastTimestamp , filterDuplicateSecs , submissions_dict , submissions ) ) {
216+ if ( ! addToSubmissions ( { response, lastTimestamp, filterDuplicateSecs, submissions_dict, submissions } ) ) {
187217 break ;
188218 }
189219
@@ -205,21 +235,21 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
205235 let treeSHA = commits . data [ 0 ] . commit . tree . sha ;
206236 for ( i = submissions . length - 1 ; i >= 0 ; i -- ) {
207237 submission = submissions [ i ] ;
208- [ treeSHA , latestCommitSHA ] = await commit ( octokit , owner , repo , defaultBranch , commitInfo , treeSHA , latestCommitSHA , submission , destinationFolder ) ;
238+ [ treeSHA , latestCommitSHA ] = await commit ( { octokit, owner, repo, defaultBranch, commitInfo, treeSHA, latestCommitSHA, submission, destinationFolder } ) ;
209239 }
210240 log ( 'Done syncing all submissions.' ) ;
211241}
212242
213243async function main ( ) {
214- const destinationFolder = core . getInput ( 'destination-folder' ) ;
215244 const githubToken = core . getInput ( 'github-token' ) ;
216245 const owner = context . repo . owner ;
217246 const repo = context . repo . repo ;
218247 const leetcodeCSRFToken = core . getInput ( 'leetcode-csrf-token' ) ;
219248 const leetcodeSession = core . getInput ( 'leetcode-session' ) ;
220249 const filterDuplicateSecs = core . getInput ( 'filter-duplicate-secs' ) ;
250+ const destinationFolder = core . getInput ( 'destination-folder' ) ;
221251
222- await sync ( githubToken , owner , repo , filterDuplicateSecs , leetcodeCSRFToken , leetcodeSession , destinationFolder ) ;
252+ await sync ( { githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFToken, leetcodeSession, destinationFolder } ) ;
223253}
224254
225255main ( ) . catch ( ( error ) => {
0 commit comments