Skip to content

joshcai/leetcode-sync

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Sync

GitHub Action for automatically syncing LeetCode submissions to a GitHub repository.

Features

  • Syncs accepted solutions from LeetCode to the default branch of the GitHub repo
  • Only syncs solutions that have not been synced before
  • Uploads the latest accepted solution for a single problem if there are multiple submissions per day

How to use

  1. Login to LeetCode and obtain the csrftoken and LEETCODE_SESSION cookie values.

    • After logging in, right-click on the page and press Inspect.
    • Refresh the page.
    • Look for a network request to https://leetcode.com.
    • Look under Request Headers for the cookie: attribute to find the values.
  2. Create a new GitHub repository to host the LeetCode submissions.

    • It can be either private or public.
  3. Add the values from step 1 as GitHub secrets, e.g. LEETCODE_CSRF_TOKEN and LEETCODE_SESSION.

  4. Add a workflow file with this action under the .github/workflows directory, e.g. sync_leetcode.yml.

    Example workflow file:

    name: Sync Leetcode
    
    on:
      workflow_dispatch:
      schedule:
        - cron:  '0 8 * * 6'
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - name: Sync
          uses: CherryKatatonic/[email protected]
          with:
            user: name
            github-token: ${{ github.token }}
            leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }}
            leetcode-session: ${{ secrets.LEETCODE_SESSION }}
  5. 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).

Inputs

  • user (optional): The user to sync (for shared repos)
  • github-token (required): The GitHub access token for pushing solutions to the repository
  • leetcode-csrf-token (required): The LeetCode CSRF token for retrieving submissions from LeetCode
  • leetcode-session (required): The LeetCode session value for retrieving submissions from LeetCode
  • filter-duplicate-secs: Number of seconds after an accepted solution to ignore other accepted solutions for the same problem, default: 86400 (1 day)

FAQ

Job fails with "HttpError: API rate limit exceeded for installation ID <id>"

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.

Acknowledgements

Special thanks to the following people who helped beta test this GitHub Action and gave feedback on improving it: