mirror of
https://github.com/bsedin/matrix-webhook.git
synced 2026-04-09 11:25:40 +00:00
formatters: add github
This commit is contained in:
@@ -13,3 +13,20 @@ def grafana(data, headers):
|
||||
text = text + "* " + match["metric"] + ": " + str(match["value"]) + "\n"
|
||||
data["body"] = text
|
||||
return data
|
||||
|
||||
|
||||
def github(data, headers):
|
||||
"""Pretty-print a github notification."""
|
||||
# TODO: Write nice useful formatters. This is only an example.
|
||||
if headers["X-GitHub-Event"] == "push":
|
||||
pusher, ref, a, b, c = [
|
||||
data[k] for k in ["pusher", "ref", "after", "before", "compare"]
|
||||
]
|
||||
pusher = f"[{pusher['name']}](https://github.com/{pusher['name']})"
|
||||
data["body"] = f"@{pusher} pushed on {ref}: [{b} → {a}]({c}):\n\n"
|
||||
for commit in data["commits"]:
|
||||
data["body"] += f"- [{commit['message']}]({commit['url']})\n"
|
||||
else:
|
||||
data["body"] = "notification from github"
|
||||
data["digest"] = headers["X-Hub-Signature-256"].replace("sha256=", "")
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user