Add gitlab formatter
Only for Google Chat and Microsoft Teams notification integrations
This commit is contained in:
parent
e91865f175
commit
f6bf150c7f
7 changed files with 153 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
"""Formatters for matrix webhook."""
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def grafana(data, headers):
|
||||
"""Pretty-print a grafana notification."""
|
||||
|
@ -30,3 +32,29 @@ def github(data, headers):
|
|||
data["body"] = "notification from github"
|
||||
data["digest"] = headers["X-Hub-Signature-256"].replace("sha256=", "")
|
||||
return data
|
||||
|
||||
|
||||
def gitlab_gchat(data, headers):
|
||||
"""Pretty-print a gitlab notification preformatted for Google Chat."""
|
||||
data["body"] = re.sub("<(.*?)\\|(.*?)>", "[\\2](\\1)", data["body"], re.MULTILINE)
|
||||
return data
|
||||
|
||||
|
||||
def gitlab_teams(data, headers):
|
||||
"""Pretty-print a gitlab notification preformatted for Microsoft Teams."""
|
||||
body = []
|
||||
for section in data["sections"]:
|
||||
if "text" in section.keys():
|
||||
text = section["text"].split("\n\n")
|
||||
text = ["* " + t for t in text]
|
||||
body.append("\n" + " \n".join(text))
|
||||
elif all(
|
||||
k in section.keys()
|
||||
for k in ("activityTitle", "activitySubtitle", "activityText")
|
||||
):
|
||||
text = section["activityTitle"] + " " + section["activitySubtitle"] + " → "
|
||||
text += section["activityText"]
|
||||
body.append(text)
|
||||
|
||||
data["body"] = " \n".join(body)
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue