Skip to content

Commit 549a44e

Browse files
author
Kat Grennan
committed
Create a folder in repo for each user
1 parent c4855c7 commit 549a44e

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

index.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function normalizeName(problemName) {
3636
return problemName.toLowerCase().replace(/\s/g, '_');
3737
}
3838

39-
async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA, latestCommitSHA, submission) {
39+
async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA, latestCommitSHA, submission, user) {
4040
const name = normalizeName(submission.title);
4141
log(`Committing solution for ${name}...`);
4242

@@ -46,12 +46,12 @@ async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA,
4646

4747
const treeData = [
4848
{
49-
path: `problems/${name}/solution.${LANG_TO_EXTENSION[submission.lang]}`,
49+
path: `${user}/problems/${name}/solution.${LANG_TO_EXTENSION[submission.lang]}`,
5050
mode: '100644',
5151
content: submission.code,
5252
}
5353
];
54-
54+
5555
const treeResponse = await octokit.git.createTree({
5656
owner: owner,
5757
repo: repo,
@@ -93,25 +93,25 @@ async function commit(octokit, owner, repo, defaultBranch, commitInfo, treeSHA,
9393

9494
// Returns false if no more submissions should be added.
9595
function addToSubmissions(response, lastTimestamp, filterDuplicateSecs, submissions_dict, submissions) {
96-
for (const submission of response.data.submissions_dump) {
97-
if (submission.timestamp <= lastTimestamp) {
98-
return false;
99-
}
100-
if (submission.status_display !== 'Accepted') {
101-
continue;
102-
}
103-
const name = normalizeName(submission.title);
104-
const lang = submission.lang;
105-
if (!submissions_dict[name]) {
106-
submissions_dict[name] = {};
107-
}
108-
// Filter out other accepted solutions less than one day from the most recent one.
109-
if (submissions_dict[name][lang] && submissions_dict[name][lang] - submission.timestamp < filterDuplicateSecs) {
110-
continue;
111-
}
112-
submissions_dict[name][lang] = submission.timestamp;
113-
submissions.push(submission);
96+
for (const submission of response.data.submissions_dump) {
97+
if (submission.timestamp <= lastTimestamp) {
98+
return false;
11499
}
100+
if (submission.status_display !== 'Accepted') {
101+
continue;
102+
}
103+
const name = normalizeName(submission.title);
104+
const lang = submission.lang;
105+
if (!submissions_dict[name]) {
106+
submissions_dict[name] = {};
107+
}
108+
// Filter out other accepted solutions less than one day from the most recent one.
109+
if (submissions_dict[name][lang] && submissions_dict[name][lang] - submission.timestamp < filterDuplicateSecs) {
110+
continue;
111+
}
112+
submissions_dict[name][lang] = submission.timestamp;
113+
submissions.push(submission);
114+
}
115115
return true;
116116
}
117117

@@ -131,7 +131,7 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
131131
// commitInfo is used to get the original name / email to use for the author / committer.
132132
// Since we need to modify the commit time, we can't use the default settings for the
133133
// authenticated user.
134-
let commitInfo = commits.data[commits.data.length-1].commit.author;
134+
let commitInfo = commits.data[commits.data.length - 1].commit.author;
135135
for (const commit of commits.data) {
136136
if (!commit.commit.message.startsWith(COMMIT_MESSAGE)) {
137137
continue
@@ -156,7 +156,7 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
156156
headers: {
157157
'X-Requested-With': 'XMLHttpRequest',
158158
'X-CSRFToken': leetcodeCSRFToken,
159-
'Cookie': `csrftoken=${leetcodeCSRFToken};LEETCODE_SESSION=${leetcodeSession};`,
159+
'Cookie': `csrftoken=${leetcodeCSRFToken};LEETCODE_SESSION=${leetcodeSession};`,
160160
},
161161
};
162162
log(`Getting submission from LeetCode, offset ${offset}`);
@@ -211,6 +211,7 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
211211
}
212212

213213
async function main() {
214+
const user = core.getInput('user');
214215
const githubToken = core.getInput('github-token');
215216
const owner = context.repo.owner;
216217
const repo = context.repo.repo;

0 commit comments

Comments
 (0)