Skip to content

Commit 4303d02

Browse files
committed
Rewrote condition for syntax consistency and reverted README changes for merge
- Changed condition to "submission === null" in src/action.js for syntax consistency. - Reverted "uses" line in README.md to point back to joshcai/leetcode-sync@v1.6. - Removed self-crediting section from README.md. Agreed to include this information in the release notes instead.
1 parent b3271cd commit 4303d02

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

README.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ GitHub Action for automatically syncing LeetCode submissions to a GitHub reposit
4848

4949
steps:
5050
- name: Sync
51-
uses: AlyHG/leetcode-sync@master
51+
uses: joshcai/leetcode-sync@v1.6
5252
with:
5353
github-token: ${{ github.token }}
5454
leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }}
5555
leetcode-session: ${{ secrets.LEETCODE_SESSION }}
5656
destination-folder: my-folder
5757
verbose: true
58-
commit-header: '[LeetCode Sync]'
58+
commit-header: "[LeetCode Sync]"
5959
```
6060
6161
6. After you've submitted a LeetCode solution, run the workflow by going to the `Actions` tab, clicking the action name, e.g. `Sync Leetcode`, and then clicking `Run workflow`. The workflow will also automatically run once a week by default (can be configured via the `cron` parameter).
@@ -101,6 +101,7 @@ Since this file is in the `.gitignore` file to avoid users accidentally committi
101101
This likely means that you hit a rate limit when committing to GitHub (this may happen if you have over ~300 submissions initially). Since the syncer writes in reverse chronological order, it should pick up syncing submissions from where it left off on the next run of the workflow, so just retry the workflow manually after some time.
102102

103103
#### Job fails with "HttpError: Resource not accessible by integration"
104+
104105
This means the github token you're using does not have permission to write to your repo. If you're using the default `github.token` method follow the instructions [here] (https://docs.github.com/en/actions/security-guides/automatic-token-authentication)
105106

106107
## Acknowledgements
@@ -111,17 +112,3 @@ Special thanks to the following people who helped beta test this GitHub Action a
111112
- [uakfdotb](https://github.com/uakfdotb)
112113
- [hexecute](https://github.com/hexecute)
113114
- [JonathanZhu11](https://github.com/JonathanZhu11)
114-
115-
## Updated by [Aly Ghallab](https://github.com/AlyHG) to Handle Locked LeetCode Premium Problems and Improve Sync Reliability - June 19, 2024
116-
117-
- **Error Handling for Locked Problems:** Added error handling in the `getInfo` function to skip locked problems. When the function encounters a locked problem (HTTP 403 error), it logs a message and skips the problem instead of retrying or throwing an exception.
118-
- **Fetching Question Data:** Updated the `getQuestionData` function to handle errors when fetching question data for locked problems. If fetching the question data results in a locked problem error (HTTP 403), it logs the error and returns null to indicate that the problem should be skipped.
119-
- **Sync Function Modification:** Modified the `sync` function to continue syncing other problems even if some are locked, ensuring that locked problems do not cause the entire sync process to fail.
120-
- **Additional Logging:** Added logging to help identify and skip locked problems during the sync process.
121-
122-
123-
These changes improve the sync process by handling scenarios where some LeetCode problems are locked, allowing the action to continue syncing all available, unlocked problems successfully.
124-
125-
126-
127-

src/action.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ async function getInfo(submission, session, csrfToken) {
8787
headers,
8888
});
8989
const runtimePercentile = `${response.data.data.submissionDetails.runtimePercentile.toFixed(
90-
2,
90+
2
9191
)}%`;
9292
const memoryPercentile = `${response.data.data.submissionDetails.memoryPercentile.toFixed(
93-
2,
93+
2
9494
)}%`;
9595
const questionId = pad(
96-
response.data.data.submissionDetails.question.questionId.toString(),
96+
response.data.data.submissionDetails.question.questionId.toString()
9797
);
9898

9999
log(`Got info for submission #${submission.id}`);
@@ -104,18 +104,18 @@ async function getInfo(submission, session, csrfToken) {
104104
code: response.data.data.submissionDetails.code,
105105
};
106106
} catch (exception) {
107-
if (retryCount >= maxRetries) {
107+
if (retryCount >= maxRetries) {
108108
// If problem is locked due to user not having LeetCode Premium
109109
if (exception.response && exception.response.status === 403) {
110110
log(`Skipping locked problem: ${submission.title}`);
111-
return null;
111+
return null;
112112
}
113113
throw exception;
114114
}
115115
log(
116116
"Error fetching submission info, retrying in " +
117117
3 ** retryCount +
118-
" seconds...",
118+
" seconds..."
119119
);
120120
await delay(3 ** retryCount * 1000);
121121
return getInfo(maxRetries, retryCount + 1);
@@ -235,15 +235,15 @@ async function getQuestionData(titleSlug, leetcodeSession, csrfToken) {
235235
const response = await axios.post(
236236
"https://leetcode.com/graphql/",
237237
graphql,
238-
{ headers },
238+
{ headers }
239239
);
240240
const result = await response.data;
241241
return result.data.question.content;
242242
} catch (error) {
243243
// If problem is locked due to user not having LeetCode Premium
244244
if (error.response && error.response.status === 403) {
245245
log(`Skipping locked problem: ${titleSlug}`);
246-
return null;
246+
return null;
247247
}
248248
console.log("error", error);
249249
}
@@ -317,7 +317,7 @@ async function sync(inputs) {
317317
for (const commit of commits.data) {
318318
if (
319319
!commit.commit.message.startsWith(
320-
!!commitHeader ? commitHeader : COMMIT_MESSAGE,
320+
!!commitHeader ? commitHeader : COMMIT_MESSAGE
321321
)
322322
) {
323323
continue;
@@ -365,7 +365,7 @@ async function sync(inputs) {
365365
const response = await axios.post(
366366
"https://leetcode.com/graphql/",
367367
graphql,
368-
{ headers },
368+
{ headers }
369369
);
370370
log(`Successfully fetched submission from LeetCode, offset ${offset}`);
371371
return response;
@@ -376,7 +376,7 @@ async function sync(inputs) {
376376
log(
377377
"Error fetching submissions, retrying in " +
378378
3 ** retryCount +
379-
" seconds...",
379+
" seconds..."
380380
);
381381
// There's a rate limit on LeetCode API, so wait with backoff before retrying.
382382
await delay(3 ** retryCount * 1000);
@@ -423,19 +423,19 @@ async function sync(inputs) {
423423
submission = await getInfo(
424424
submissions[i],
425425
leetcodeSession,
426-
leetcodeCSRFToken,
426+
leetcodeCSRFToken
427427
);
428-
if (!submission) {
428+
429+
if (submission === null) {
429430
// Skip this submission if it is null (locked problem)
430431
continue;
431432
}
432433

433-
434434
// Get the question data for the submission.
435435
const questionData = await getQuestionData(
436436
submission.titleSlug,
437437
leetcodeSession,
438-
leetcodeCSRFToken,
438+
leetcodeCSRFToken
439439
);
440440
if (questionData === null) {
441441
// Skip this submission if question data is null (locked problem)

0 commit comments

Comments
 (0)