Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run
25 lines
941 B
Python
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)
|