]> git.ipfire.org Git - pbs.git/commitdiff
builds: Refactor sending emails when someone comments
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Oct 2022 15:46:50 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Oct 2022 15:53:46 +0000 (15:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/builds.py
src/templates/builds/messages/comment.txt [new file with mode: 0644]
src/templates/messages/builds/new-comment.markdown [deleted file]

index aa5f151786a1b626414cc77bed4f0648aaa3e793..183dd8365a8f994bdb89f97dfa923b23722735e1 100644 (file)
@@ -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
 
index 5df2ec9cefdf7fd5b023125e73b245f3d346af71..34a60aaf4f4517192c631869cb14584b097db05c 100644 (file)
@@ -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 (file)
index 0000000..2077027
--- /dev/null
@@ -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 (file)
index d3e95fc..0000000
+++ /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 %}