Skip to content

Commit a130447

Browse files
committed
chore: add dingtalk-notify.yml
1 parent dc3fbed commit a130447

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: DingTalk Notification
2+
3+
on:
4+
issues:
5+
types: [opened, edited, closed, reopened]
6+
pull_request:
7+
types: [opened, edited, closed, reopened, review_requested]
8+
9+
jobs:
10+
notify:
11+
runs-on: ubuntu-latest
12+
if: github.event.sender.type == 'User' # 只通知用户,忽略机器人
13+
steps:
14+
- name: Send to DingTalk
15+
run: |
16+
if [ "${{ github.event_name }}" == "issues" ]; then
17+
EVENT_TYPE="Issue"
18+
ACTION="${{ github.event.action }}"
19+
TITLE="${{ github.event.issue.title }}"
20+
URL="${{ github.event.issue.html_url }}"
21+
AUTHOR="${{ github.event.issue.user.login }}"
22+
else
23+
EVENT_TYPE="Pull Request"
24+
ACTION="${{ github.event.action }}"
25+
TITLE="${{ github.event.pull_request.title }}"
26+
URL="${{ github.event.pull_request.html_url }}"
27+
AUTHOR="${{ github.event.pull_request.user.login }}"
28+
fi
29+
30+
# 根据动作类型设置emoji
31+
case "$ACTION" in
32+
opened)
33+
EMOJI="🆕"
34+
;;
35+
edited)
36+
EMOJI="✏️"
37+
;;
38+
closed)
39+
EMOJI="✅"
40+
;;
41+
reopened)
42+
EMOJI="🔄"
43+
;;
44+
review_requested)
45+
EMOJI="👀"
46+
;;
47+
*)
48+
EMOJI="📌"
49+
;;
50+
esac
51+
52+
# 构造钉钉消息
53+
MESSAGE="{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"title\": \"GitHub ${EVENT_TYPE} ${ACTION}\",\n \"text\": \"## ${EMOJI} GitHub ${EVENT_TYPE} ${ACTION}\\n\\n**仓库**: ${{ github.repository }}\\n\\n**标题**: ${TITLE}\\n\\n**操作人**: ${AUTHOR}\\n\\n[查看详情](${URL})\"\n }\n }"
54+
55+
# 发送到钉钉
56+
curl -X POST "${{ secrets.DINGTALK_WEBHOOK }}" \
57+
-H "Content-Type: application/json" \
58+
-d "$MESSAGE"

0 commit comments

Comments
 (0)