-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmatrix-all-github-activity-notification.yml
More file actions
387 lines (355 loc) · 13.1 KB
/
Copy pathmatrix-all-github-activity-notification.yml
File metadata and controls
387 lines (355 loc) · 13.1 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: 'Matrix All Activity Notifications'
on:
# Issues
issues:
types: [opened, closed, reopened]
# edited, assigned, unassigned, labeled, unlabeled, locked, unlocked, transferred, pinned, unpinned]
# Issue Comments
#issue_comment:
# types: [created] #, edited, deleted]
# Pull Requests
pull_request:
types: [opened] # , edited, closed]
# , reopened, assigned, unassigned, review_requested, review_request_removed, labeled, unlabeled, synchronize, converted_to_draft, ready_for_review, locked, unlocked]
# Pull Request Reviews
# pull_request_review:
# types: [submitted] # , edited, dismissed]
# Pull Request Review Comments
#pull_request_review_comment:
# types: [created] #, edited, deleted]
# Pushes to any branch AND tags
#push:
# branches: ['**']
# tags: ['**']
# Releases
# Disabled — the release.yml workflow owns this notification and only fires
# it after the final deploy job succeeds, so the user sees one notification
# after everything is done rather than the moment the draft is unhidden.
#release:
# types: [published]
# Stars
#watch:
# types: [started]
# Forks
#fork:
# Discussions
discussion:
types: [created, answered] #, edited, deleted, pinned, unpinned, locked, unlocked, transferred, category_changed, answered, unanswered]
# Discussion Comments
#discussion_comment:
# types: [created] #, edited, deleted]
# Wiki
gollum:
# Milestones
milestone:
types: [closed] # [created, closed, opened, edited, deleted]
# Labels
#label:
# types: [created, edited, deleted]
# Branch/Tag creation and deletion
#create:
#delete:
# Deployment
# Both deployment and deployment_status are disabled — they fire multiple
# times per release (pending/in_progress/success per environment) and
# duplicate the `release: [published]` notification we already get.
#deployment:
#deployment_status:
# Pages
# page_build:
# Repository dispatch
# repository_dispatch:
# Public (when repo goes public)
public:
# Check runs
#check_run:
# types: [created, completed, rerequested, requested_action]
# Check suites
#check_suite:
# types: [completed, requested, rerequested]
# Branch protection rules
#branch_protection_rule:
# types: [created, edited, deleted]
# Registry packages
# Disabled — fires on every package publish/update and overlaps with the
# `release: [published]` notification during a release cycle.
#registry_package:
# types: [published, updated]
# Status (commit status)
# status:
# Restrict permissions to minimum needed
permissions: {}
jobs:
notify-matrix:
runs-on: ubuntu-latest
# Job-level env so the gate in the Matrix send step below can reliably
# read env.MATRIX_TOKEN in its `if:` expression.
env:
MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }}
steps:
- name: Determine activity type and format message
id: format
env:
# Set environment variables for all potentially problematic values
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_URL: ${{ github.event.issue.html_url }}
COMMENT_URL: ${{ github.event.comment.html_url }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_MERGED: ${{ github.event.pull_request.merged }}
REVIEW_URL: ${{ github.event.review.html_url }}
REF_NAME: ${{ github.ref_name }}
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COMPARE_URL: ${{ github.event.compare }}
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_URL: ${{ github.event.release.html_url }}
ACTOR_NAME: ${{ github.actor }}
FORKEE_OWNER: ${{ github.event.forkee.owner.login }}
FORKEE_URL: ${{ github.event.forkee.html_url }}
DISCUSSION_TITLE: ${{ github.event.discussion.title }}
DISCUSSION_URL: ${{ github.event.discussion.html_url }}
PAGES_MODIFIED: ${{ join(github.event.pages.*.page_name, ', ') }}
MILESTONE_TITLE: ${{ github.event.milestone.title }}
MILESTONE_URL: ${{ github.event.milestone.html_url }}
LABEL_NAME: ${{ github.event.label.name }}
REF_VALUE: ${{ github.event.ref }}
REF_TYPE: ${{ github.event.ref_type }}
DEPLOYMENT_ENV: ${{ github.event.deployment.environment }}
DEPLOYMENT_STATUS_STATE: ${{ github.event.deployment_status.state }}
DEPLOYMENT_STATUS_URL: ${{ github.event.deployment_status.target_url }}
CHECK_RUN_NAME: ${{ github.event.check_run.name }}
CHECK_RUN_URL: ${{ github.event.check_run.html_url }}
CHECK_SUITE_CONCLUSION: ${{ github.event.check_suite.conclusion }}
CHECK_SUITE_URL: ${{ github.event.check_suite.html_url }}
PACKAGE_NAME: ${{ github.event.package.name }}
PACKAGE_URL: ${{ github.event.package.html_url }}
STATUS_STATE: ${{ github.event.state }}
TARGET_URL: ${{ github.event.target_url }}
REPO_URL: ${{ github.event.repository.html_url }}
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
run: |
echo "Event: $EVENT_NAME"
echo "Action: $EVENT_ACTION"
# Set default values
ICON="📝"
TITLE="GitHub Activity"
DESCRIPTION=""
URL="$REPO_URL"
ACTOR="$ACTOR_NAME"
case "$EVENT_NAME" in
"issues")
ICON="🐛"
case "$EVENT_ACTION" in
"opened") TITLE="New Issue Opened" ;;
"closed") TITLE="Issue Closed" ;;
"reopened") TITLE="Issue Reopened" ;;
"edited") TITLE="Issue Edited" ;;
"assigned") TITLE="Issue Assigned" ;;
"labeled") TITLE="Issue Labeled" ;;
*) TITLE="Issue $EVENT_ACTION" ;;
esac
DESCRIPTION="$ISSUE_TITLE"
URL="$ISSUE_URL"
;;
"issue_comment")
ICON="💬"
TITLE="Issue Comment $EVENT_ACTION"
DESCRIPTION="On: $ISSUE_TITLE"
URL="$COMMENT_URL"
;;
"pull_request")
ICON="🔀"
case "$EVENT_ACTION" in
"opened") TITLE="New Pull Request" ;;
"closed")
if [[ "$PR_MERGED" == "true" ]]; then
TITLE="Pull Request Merged"
ICON="✅"
else
TITLE="Pull Request Closed"
fi
;;
"reopened") TITLE="Pull Request Reopened" ;;
"ready_for_review") TITLE="Pull Request Ready for Review" ;;
*) TITLE="Pull Request $EVENT_ACTION" ;;
esac
DESCRIPTION="$PR_TITLE"
URL="$PR_URL"
;;
"pull_request_review")
ICON="👀"
TITLE="Pull Request Review $EVENT_ACTION"
DESCRIPTION="On: $PR_TITLE"
URL="$REVIEW_URL"
;;
"pull_request_review_comment")
ICON="💭"
TITLE="PR Review Comment $EVENT_ACTION"
DESCRIPTION="On: $PR_TITLE"
URL="$COMMENT_URL"
;;
"push")
ICON="📤"
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
ICON="🏷️"
TITLE="Tag Pushed"
DESCRIPTION="Tag: $REF_NAME"
else
TITLE="Push to $REF_NAME"
DESCRIPTION="$HEAD_COMMIT_MESSAGE"
fi
URL="$COMPARE_URL"
;;
"release")
ICON="🚀"
TITLE="Release $EVENT_ACTION"
# Use release name if available, otherwise use tag name
if [[ -n "$RELEASE_NAME" ]]; then
DESCRIPTION="$RELEASE_NAME"
else
DESCRIPTION="$RELEASE_TAG"
fi
URL="$RELEASE_URL"
;;
"watch")
ICON="⭐"
TITLE="Repository Starred"
DESCRIPTION="New watcher: $ACTOR_NAME"
;;
"fork")
ICON="🍴"
TITLE="Repository Forked"
DESCRIPTION="By $FORKEE_OWNER"
URL="$FORKEE_URL"
;;
"discussion")
ICON="💬"
TITLE="Discussion $EVENT_ACTION"
DESCRIPTION="$DISCUSSION_TITLE"
URL="$DISCUSSION_URL"
;;
"discussion_comment")
ICON="💬"
TITLE="Discussion Comment $EVENT_ACTION"
DESCRIPTION="On: $DISCUSSION_TITLE"
URL="$COMMENT_URL"
;;
"gollum")
ICON="📖"
TITLE="Wiki Updated"
DESCRIPTION="Pages modified: $PAGES_MODIFIED"
;;
"milestone")
ICON="🎯"
TITLE="Milestone $EVENT_ACTION"
DESCRIPTION="$MILESTONE_TITLE"
URL="$MILESTONE_URL"
;;
"label")
ICON="🏷️"
TITLE="Label $EVENT_ACTION"
DESCRIPTION="$LABEL_NAME"
;;
"create")
ICON="🌱"
TITLE="$REF_TYPE Created"
DESCRIPTION="$REF_VALUE"
;;
"delete")
ICON="🗑️"
TITLE="$REF_TYPE Deleted"
DESCRIPTION="$REF_VALUE"
;;
"deployment")
ICON="🚀"
TITLE="Deployment"
DESCRIPTION="Environment: $DEPLOYMENT_ENV"
;;
"deployment_status")
ICON="🚀"
TITLE="Deployment Status"
DESCRIPTION="State: $DEPLOYMENT_STATUS_STATE"
URL="$DEPLOYMENT_STATUS_URL"
;;
"page_build")
ICON="📄"
TITLE="Page Build"
DESCRIPTION="GitHub Pages build"
;;
"repository_dispatch")
ICON="📡"
TITLE="Repository Dispatch"
DESCRIPTION="Event type: $EVENT_ACTION"
;;
"public")
ICON="🌍"
TITLE="Repository Made Public"
DESCRIPTION="Repository is now public"
;;
"check_run")
ICON="✅"
TITLE="Check Run $EVENT_ACTION"
DESCRIPTION="$CHECK_RUN_NAME"
URL="$CHECK_RUN_URL"
;;
"check_suite")
ICON="✅"
TITLE="Check Suite $EVENT_ACTION"
DESCRIPTION="Conclusion: $CHECK_SUITE_CONCLUSION"
URL="$CHECK_SUITE_URL"
;;
"branch_protection_rule")
ICON="🛡️"
TITLE="Branch Protection Rule $EVENT_ACTION"
DESCRIPTION="Rule updated"
;;
"registry_package")
ICON="📦"
TITLE="Package $EVENT_ACTION"
DESCRIPTION="$PACKAGE_NAME"
URL="$PACKAGE_URL"
;;
"status")
ICON="🔍"
TITLE="Status Update"
DESCRIPTION="State: $STATUS_STATE"
URL="$TARGET_URL"
;;
*)
TITLE="$EVENT_NAME $EVENT_ACTION"
;;
esac
# Output variables using proper escaping
{
echo "icon=$ICON"
echo "title=$TITLE"
echo "description=$DESCRIPTION"
echo "url=$URL"
echo "actor=$ACTOR"
} >> $GITHUB_OUTPUT
- name: Send Matrix notification
# Skip if MATRIX_TOKEN is not available (e.g. dependabot PRs) and
# don't fail the workflow when Matrix is unreachable (rate limit,
# outage, token rotation) — a missed notification should never turn
# the CI badge red.
if: env.MATRIX_TOKEN != ''
continue-on-error: true
uses: lkiesow/matrix-notification@v1
with:
server: matrix.org
token: ${{ secrets.MATRIX_TOKEN }}
room: '!azsMvrsrqEENIcSLOe:matrix.org'
message: |
${{ steps.format.outputs.icon }} ${{ steps.format.outputs.title }}
Actor: ${{ steps.format.outputs.actor }}
Repository: ${{ github.repository }}
${{ steps.format.outputs.description && format('Details: {0}', steps.format.outputs.description) || '' }}
Link: ${{ steps.format.outputs.url }}
formatted_message: |
${{ steps.format.outputs.icon }} <b>${{ steps.format.outputs.title }}</b><br><br>
<b>Actor:</b> ${{ steps.format.outputs.actor }}<br>
<b>Repository:</b> ${{ github.repository }}<br>
${{ steps.format.outputs.description && format('<b>Details:</b> {0}<br>', steps.format.outputs.description) || '' }}
<br><b>Link:</b> <a href="${{ steps.format.outputs.url }}">${{ steps.format.outputs.url }}</a>