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$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7 (webhook-matrix-notifier)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
|
|
17
wmn.py
17
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"<strong>{username} pushed {commit_count} commits to {project_name}</strong><br>\n"
|
||||
"<ul>\n" + "\n".join((f"{commit['message']}" for commit in request.json["commits"])) + "</ul>\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" <li>{msg}</li>" for msg in commit_messages))
|
||||
text_commits = "\n".join((f"- {msg}" for msg in commit_messages))
|
||||
room.send_html(f"<strong>{username} pushed {len(commit_messages)} commits to {project_name}</strong><br>\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")
|
||||
|
||||
return ""
|
||||
|
|
Loading…
Reference in a new issue