Skip to content

Commit f6966c0

Browse files
committed
chore: add Feishu Notifier workflow [gh-actions-feishu]
1 parent a811872 commit f6966c0

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Feishu Notifier
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
notify:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Send notification
11+
env:
12+
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK_URL }}
13+
REPO: ${{ github.repository }}
14+
ACTOR: ${{ github.actor }}
15+
REF_NAME: ${{ github.ref_name }}
16+
COMMITS_JSON: ${{ toJson(github.event.commits) }}
17+
run: |
18+
COUNT=$(echo "$COMMITS_JSON" | jq 'length')
19+
20+
LIST=""
21+
for i in $(seq 0 $((COUNT-1))); do
22+
MSG=$(echo "$COMMITS_JSON" | jq -r ".[$i].message" | head -1)
23+
SHA=$(echo "$COMMITS_JSON" | jq -r ".[$i].id" | cut -c1-7)
24+
URL=$(echo "$COMMITS_JSON" | jq -r ".[$i].url")
25+
26+
ITEM="• [$SHA]($URL): $MSG"
27+
if [ -z "$LIST" ]; then
28+
LIST="$ITEM"
29+
else
30+
LIST="$LIST<br>$ITEM"
31+
fi
32+
done
33+
34+
PAYLOAD=$(jq -n \
35+
--arg repo "$REPO" \
36+
--arg actor "$ACTOR" \
37+
--arg ref "$REF_NAME" \
38+
--arg count "$COUNT" \
39+
--arg list "$LIST" \
40+
'{
41+
msg_type: "interactive",
42+
card: {
43+
config: { wide_screen_mode: true },
44+
header: {
45+
title: { tag: "plain_text", content: ("📦 " + $repo) },
46+
template: "blue"
47+
},
48+
elements: [
49+
{ tag: "div", text: { tag: "lark_md", content: ("**" + $actor + "** pushed **" + $count + " commit(s)** to **" + $ref + "** branch") } },
50+
{ tag: "div", text: { tag: "lark_md", content: $list } }
51+
]
52+
}
53+
}')
54+
55+
curl -s -X POST "$FEISHU_WEBHOOK" \
56+
-H "Content-Type: application/json" \
57+
-d "$PAYLOAD"

0 commit comments

Comments
 (0)