8403a616b0d7d43ea503edebf42ec0ff2f9788a7
[GitLab/stricted-build/lineage_builder.git] / ui / slack / webhook.py
1 import requests
2
3 from ui import config
4
5
6 def post_build(status, device, version, btype, id_):
7 if not config.SLACK_WEBHOOK_URL:
8 return
9 if status == "failed":
10 state = "has failed for"
11 elif status == "canceled":
12 state = "was canceled on"
13 else:
14 return
15 version = version.split("-")[1]
16 text = f"LineageOS {version} {state} {device} ({btype})"
17 data = {
18 "channel": "#releases",
19 "attachments": [
20 {
21 "fallback": text,
22 "author_name": "buildbot",
23 "title": text,
24 "text": f"https://gitlab.com/lineageos/builder/android/pipelines/{id_}",
25 "color": "danger" if status == "failed" else "#020202"
26 }
27 ]
28 }
29 requests.post(config.SLACK_WEBHOOK_URL, json=data)
30
31 if __name__ == "__main__":
32 post_build('failed', 'mako', 'lineage-40.1', 'userdebug', 4)
33 post_build('canceled', 'mako', 'lineage-40.1', 'stable', 5)