diff --git a/.idea/webhook-matrix-notifier.iml b/.idea/webhook-matrix-notifier.iml
index 85c7612..446968a 100644
--- a/.idea/webhook-matrix-notifier.iml
+++ b/.idea/webhook-matrix-notifier.iml
@@ -4,7 +4,7 @@
-
+
diff --git a/wmn.py b/wmn.py
index 5daf2a3..2f43373 100644
--- a/wmn.py
+++ b/wmn.py
@@ -33,13 +33,20 @@ def notify():
room = client.join_room(room_id_or_alias=channel)
+ def sort_commits_by_time(commits):
+ return sorted(commits, key=lambda commit: commit["timestamp"])
+
+ def extract_commit_message(commit):
+ return next(commit["message"].splitlines(keepends=False), "$EMPTY_COMMIT_MESSAGE - impossibruh").strip()
+
username = request.json["user_name"]
- commit_count = len(request.json["commits"])
+ commit_messages = list(map(extract_commit_message, sort_commits_by_time(request.json["commits"])))
project_name = request.json["project"]["name"]
- room.send_html(f"{username} pushed {commit_count} commits to {project_name}
\n"
- "\n" + "\n".join((f"{commit['message']}" for commit in request.json["commits"])) + "
\n",
- body=f"{username} pushed {commit_count} commits to {project_name}\n"
- "" + "\n".join((f"- {commit['message']}" for commit in request.json["commits"])) + "\n",
+ html_commits = "\n".join((f" {msg}" for msg in commit_messages))
+ text_commits = "\n".join((f"- {msg}" for msg in commit_messages))
+ room.send_html(f"{username} pushed {len(commit_messages)} commits to {project_name}
\n"
+ f"\n",
+ body=f"{username} pushed {len(commit_messages)} commits to {project_name}\n{text_commits}\n",
msgtype="m.notice")
return ""