From 2cd2acf67c91446ade73e0c2527e28f6e6cf66de Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 21 Jul 2019 15:26:30 +0200 Subject: [PATCH] Format timestamp and switch to m.text message type for Jenkins requests, because matterbridge doesn't forward m.notice. --- wmn.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wmn.py b/wmn.py index a2f8265..1d8f95e 100644 --- a/wmn.py +++ b/wmn.py @@ -1,5 +1,6 @@ import json import re +from datetime import datetime import yaml from flask import Flask, request, abort @@ -95,6 +96,9 @@ def process_gitlab_request(): def process_jenkins_request(): + # TODO: make switching message types possible + # msgtype = "m.notice" + msgtype = "m.text" check_token('X-Jenkins-Token') room = get_a_room() jenkins_event = request.headers.get("X-Jenkins-Event") @@ -111,10 +115,11 @@ def process_jenkins_request(): 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 {change['timestamp']}" + f"at {htimestamp}" else: return shorten(json.dumps(change), appendix="...}") @@ -133,7 +138,7 @@ def process_jenkins_request(): 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 ""), - msgtype="m.notice") + msgtype=msgtype) except MatrixRequestError as e: return matrix_error(e)