From: Michael Tremer Date: Thu, 13 Oct 2022 15:46:50 +0000 (+0000) Subject: builds: Refactor sending emails when someone comments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72dae6ead8305caa456324e3598dd51cd9d67782;p=pbs.git builds: Refactor sending emails when someone comments Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index aa5f1517..183dd836 100644 --- a/Makefile.am +++ b/Makefile.am @@ -205,6 +205,11 @@ dist_templates_builds_DATA = \ templates_buildsdir = $(templatesdir)/builds +dist_templates_builds_messages_DATA = \ + src/templates/builds/messages/comment.txt + +templates_builds_messagesdir = $(templates_buildsdir)/messages + dist_templates_builds_modules_DATA = \ src/templates/builds/modules/list.html @@ -243,11 +248,6 @@ templates_jobs_messagesdir = $(templates_jobsdir)/messages templates_messagesdir = $(templatesdir)/messages -dist_templates_messages_builds_DATA = \ - src/templates/messages/builds/new-comment.markdown - -templates_messages_buildsdir = $(templates_messagesdir)/builds - dist_templates_messages_users_DATA = \ src/templates/messages/users/email-activation.markdown diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 5df2ec9c..34a60aaf 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -622,15 +622,6 @@ class Build(base.DataObject): """ pass # XXX TODO - @property - def message_recipients(self): - ret = [] - - for watcher in self.watchers: - ret.append("%s <%s>" % (watcher.realname, watcher.email)) - - return ret - @lazy_property def repo(self): res = self.db.get("SELECT repo_id FROM repositories_builds \ @@ -755,5 +746,6 @@ class Comment(base.DataObject): return self.data.score def notify(self): - self.backend.messages.send_template_to_many(self.build.message_recipients, "builds/new-comment", - sender=self.user.envelope_from, build=self.build, user=self.user, text=self.text) + for watcher in self.build.watchers: + watcher.send_email("builds/messages/comment.txt", + build=self.build, comment=self) diff --git a/src/templates/builds/messages/comment.txt b/src/templates/builds/messages/comment.txt new file mode 100644 index 00000000..2077027f --- /dev/null +++ b/src/templates/builds/messages/comment.txt @@ -0,0 +1,3 @@ +Subject: {{ _("%(user)s commented on %(build)s") % { "user" : comment.user, "build" : build }} + +{% for line in comment.text.splitlines() %} {{ line }}{% end %} diff --git a/src/templates/messages/builds/new-comment.markdown b/src/templates/messages/builds/new-comment.markdown deleted file mode 100644 index d3e95fc1..00000000 --- a/src/templates/messages/builds/new-comment.markdown +++ /dev/null @@ -1,3 +0,0 @@ -Subject: {{ _("%(user)s commented on %(build)s") % { "user" : user.realname, "build" : build }} - -{% for line in text.splitlines() %} {{ line }}{% end %}