-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1problem1day-addNewIssue2project.yml
More file actions
109 lines (96 loc) · 3.79 KB
/
1problem1day-addNewIssue2project.yml
File metadata and controls
109 lines (96 loc) · 3.79 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Daily / Add issue to 1problem1day project
# 符合标题格式的issue自动添加到https://github.com/users/LetMeFly666/projects/5中
# Test at https://github.com/LetMeFly666/LeetCode-test
on:
issues:
types: [opened]
permissions:
issues: read
repository-projects: write
env:
PROJECT_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_PROJECT_ID }}
DATE_FIELD_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_DATE_FIELD_ID }}
jobs:
add:
runs-on: ubuntu-latest
steps:
- name: Add issue & set Date
id: add-issue-and-set-date
env:
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
run: |
title="${{ github.event.issue.title }}"
issue_node_id="${{ github.event.issue.node_id }}"
created_at="${{ github.event.issue.created_at }}"
if [[ ! "$title" =~ ^\[newSolution\]Who\ can\ add\ 1\ more\ problem\ of\ LeetCode\ [0-9]+.*$ ]]; then
echo "Title not match, skip"
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
date_cn=$(date -d "$created_at +8 hours" +%F)
echo "Add issue to project"
item_id=$(gh api graphql -f query='
mutation($project:ID!, $content:ID!) {
addProjectV2ItemById(input:{
projectId:$project
contentId:$content
}) {
item { id }
}
}
' \
-f project="$PROJECT_ID" \
-f content="$issue_node_id" \
--jq '.data.addProjectV2ItemById.item.id')
echo "Set Date field"
gh api graphql -f query='
mutation($project:ID!, $item:ID!, $field:ID!, $date:Date!) {
updateProjectV2ItemFieldValue(input:{
projectId:$project
itemId:$item
fieldId:$field
value:{ date:$date }
}) {
projectV2Item { id }
}
}
' \
-f project="$PROJECT_ID" \
-f item="$item_id" \
-f field="$DATE_FIELD_ID" \
-f date="$date_cn"
- name: Resolve workflow path
id: resolve-workflow-path
if: steps.add-issue-and-set-date.outputs.skip != 'true'
env:
REPO: ${{ github.repository }}
run: |
workflow_path=${GITHUB_WORKFLOW_REF#*/} # 去掉owner
workflow_path=${workflow_path#*/} # 去掉repo名
workflow_path=${workflow_path%@*} # 去掉@ref
action_file="https://github.com/$REPO/blob/$GITHUB_SHA/$workflow_path"
echo "action_file=$action_file" >> $GITHUB_OUTPUT
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
if: steps.add-issue-and-set-date.outputs.skip != 'true'
with:
app-id: ${{ vars.DAILY_BOT_APP_ID }}
private-key: ${{ secrets.DAILY_BOT_APP_PRIVATE_KEY }}
- name: Comment on issue
uses: actions/github-script@v7
if: steps.add-issue-and-set-date.outputs.skip != 'true'
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const now = new Date().toLocaleString('zh-CN', {
timeZone: 'Asia/Shanghai',
hour12: false
});
const actionFile = `${{ steps.resolve-workflow-path.outputs.action_file }}`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `This issue was automatically added to the project.\n🕒 Time (Beijing, UTC+8): ${now}\n🤖 Triggered by [1problem1day Bot](https://github.com/apps/1problem1day) according to [action file](${actionFile})`
});