Sort commits and output first-line commit messages
This commit is contained in:
parent
1b2fc7610c
commit
b5c97dd62c
|
@ -4,7 +4,7 @@
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="Python 3.7 (webhook-matrix-notifier)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TestRunnerService">
|
<component name="TestRunnerService">
|
||||||
|
|
17
wmn.py
17
wmn.py
|
@ -33,13 +33,20 @@ def notify():
|
||||||
|
|
||||||
room = client.join_room(room_id_or_alias=channel)
|
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"]
|
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"]
|
project_name = request.json["project"]["name"]
|
||||||
room.send_html(f"<strong>{username} pushed {commit_count} commits to {project_name}</strong><br>\n"
|
html_commits = "\n".join((f" <li>{msg}</li>" for msg in commit_messages))
|
||||||
"<ul>\n" + "\n".join((f"{commit['message']}" for commit in request.json["commits"])) + "</ul>\n",
|
text_commits = "\n".join((f"- {msg}" for msg in commit_messages))
|
||||||
body=f"{username} pushed {commit_count} commits to {project_name}\n"
|
room.send_html(f"<strong>{username} pushed {len(commit_messages)} commits to {project_name}</strong><br>\n"
|
||||||
"" + "\n".join((f"- {commit['message']}" for commit in request.json["commits"])) + "\n",
|
f"<ul>\n{html_commits}\n</ul>\n",
|
||||||
|
body=f"{username} pushed {len(commit_messages)} commits to {project_name}\n{text_commits}\n",
|
||||||
msgtype="m.notice")
|
msgtype="m.notice")
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue