GITLAB_WEBHOOK_TOKEN = os.environ.get("GITLAB_WEBHOOK_TOKEN", "secret")
PRESERVE_CONTEXT_ON_EXCEPTION = False
+
+SLACK_WEBHOOK_URL = os.environ.get("SLACK_WEBHOOK_URL", None)
from ui import config
from ui.gitlab import api
from ui.models import Build, Runner, db
+from ui.slack.webhook import post_build
def process(request):
if request.headers.get('X-Gitlab-Token', None) != config.GITLAB_WEBHOOK_TOKEN:
build.build_runner.runner_name = runner.get("description")
db.session.add(build)
db.session.commit()
+ if build.build_status in ['failed', 'canceled']:
+ post_build(build.build_status, build.build_device, build.build_version, build.build_type, build.build_id)
--- /dev/null
+import requests
+
+from ui import config
+
+
+def post_build(status, device, version, btype, id_):
+ if not config.SLACK_WEBHOOK_URL:
+ return
+ if status == "failed":
+ state = "has failed for"
+ elif status == "canceled":
+ state = "was canceled on"
+ else:
+ return
+ version = version.split("-")[1]
+ text = f"LineageOS {version} {state} {device} ({btype})"
+ data = {
+ "attachments": [
+ {
+ "fallback": text,
+ "author_name": "buildbot",
+ "title": text,
+ "text": f"https://gitlab.com/lineageos/builder/android/pipelines/{id_}",
+ "color": "danger" if status == "failed" else "#020202"
+ }
+ ]
+ }
+ requests.post(config.SLACK_WEBHOOK_URL, json=data)
+
+if __name__ == "__main__":
+ post_build('failed', 'mako', 'lineage-40.1', 'userdebug', 4)
+ post_build('canceled', 'mako', 'lineage-40.1', 'stable', 5)