-
Notifications
You must be signed in to change notification settings - Fork 1
178 lines (164 loc) · 7.28 KB
/
github-event-notification.yaml
File metadata and controls
178 lines (164 loc) · 7.28 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Notify (GitHub Events)
permissions:
issues: write
pull-requests: write
contents: read
on:
issues:
types: [opened, edited, reopened, closed, assigned, labeled]
pull_request:
types: [opened, closed, reopened, ready_for_review, review_requested]
pull_request_review:
types: [submitted, edited, dismissed]
issue_comment:
types: [created, edited]
pull_request_review_comment:
types: [created, edited]
jobs:
notify:
runs-on: ubuntu-latest
name: Send Notifications
steps:
- name: Determine Event Type
id: event_info
run: |
EVENT="${{ github.event_name }}"
ACTION="${{ github.event.action }}"
REPO="${{ github.repository }}"
ACTOR="${{ github.actor }}"
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
if [[ "$EVENT" == "issues" ]]; then
TITLE="Issue $ACTION: ${{ github.event.issue.title }}"
URL="${{ github.event.issue.html_url }}"
NUMBER="${{ github.event.issue.number }}"
USER="${{ github.event.issue.user.login }}"
DESCRIPTION="Issue #$NUMBER by $USER"
STATE="${{ github.event.issue.state }}"
EMOJI="🐛"
elif [[ "$EVENT" == "pull_request" ]]; then
NUMBER="${{ github.event.pull_request.number }}"
USER="${{ github.event.pull_request.user.login }}"
URL="${{ github.event.pull_request.html_url }}"
STATE="${{ github.event.pull_request.state }}"
SOURCE="${{ github.event.pull_request.head.ref }}"
TARGET="${{ github.event.pull_request.base.ref }}"
if [[ "$ACTION" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
TITLE="PR merged: ${{ github.event.pull_request.title }}"
EMOJI="✅"
STATE="merged"
elif [[ "$ACTION" == "closed" ]]; then
TITLE="PR closed: ${{ github.event.pull_request.title }}"
EMOJI="❌"
else
TITLE="PR $ACTION: ${{ github.event.pull_request.title }}"
EMOJI="🔀"
fi
DESCRIPTION="PR #$NUMBER by $USER: $SOURCE → $TARGET"
elif [[ "$EVENT" == "pull_request_review" ]]; then
TITLE="PR Review: ${{ github.event.pull_request.title }}"
URL="${{ github.event.review.html_url }}"
NUMBER="${{ github.event.pull_request.number }}"
USER="${{ github.event.review.user.login }}"
REVIEW_STATE="${{ github.event.review.state }}"
STATE="${{ github.event.review.state }}"
SOURCE="${{ github.event.pull_request.head.ref }}"
TARGET="${{ github.event.pull_request.base.ref }}"
DESCRIPTION="Review by $USER on PR #$NUMBER"
EMOJI="👀"
elif [[ "$EVENT" == "issue_comment" ]]; then
NUMBER="${{ github.event.issue.number }}"
USER="${{ github.event.comment.user.login }}"
URL="${{ github.event.comment.html_url }}"
STATE="commented"
if [[ "${{ github.event.issue.pull_request }}" != "" ]]; then
TITLE="Comment on PR: ${{ github.event.issue.title }}"
EMOJI="💬"
else
TITLE="Comment on Issue: ${{ github.event.issue.title }}"
EMOJI="💬"
fi
DESCRIPTION="Comment by $USER on #$NUMBER"
elif [[ "$EVENT" == "pull_request_review_comment" ]]; then
TITLE="Comment on PR: ${{ github.event.pull_request.title }}"
URL="${{ github.event.comment.html_url }}"
NUMBER="${{ github.event.pull_request.number }}"
USER="${{ github.event.comment.user.login }}"
STATE="commented"
SOURCE="${{ github.event.pull_request.head.ref }}"
TARGET="${{ github.event.pull_request.base.ref }}"
DESCRIPTION="Review comment by $USER on PR #$NUMBER"
EMOJI="💬"
else
TITLE="GitHub Event: $EVENT"
URL="${{ github.event.repository.html_url }}"
DESCRIPTION="Event triggered in $REPO"
STATE="N/A"
NUMBER="N/A"
USER="$ACTOR"
EMOJI="📢"
fi
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "url=$URL" >> $GITHUB_OUTPUT
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
echo "emoji=$EMOJI" >> $GITHUB_OUTPUT
echo "number=${NUMBER:-N/A}" >> $GITHUB_OUTPUT
echo "user=${USER:-$ACTOR}" >> $GITHUB_OUTPUT
echo "state=${STATE:-N/A}" >> $GITHUB_OUTPUT
echo "source=${SOURCE:-N/A}" >> $GITHUB_OUTPUT
echo "target=${TARGET:-N/A}" >> $GITHUB_OUTPUT
echo "repo_url=$REPO_URL" >> $GITHUB_OUTPUT
- name: Google Chat Notification
if: always()
uses: Co-qn/google-chat-notification@releases/v1
with:
name: ${{ steps.event_info.outputs.title }}
url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
status: ${{ job.status }}
- name: Slack Notification
if: always()
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"text": "${{ steps.event_info.outputs.title }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.event_info.outputs.emoji }} ${{ steps.event_info.outputs.title }}"
}
},
{
"type": "section",
"fields": [
{ "type": "mrkdwn", "text": "*Repository:*\n<${{ steps.event_info.outputs.repo_url }}|${{ github.repository }}>" },
{ "type": "mrkdwn", "text": "*Event:*\n${{ github.event_name }}" },
{ "type": "mrkdwn", "text": "*Author:*\n${{ steps.event_info.outputs.user }}" },
{ "type": "mrkdwn", "text": "*Action:*\n${{ github.event.action }}" },
{ "type": "mrkdwn", "text": "*Number:*\n<${{ steps.event_info.outputs.url }}|#${{ steps.event_info.outputs.number }}>" },
{ "type": "mrkdwn", "text": "*State:*\n${{ steps.event_info.outputs.state }}" }
]
},
{
"type": "section",
"text": { "type": "mrkdwn", "text": "${{ steps.event_info.outputs.description }}" }
},
{
"type": "actions",
"elements": [
{ "type": "button", "text": { "type": "plain_text", "text": "View on GitHub" }, "url": "${{ steps.event_info.outputs.url }}", "style": "primary" },
{ "type": "button", "text": { "type": "plain_text", "text": "View Repository" }, "url": "${{ steps.event_info.outputs.repo_url }}" }
]
},
{
"type": "context",
"elements": [
{ "type": "mrkdwn", "text": "Triggered by ${{ github.actor }} • ${{ github.event_name }} event" }
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}