-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.py
78 lines (72 loc) · 2.53 KB
/
entrypoint.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
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
import sys
import json
from slack_sdk.webhook import WebhookClient
from slack_sdk.errors import SlackApiError
url = sys.argv[4]
webhook = WebhookClient(url)
def message_builder(outcome, project, build, repo, version, notes):
color = "#000000"
success_color = "#4BB543"
failure_color = "#FF0000"
if outcome == "success":
color = success_color
if outcome == "failure":
color = failure_color
org = repo.split("/")[0]
service = repo.split("/")[1]
if version == "none":
service_info = service
else:
service_info = f"{service} `{version}`"
message = [
{
"color": color,
"blocks": [
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Service: {service_info}"},
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"{notes} "},
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Outcome: {outcome.capitalize()}"},
},
{"type": "divider"},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {"type": "plain_text", "text": f"Project: {project}"},
"value": f"https://console.cloud.google.com/home/dashboard?project={project}",
"url": f"https://console.cloud.google.com/home/dashboard?project={project}",
},
{
"type": "button",
"text": {"type": "plain_text", "text": f"Build #{build}"},
"value": f"https://github.com/{org}/{service}/actions/runs/{build}",
"url": f"https://github.com/{org}/{service}/actions/runs/{build}",
},
],
},
],
}
]
return message
if __name__ == "__main__":
outcome = sys.argv[1]
project = sys.argv[2]
build = sys.argv[3]
repo = sys.argv[5]
version = sys.argv[6]
notes = sys.argv[7]
try:
formatted_message = message_builder(outcome, project, build, repo, version, notes)
response = webhook.send(
attachments=formatted_message
)
except SlackApiError as e:
assert e.response["error"]