-
Notifications
You must be signed in to change notification settings - Fork 282
90 lines (83 loc) · 2.92 KB
/
Copy pathpush_notification.yml
File metadata and controls
90 lines (83 loc) · 2.92 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
name: GSI Push Main Notification
on:
push:
branches:
- main
permissions:
contents: read
jobs:
notify-push-main:
runs-on: ubuntu-latest
steps:
- name: Main Branch Push
run: |
echo "Workflow initiated by event with name: ${EVENT_NAME}"
echo "Pushing commit to main: ${HEAD_COMMIT_ID}"
echo "Pushed by: ${PUSHER_NAME}"
env:
EVENT_NAME: ${{ github.event_name }}
HEAD_COMMIT_ID: ${{ github.event.head_commit.id }}
PUSHER_NAME: ${{ github.event.pusher.name }}
- name: Push Notification to Google Chat
continue-on-error: true
shell: bash
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
COMMIT_MSG: ${{ github.event.head_commit.message }}
AUTHOR: ${{ github.event.head_commit.author.username }}
REPO: ${{ github.event.repository.full_name }}
COMPARE_URL: ${{ github.event.compare }}
run: |
if [ -z "$WEBHOOK_URL" ]; then
echo "WEBHOOK_URL secret is not set. Skipping notification."
exit 0
fi
PAYLOAD=$(jq -n \
--arg commit "$COMMIT_MSG" \
--arg author "$AUTHOR" \
--arg repo "$REPO" \
--arg compare "$COMPARE_URL" \
'
def guard(val): if (val == null or val == "") then "None" else val end;
{
cardsV2: [
{
cardId: "pushNotificationCard",
card: {
header: {
title: "Push to main branch",
subtitle: guard($commit)
},
sections: [
{
widgets: [
{ decoratedText: { topLabel: "Repo", text: guard($repo) } },
{ decoratedText: { topLabel: "Committed by", text: guard($author) } },
{
buttonList: {
buttons: [
{
text: "Ref comparison",
onClick: {
openLink: {
url: $compare
}
}
}
]
}
}
]
}
]
}
}
]
}')
RESPONSE=$(curl --fail-with-body --location --request POST "$WEBHOOK_URL" \
--header 'Content-Type: application/json; charset=UTF-8' \
--data-raw "$PAYLOAD" 2>&1) || {
echo "Failed to send Google Chat notification:"
echo "$RESPONSE"
exit 1
}