Repository navigation
103 lines (96 loc) · 3.95 KB
/
Copy pathpr_notification.yml
File metadata and controls
103 lines (96 loc) · 3.95 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
name: GSI Chatroom PR Notification
on:
pull_request:
types: [review_requested]
permissions:
contents: read
jobs:
notify-pull-request:
runs-on: ubuntu-latest
steps:
- name: Pull Request Details
run: |
echo "Pull Request: ${PR_NUMBER}"
echo "Author: ${AUTHOR}"
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
AUTHOR: ${{ github.event.pull_request.user.login }}
- name: Google Chat Notification
continue-on-error: true
shell: bash
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
PR_NUMBER: ${{ github.event.pull_request.number }}
TITLE: ${{ github.event.pull_request.title }}
LABELS: ${{ join(github.event.pull_request.labels.*.name, ', ') }}
REPO: ${{ github.event.pull_request.head.repo.full_name }}
CREATOR: ${{ github.event.pull_request.user.login }}
STATE: ${{ github.event.pull_request.state }}
ASSIGNEES: ${{ join(github.event.pull_request.assignees.*.login, ', ') }}
REVIEWERS: ${{ join(github.event.pull_request.requested_reviewers.*.login, ', ') }}
URL: ${{ github.event.pull_request.html_url }}
run: |
if [ -z "$WEBHOOK_URL" ]; then
echo "WEBHOOK_URL secret is not set (e.g. fork PR). Skipping notification."
exit 0
fi
PAYLOAD=$(jq -n \
--arg pr_num "$PR_NUMBER" \
--arg title "$TITLE" \
--arg labels "$LABELS" \
--arg repo "$REPO" \
--arg creator "$CREATOR" \
--arg state "$STATE" \
--arg assignees "$ASSIGNEES" \
--arg reviewers "$REVIEWERS" \
--arg url "$URL" \
'
def guard(val): if (val == null or val == "") then "None" else val end;
def guard_list(val): if (val == null or val == "") then "None" else "- " + val end;
{
cardsV2: [
{
cardId: "prNotificationCard",
card: {
header: {
title: "Pull request notification",
subtitle: ("Pull request: #" + guard($pr_num))
},
sections: [
{
widgets: [
{ decoratedText: { topLabel: "Repo", text: guard($repo) } },
{ decoratedText: { topLabel: "Title", text: guard($title) } },
{ decoratedText: { topLabel: "Creator", text: guard($creator) } },
{ decoratedText: { topLabel: "State", text: guard($state) } },
{ decoratedText: { topLabel: "Assignees", text: guard_list($assignees) } },
{ decoratedText: { topLabel: "Reviewers", text: guard_list($reviewers) } },
{ decoratedText: { topLabel: "Labels", text: guard_list($labels) } },
{
buttonList: {
buttons: [
{
text: "Open Pull Request",
onClick: {
openLink: {
url: $url
}
}
}
]
}
}
]
}
]
}
}
]
}')
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
}