Fix empty changes error for Jenkins

and update project files.
This commit is contained in:
Ben 2020-05-16 17:53:57 +02:00
parent fffe8c25b6
commit 419ec79227
4 changed files with 21 additions and 8 deletions

View file

@ -4,10 +4,11 @@
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="ERROR" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="3">
<list size="4">
<item index="0" class="java.lang.String" itemvalue="3.6" />
<item index="1" class="java.lang.String" itemvalue="3.7" />
<item index="2" class="java.lang.String" itemvalue="3.8" />
<item index="3" class="java.lang.String" itemvalue="3.9" />
</list>
</value>
</option>

View file

@ -4,4 +4,7 @@
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (webhook-matrix-notifier)" project-jdk-type="Python SDK" />
<component name="PythonCompatibilityInspectionAdvertiser">
<option name="version" value="3" />
</component>
</project>

View file

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (webhook-matrix-notifier)" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

21
wmn.py
View file

@ -150,22 +150,31 @@ def process_jenkins_request():
f" <li>{shorten(change_message)} {commit_link} by {change['author']} at {htimestamp}</li>",
)
else:
return shorten(json.dumps(change).replace("<", "&"), appendix="...}")
dump = shorten(json.dumps(change), appendix="...}")
return (
dump,
dump.replace("<", "&lt;").replace(">", "&gt;")
)
build_name = request.json["displayName"]
project_name = request.json["project"]["fullDisplayName"]
result_type = request.json["result"]["type"]
result_color = request.json["result"]["color"]
text_change_messages, html_change_messages = zip(*map(extract_change_message, request.json['changes']))
changes = request.json['changes']
if len(changes) > 0:
text_change_messages, html_change_messages = zip(*map(extract_change_message, changes))
else:
text_change_messages, html_change_messages = (), () # it's an owl!
newline = '\n'
try:
room.send_html(f"<p><strong>Build {build_name} on project {project_name} complete: "
f"<font color=\"{result_color}\">{result_type}</font></strong>, "
f"{len(request.json['changes'])} commits</p>\n"
"" + (f"<ul>\n{newline.join(html_change_messages)}\n</ul>\n" if len(request.json['changes']) > 0 else ""),
f"{len(changes)} commits</p>\n"
"" + (f"<ul>\n{newline.join(html_change_messages)}\n</ul>\n" if len(html_change_messages) > 0 else ""),
body=f"**Build {build_name} on project {project_name} complete: {result_type}**, "
f"{len(request.json['changes'])} commits\n"
"" + (f"{newline.join(text_change_messages)}\n" if len(request.json['changes']) > 0 else ""),
f"{len(changes)} commits\n"
"" + (f"{newline.join(text_change_messages)}\n" if len(text_change_messages) > 0 else ""),
msgtype=msgtype)
except MatrixRequestError as e:
return matrix_error(e)