Skip to content

Commit 8d61cdc

Browse files
committed
Add reusable mattermost notify worfklow
1 parent 46ee07e commit 8d61cdc

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Mattermost Notification
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
preset:
7+
description: "Standard message type: 'review_request', 'review_decision', 'status', or 'custom'"
8+
required: false
9+
type: string
10+
default: "custom"
11+
job_status:
12+
description: "Required for 'status' preset. Pass ${{ needs.job_name.result }}"
13+
required: false
14+
type: string
15+
title:
16+
description: "Title override for status notifications (e.g. 'Docker Deploy')"
17+
required: false
18+
type: string
19+
message:
20+
description: "Custom text or additional notes"
21+
required: false
22+
type: string
23+
default: ""
24+
secrets:
25+
MM_WEBHOOK_URL:
26+
required: true
27+
28+
jobs:
29+
notify:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Determine Message
33+
id: msg
34+
shell: bash
35+
run: |
36+
PRESET="${{ inputs.preset }}"
37+
CUSTOM_MSG="${{ inputs.message }}"
38+
CUSTOM_TITLE="${{ inputs.title }}"
39+
TEXT=""
40+
41+
# --- PRESET LOGIC ---
42+
if [[ "$PRESET" == "review_request" ]]; then
43+
TEXT=":eyes: **Review Requested**
44+
**Repo:** ${{ github.repository }}
45+
**PR:** #${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}
46+
**Reviewer:** @${{ github.event.requested_reviewer.login }}
47+
[Review Now](${{ github.event.pull_request.html_url }})"
48+
49+
elif [[ "$PRESET" == "review_decision" ]]; then
50+
STATUS="${{ github.event.review.state }}"
51+
52+
# Determine Icon and Header based on the specific review state
53+
if [[ "$STATUS" == "approved" ]]; then
54+
ICON=":white_check_mark:"
55+
HEADER="PR Approved"
56+
elif [[ "$STATUS" == "changes_requested" ]]; then
57+
ICON=":arrows_counterclockwise:"
58+
HEADER="Changes Requested"
59+
else
60+
ICON=":speech_balloon:"
61+
HEADER="PR Comment"
62+
fi
63+
64+
TEXT="$ICON **$HEADER**
65+
**Repo:** ${{ github.repository }}
66+
**PR:** #${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}
67+
**Reviewer:** ${{ github.actor }}
68+
[Read Review](${{ github.event.review.html_url }})"
69+
70+
elif [[ "$PRESET" == "status" ]]; then
71+
RESULT="${{ inputs.job_status }}"
72+
73+
# Determine the Icon and the Status Word (Suffix)
74+
if [[ "$RESULT" == "success" ]]; then
75+
ICON=":white_check_mark:"
76+
STATUS_SUFFIX="Succeeded"
77+
else
78+
ICON=":x:"
79+
STATUS_SUFFIX="Failed"
80+
fi
81+
82+
# Determine the Name (Prefix)
83+
if [[ -n "$CUSTOM_TITLE" ]]; then
84+
PREFIX="$CUSTOM_TITLE"
85+
else
86+
PREFIX="Action"
87+
fi
88+
89+
# Determine the Header (e.g. "Docker Deploy" + "Succeeded")
90+
FINAL_HEADER="$PREFIX $STATUS_SUFFIX"
91+
92+
TEXT="$ICON **$FINAL_HEADER**
93+
**Repo:** ${{ github.repository }}
94+
**Ref:** ${{ github.ref_name }}
95+
**Author:** ${{ github.actor }}
96+
[View Logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
97+
fi
98+
99+
# --- COMBINE LOGIC ---
100+
# Add message if provided
101+
if [[ -n "$CUSTOM_MSG" ]]; then
102+
if [[ -n "$TEXT" ]]; then
103+
TEXT="$TEXT
104+
105+
---
106+
$CUSTOM_MSG"
107+
else
108+
TEXT="$CUSTOM_MSG"
109+
fi
110+
fi
111+
112+
echo "final_message<<EOF" >> $GITHUB_OUTPUT
113+
echo "$TEXT" >> $GITHUB_OUTPUT
114+
echo "EOF" >> $GITHUB_OUTPUT
115+
116+
- name: Send Alert
117+
uses: mattermost/action-mattermost-notify@master
118+
with:
119+
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
120+
MATTERMOST_ICON_URL: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
121+
TEXT: ${{ steps.msg.outputs.final_message }}

0 commit comments

Comments
 (0)