From 2e40dbc1e4d9e2dceafe9e9ebf2c4fbe62426d7d Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 11 Aug 2021 00:39:17 +0200 Subject: [PATCH] Allow hiding of event details The optional configuration setting "hide_details" can be used for omitting event details in matrix messages triggered via webhooks. --- base-config.yaml | 1 + gitlab_matrix/util/config.py | 1 + gitlab_matrix/webhook.py | 1 + templates/messages/comment.html | 8 +++++--- templates/messages/issue_open.html | 11 +++++++---- templates/messages/merge_request.html | 8 +++++--- templates/messages/tag.html | 2 +- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/base-config.yaml b/base-config.yaml index 41dd666..4cad423 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -2,3 +2,4 @@ secret: "put a random password here" base_command: "gitlab" send_as_notice: true time_format: "%d.%m.%Y %H:%M:%S %Z" +hide_details: false diff --git a/gitlab_matrix/util/config.py b/gitlab_matrix/util/config.py index 72c2ca2..b8cdfd4 100644 --- a/gitlab_matrix/util/config.py +++ b/gitlab_matrix/util/config.py @@ -28,3 +28,4 @@ def do_update(self, helper: ConfigUpdateHelper) -> None: helper.copy("base_command") helper.copy("send_as_notice") helper.copy("time_format") + helper.copy("hide_details") diff --git a/gitlab_matrix/webhook.py b/gitlab_matrix/webhook.py index 3fbfd9b..c8d0a67 100644 --- a/gitlab_matrix/webhook.py +++ b/gitlab_matrix/webhook.py @@ -153,6 +153,7 @@ def abort() -> None: **OTHER_ENUMS, "abort": abort, "util": TemplateUtil, + "hide_details": True, } for subevt in evt.preprocess(): diff --git a/templates/messages/comment.html b/templates/messages/comment.html index be88092..5cdb205 100644 --- a/templates/messages/comment.html +++ b/templates/messages/comment.html @@ -14,7 +14,9 @@ {# unsupported comment target #} {% do abort() %} {% endif %} -
-{% if object_attributes.description %} -
{{ object_attributes.description|markdown }}
+{% if not hide_details %} +
+ {% if object_attributes.description %} +
{{ object_attributes.description|markdown }}
+ {% endif %} {% endif %} diff --git a/templates/messages/issue_open.html b/templates/messages/issue_open.html index fbebee3..ed89d24 100644 --- a/templates/messages/issue_open.html +++ b/templates/messages/issue_open.html @@ -1,6 +1,9 @@ {{ templates.repo_sender_prefix }} - opened {{ issue_link(object_attributes) }}
-{% if object_attributes.description %} -
{{ object_attributes.description|markdown }}
+ opened {{ issue_link(object_attributes) }} +{% if not hide_details %} +
+ {% if object_attributes.description %} +
{{ object_attributes.description|markdown }}
+ {% endif %} + {{ fancy_labels(object_attributes.labels) }} {% endif %} -{{ fancy_labels(object_attributes.labels) }} diff --git a/templates/messages/merge_request.html b/templates/messages/merge_request.html index 0b3dffc..1793e1a 100644 --- a/templates/messages/merge_request.html +++ b/templates/messages/merge_request.html @@ -1,10 +1,12 @@ {{ templates.repo_sender_prefix }} {% if action == OPEN %} opened {{ merge_request_link(object_attributes) }} - {% if object_attributes.description %} -
{{ object_attributes.description|markdown }}
+ {% if not hide_details %} + {% if object_attributes.description %} +
{{ object_attributes.description|markdown }}
+ {% endif %} + {{ fancy_labels(labels) }} {% endif %} - {{ fancy_labels(labels) }} {% else %} {{ object_attributes.action.past_tense }} {{ merge_request_link(object_attributes) }} diff --git a/templates/messages/tag.html b/templates/messages/tag.html index 8b3a8bb..4d002ed 100644 --- a/templates/messages/tag.html +++ b/templates/messages/tag.html @@ -6,7 +6,7 @@ created tag {{ ref_name }} {% endif %} -{%- if message -%}: +{%- if message and not hide_details -%}:
{{ message | markdown }}