Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit daa1ad7

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 2637759 + f62f2bf commit daa1ad7

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

‎src/action.js‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ async function commit(params) {
100100
latestCommitSHA,
101101
submission,
102102
destinationFolder,
103-
commitHeader
103+
commitHeader,
104+
questionData
104105
} = params;
105106

106107
const name = normalizeName(submission.title);
@@ -120,12 +121,17 @@ async function commit(params) {
120121
message = `${commitName} Runtime - ${submission.runtime}, Memory - ${submission.memory}`;
121122
qid = '';
122123
}
123-
124-
const path = `${prefix}${qid}${name}/solution.${LANG_TO_EXTENSION[submission.lang]}`
124+
constquestionPath=`${prefix}${qid}${name}/README.md`;// Markdown file for the problem with question data
125+
const solutionPath = `${prefix}${qid}${name}/solution.${LANG_TO_EXTENSION[submission.lang]}`;// Separate file for the solution
125126

126127
const treeData = [
127128
{
128-
path,
129+
path: questionPath,
130+
mode: '100644',
131+
content: questionData,
132+
},
133+
{
134+
path: solutionPath,
129135
mode: '100644',
130136
content: `${submission.code}\n`, // Adds newline at EOF to conform to git recommendations
131137
}
@@ -170,6 +176,33 @@ async function commit(params) {
170176
return [treeResponse.data.sha, commitResponse.data.sha];
171177
}
172178

179+
async function getQuestionData(titleSlug, leetcodeSession) {
180+
log(`Getting question data for ${titleSlug}...`);
181+
182+
const headers = {
183+
"Content-Type": "application/json",
184+
"Cookie": `LEETCODE_SESSION=${leetcodeSession};`
185+
}
186+
187+
const graphql = JSON.stringify({
188+
query: `query getQuestionDetail($titleSlug: String!) {
189+
question(titleSlug: $titleSlug) {
190+
content
191+
}
192+
}`,
193+
variables: {"titleSlug": titleSlug},
194+
})
195+
196+
197+
try {
198+
const response = await axios.post("https://leetcode.com/graphql/", graphql, {headers});
199+
const result = await response.data;
200+
return result.data.question.content;
201+
} catch (error) {
202+
console.log('error', error);
203+
}
204+
}
205+
173206
// Returns false if no more submissions should be added.
174207
function addToSubmissions(params) {
175208
const {
@@ -304,11 +337,14 @@ async function sync(inputs) {
304337
let latestCommitSHA = commits.data[0].sha;
305338
let treeSHA = commits.data[0].commit.tree.sha;
306339
for (i = submissions.length - 1; i >= 0; i--) {
307-
letsubmission = submissions[i];
340+
submission = submissions[i];
308341
if (verbose != 'false') {
309342
submission = await getInfo(submission, leetcodeSession, leetcodeCSRFToken);
310343
}
311-
[treeSHA, latestCommitSHA] = await commit({ octokit, owner, repo, defaultBranch, commitInfo, treeSHA, latestCommitSHA, submission, destinationFolder, commitHeader })
344+
345+
// Get the question data for the submission.
346+
const questionData = await getQuestionData(submission.title_slug, leetcodeSession);
347+
[treeSHA, latestCommitSHA] = await commit({ octokit, owner, repo, defaultBranch, commitInfo, treeSHA, latestCommitSHA, submission, destinationFolder, commitHeader, questionData });
312348
}
313349
log('Done syncing all submissions.');
314350
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /