-
Notifications
You must be signed in to change notification settings - Fork 2
57 lines (51 loc) · 1.78 KB
/
feishu-notify.yml
File metadata and controls
57 lines (51 loc) · 1.78 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
name: Feishu Notifier
on:
push:
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send notification
env:
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK_URL }}
REPO: ${{ github.repository }}
ACTOR: ${{ github.actor }}
REF_NAME: ${{ github.ref_name }}
COMMITS_JSON: ${{ toJson(github.event.commits) }}
run: |
COUNT=$(echo "$COMMITS_JSON" | jq 'length')
LIST=""
for i in $(seq 0 $((COUNT-1))); do
MSG=$(echo "$COMMITS_JSON" | jq -r ".[$i].message" | head -1)
SHA=$(echo "$COMMITS_JSON" | jq -r ".[$i].id" | cut -c1-7)
URL=$(echo "$COMMITS_JSON" | jq -r ".[$i].url")
ITEM="• [$SHA]($URL): $MSG"
if [ -z "$LIST" ]; then
LIST="$ITEM"
else
LIST="$LIST<br>$ITEM"
fi
done
PAYLOAD=$(jq -n \
--arg repo "$REPO" \
--arg actor "$ACTOR" \
--arg ref "$REF_NAME" \
--arg count "$COUNT" \
--arg list "$LIST" \
'{
msg_type: "interactive",
card: {
config: { wide_screen_mode: true },
header: {
title: { tag: "plain_text", content: ("📦 " + $repo) },
template: "blue"
},
elements: [
{ tag: "div", text: { tag: "lark_md", content: ("**" + $actor + "** pushed **" + $count + " commit(s)** to **" + $ref + "** branch") } },
{ tag: "div", text: { tag: "lark_md", content: $list } }
]
}
}')
curl -s -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"