forked from singnet/integration-github-mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 1.08 KB
/
main.py
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
import os
import sys
from mattermost import is_empty, log_error, read_message, send
def main():
msg = {}
mattermost_msg = os.getenv("MATTERMOST_MESSAGE")
if mattermost_msg:
msg["text"] = mattermost_msg
else:
msg = read_message("mattermost.json")
webhook = os.getenv("MATTERMOST_WEBHOOK_URL")
if not webhook:
log_error("Missing MATTERMOST_WEBHOOK_URL environment variable")
channel_name = os.getenv("MATTERMOST_CHANNEL", msg.get("ChannelName", ""))
if channel_name is not None:
msg["ChannelName"] = channel_name
username = os.getenv("MATTERMOST_USERNAME", msg.get("Username", ""))
if username is not None:
msg["Username"] = username
icon_url = os.getenv("MATTERMOST_ICON", msg.get("IconURL", ""))
if icon_url is not None:
msg["IconURL"] = icon_url
if is_empty(msg):
print(
"mattermost.json and MATTERMOST_MESSAGE is empty, exiting without failing."
)
sys.exit(0)
send(webhook, msg)
print("Mattermost message sent!")
if __name__ == "__main__":
main()