|
| 1 | +name: Create New Note for Daily LeetCode Problem |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # Allows for manual triggering |
| 5 | + |
| 6 | +jobs: |
| 7 | + create-note: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v2 |
| 13 | + |
| 14 | + - name: Fetch daily LeetCode problem details and create note |
| 15 | + env: |
| 16 | + GITHUB_USERNAME: ${{ github.actor }} |
| 17 | + run: | |
| 18 | + # Fetch problem details |
| 19 | + curl -X POST -H 'Content-Type: application/json' \ |
| 20 | + -d '{"query":"query questionOfToday { activeDailyCodingChallengeQuestion { date link question { questionId title titleSlug difficulty } } }","operationName":"questionOfToday"}' \ |
| 21 | + https://leetcode.com/graphql -o response.json |
| 22 | +
|
| 23 | + # Parse problem details |
| 24 | + PROBLEM_ID=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.questionId' response.json) |
| 25 | + TITLE=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.title' response.json) |
| 26 | + TITLE_SLUG=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.titleSlug' response.json) |
| 27 | + LINK="https://leetcode.com/problems/${TITLE_SLUG}" |
| 28 | +
|
| 29 | + # Create problem directory and note |
| 30 | + PROBLEM_DIR="problems/${PROBLEM_ID}" |
| 31 | + NOTE_FILE="${PROBLEM_DIR}/${GITHUB_USERNAME}.md" |
| 32 | + mkdir -p "${PROBLEM_DIR}" |
| 33 | + |
| 34 | + # Customize template and write to new file |
| 35 | + sed "s|<NUMBER>|${PROBLEM_ID}|g; s|<TITLE>|${TITLE}|g; s|<LINK TO DESCRIPTION>|${LINK}|g" problems/template.md > "${NOTE_FILE}" |
| 36 | +
|
| 37 | + - name: Commit and push changes |
| 38 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 39 | + with: |
| 40 | + commit_message: "Creating a template for ${{ github.actor }}'s solution to problem ${PROBLEM_ID}" |
| 41 | + branch: main |
| 42 | + file_pattern: problems/*/*.md |
0 commit comments