-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1problem1day-autoGenIssueEveryday.yml
More file actions
53 lines (45 loc) · 1.87 KB
/
1problem1day-autoGenIssueEveryday.yml
File metadata and controls
53 lines (45 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Daily / Generate LeetCode Daily Issue
# 每天北京时间0点自动创建今天的每日一题issue
on:
schedule:
- cron: '0 16 * * *' # UTC 16 = 北京 0 点
workflow_dispatch:
permissions:
issues: write
jobs:
daily:
runs-on: ubuntu-latest
steps:
- name: Fetch LeetCode daily question
id: fetch
run: |
date=$(TZ=Asia/Shanghai date +%Y-%m-%d)
year=${date:0:4}
month=${date:5:2}
curl -s https://leetcode.cn/graphql/ \
-H 'Content-Type: application/json' \
-d "{
\"query\":\"query dailyQuestionRecords(\$year:Int!,\$month:Int!){dailyQuestionRecords(year:\$year,month:\$month){date question{questionFrontendId titleSlug translatedTitle}}}\",
\"variables\":{\"year\":\"$year\",\"month\":\"$month\"}
}" \
| jq -r --arg d "$date" '
.data.dailyQuestionRecords[]
| select(.date==$d)
| "\(.question.questionFrontendId)|\(.question.titleSlug)|\(.question.translatedTitle)"
' > daily.txt
- name: Create issue
env:
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
REPO: ${{ github.repository }}
run: |
IFS='|' read -r id slug title < daily.txt
date=$(TZ=Asia/Shanghai date +%Y-%m-%d)
workflow_path=${GITHUB_WORKFLOW_REF#*/} # 去掉owner
workflow_path=${workflow_path#*/} # 去掉repo名
workflow_path=${workflow_path%@*} # 去掉@ref
gh issue create \
--title "[newSolution]Who can add 1 more problem of LeetCode $id" \
--body "By Github [Actions](https://github.com/$REPO/blob/$GITHUB_SHA/$workflow_path) | [$id.$title](https://leetcode.cn/problems/$slug/) | $date" \
--label 题解 \
--assignee LetMeFly666 \
--repo "$REPO"