OSVauco/gitea-chat-bridge/main.py
chris f467e5bea6
Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run
chore: update gitea-chat-bridge/main.py via opax-mcp
2026-07-25 07:44:47 +00:00

25 lines
941 B
Python

import functions_framework
import requests
import os
CHAT_WEBHOOK = os.environ.get("CHAT_WEBHOOK_URL")
@functions_framework.http
def handler(request):
try:
payload = request.get_json(silent=True) or {}
repo = payload.get("repository", {}).get("full_name", "unknown")
pusher = payload.get("pusher", {}).get("login", "unknown")
ref = payload.get("ref", "").replace("refs/heads/", "")
commits = payload.get("commits", [])
lines = [f"\U0001f500 *Push til {repo}* \u2014 branch {ref} av {pusher}"]
for c in commits[:5]:
sha = c.get("id","")[:7]
msg = c.get("message","").split("\n")[0][:80]
url = c.get("url","")
lines.append(f" \u2022 {sha}: {msg}\n {url}")
requests.post(CHAT_WEBHOOK, json={"text": "\n".join(lines)}, timeout=5)
return ("OK", 200)
except Exception as e:
return (str(e), 500)