From 7fd23d0e32bf2ff5fc15babe9a1262d90c1f2a4f Mon Sep 17 00:00:00 2001 From: Olivier van der Toorn Date: Fri, 6 Oct 2023 15:19:57 +0200 Subject: [PATCH] Add support for reviewer changes in merge requests The merge request event webhook is called for reviwers updates, however this is ignored by the GitlabChanges class. Therefore these updates are not forwarded to Matrix. By adding the reviewers section to both the GitlabChanges and to the issue_update template (which is used for merge request updates) the bot reports about changes in reviewers. --- gitlab_matrix/types.py | 7 +++++++ templates/macros.html | 3 +++ templates/messages/issue_update.html | 3 +++ 3 files changed, 13 insertions(+) diff --git a/gitlab_matrix/types.py b/gitlab_matrix/types.py index f48174f..ab1301e 100644 --- a/gitlab_matrix/types.py +++ b/gitlab_matrix/types.py @@ -252,6 +252,12 @@ class GitlabAssigneeChanges(GitlabChangeWrapper, SerializableAttrs): current: List[GitlabUser] +@dataclass +class GitlabReviewersChanges(GitlabChangeWrapper, SerializableAttrs): + previous: List[GitlabUser] + current: List[GitlabUser] + + @dataclass class GitlabLabelChanges(GitlabChangeWrapper, SerializableAttrs): previous: List[GitlabLabel] @@ -290,6 +296,7 @@ class GitlabChanges(SerializableAttrs): title: Optional[GitlabStringChange] = None labels: Optional[GitlabLabelChanges] = None assignees: Optional[GitlabAssigneeChanges] = None + reviewers: Optional[GitlabReviewersChanges] = None time_estimate: Optional[GitlabIntChange] = None total_time_spent: Optional[GitlabIntChange] = None weight: Optional[GitlabIntChange] = None diff --git a/templates/macros.html b/templates/macros.html index 234f7c0..ef8ba75 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -73,3 +73,6 @@ {%- macro assignee_changes(added, removed) -%} {{ list_changes(added, removed, "assigned", "unassigned", user_link) }} {%- endmacro -%} +{%- macro reviewers_changes(added, removed) -%} + {{ list_changes(added, removed, "assigned", "unassigned", user_link) }} +{%- endmacro -%} diff --git a/templates/messages/issue_update.html b/templates/messages/issue_update.html index 5377fbe..aba0539 100644 --- a/templates/messages/issue_update.html +++ b/templates/messages/issue_update.html @@ -12,6 +12,9 @@ {% elif changes.assignees %} {{ assignee_changes(changes.assignees.added, changes.assignees.removed) }} {{ issue_or_merge_link(object_attributes) }} +{% elif changes.reviewers %} + {{ reviewers_changes(changes.reviewers.added, changes.reviewers.removed) }} + {{ issue_or_merge_link(object_attributes) }} {% elif changes.time_estimate %} {% if not changes.time_estimate.current %} removed the time estimate of {{ issue_or_merge_link(object_attributes) }}