From 07abc2bf12d473fcc96e02c6c69b566025b543bb Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Wed, 29 Apr 2020 02:59:27 +0200 Subject: [PATCH] Respect the GitHub project URL and link commits --- wmn.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/wmn.py b/wmn.py index 396c01c..3e026c6 100644 --- a/wmn.py +++ b/wmn.py @@ -134,32 +134,36 @@ def process_jenkins_request(): except MatrixRequestError as e: return matrix_error(e) + project_url = request.json["githubProjectUrl"] + def extract_change_message(change): change_message = next(iter_first_line(change["message"]), "") if len(change_message) > 0: htimestamp = datetime.fromtimestamp(change['timestamp'] / 1000).strftime("%d. %b %y %H:%M") - return f"{shorten(change_message)} " \ - f"({shorten(change['commitId'], 7, appendix='')}) " \ - f"by {change['author']} " \ - f"at {htimestamp}" + bare_commit_link = f"({shorten(change['commitId'], 7, appendix='')})" + if project_url is not None and project_url: + commit_link = f"{bare_commit_link}" + else: + commit_link = bare_commit_link + return (f"
  • {shorten(change_message)} {commit_link} by {change['author']} at {htimestamp}
  • ", + f"- {shorten(change_message)} {bare_commit_link} by {change['author']} at {htimestamp}") else: - return shorten(json.dumps(change), appendix="...}") + return shorten(json.dumps(change).replace("<", "&"), appendix="...}") build_name = request.json["displayName"] project_name = request.json["project"]["fullDisplayName"] result_type = request.json["result"]["type"] result_color = request.json["result"]["color"] - change_messages = list(map(extract_change_message, request.json["changes"])) - html_changes = "\n".join((f"
  • {msg}
  • " for msg in change_messages)) - text_changes = "\n".join((f"- {msg}" for msg in change_messages)) + html_change_messages, text_change_messages = map(extract_change_message, request.json['changes']) + newline = '\n' try: room.send_html(f"

    Build {build_name} on project {project_name} complete: " f"{result_type}, " - f"{len(change_messages)} commits

    \n" - "" + (f"\n" if len(change_messages) > 0 else ""), + f"{len(request.json['changes'])} commits

    \n" + "" + (f"\n" if len(request.json['changes']) > 0 else ""), body=f"**Build {build_name} on project {project_name} complete: {result_type}**, " - f"{len(change_messages)} commits\n" - "" + (f"{text_changes}\n" if len(change_messages) > 0 else ""), + f"{len(request.json['changes'])} commits\n" + "" + (f"{newline.join(text_change_messages)}\n" if len(request.json['changes']) > 0 else ""), msgtype=msgtype) except MatrixRequestError as e: return matrix_error(e)