]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Use templates to sender job status emails
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2017 17:55:37 +0000 (17:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2017 17:55:37 +0000 (17:55 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/constants.py.in
src/buildservice/jobs.py
src/buildservice/messages.py
src/templates/messages/jobs/failed.markdown [new file with mode: 0644]
src/templates/messages/jobs/finished.markdown [new file with mode: 0644]

index 075c805130c8431dbbf87f681da2241416774024..6a3f3f14316f21f9c0d884e78a0abe32a74931f4 100644 (file)
@@ -243,6 +243,12 @@ templates_errorsdir = $(templatesdir)/errors
 
 templates_messagesdir = $(templatesdir)/messages
 
+dist_templates_messages_jobs_DATA = \
+       src/templates/messages/jobs/failed.markdown \
+       src/templates/messages/jobs/finished.markdown
+
+templates_messages_jobsdir = $(templates_messagesdir)/jobs
+
 dist_templates_messages_users_DATA = \
        src/templates/messages/users/account-activation.markdown \
        src/templates/messages/users/email-activation.markdown
index d62a9c9d7f8cb93314ba769465671720825e0cd2..8e2a68949b1d1550755181288738a5e84d6282d5 100644 (file)
@@ -56,38 +56,6 @@ FILE_EXTENSIONS_VIEWABLE = (
        "Makefile",
 )
 
-N_ = lambda x: x
-
-MSG_BUILD_FAILED_SUBJECT = N_("[%(build_name)s] Build job failed.")
-MSG_BUILD_FAILED = N_("""\
-The build job "%(build_name)s" has failed.
-
-This could have a couple of reasons and needs to be investigated by you.
-
-Here is more information about the incident:
-
-    Build name: %(build_name)s
-    Build host: %(build_host)s
-
-Click on this link to get all details about the build:
-    https://pakfire.ipfire.org/job/%(build_uuid)s
-
-Sincerely,
-    The Pakfire Build Service""")
-
-
-MSG_BUILD_FINISHED_SUBJECT = N_("[%(build_name)s] Build job finished.")
-MSG_BUILD_FINISHED = N_("""\
-The build job "%(build_name)s" has finished.
-
-If you are the maintainer, it is up to you to push it to one or more repositories.
-
-Click on this link to get all details about the build:
-    https://pakfire.ipfire.org/job/%(build_uuid)s
-
-Sincerely,
-    The Pakfire Build Service""")
-
 # Bug update messages.
 BUG_TESTING_MSG = """\
 %(package_name)s has been pushed to the %(distro_name)s %(repo_name)s repository.
index e0b3af4c47146226307449c1da905289a409528f..a6b0be0f8f961e1e2d800853f7a8a2180cfa9d0c 100644 (file)
@@ -566,31 +566,15 @@ class Job(base.DataObject):
                logging.debug("Sending finished message for job %s to %s" % \
                        (self.name, ", ".join(self.message_recipients)))
 
-               info = {
-                       "build_name" : self.name,
-                       "build_host" : self.builder.name,
-                       "build_uuid" : self.uuid,
-               }
-
-               self.backend.messages.send_to_all(self.message_recipients,
-                       MSG_BUILD_FINISHED_SUBJECT, MSG_BUILD_FINISHED, info)
+               self.backend.messages.send_template_to_many(self.message_recipients,
+                       "messages/jobs/finished", job=self)
 
        def send_failed_message(self):
                logging.debug("Sending failed message for job %s to %s" % \
                        (self.name, ", ".join(self.message_recipients)))
 
-               build_host = "--"
-               if self.builder:
-                       build_host = self.builder.name
-
-               info = {
-                       "build_name" : self.name,
-                       "build_host" : build_host,
-                       "build_uuid" : self.uuid,
-               }
-
-               self.backend.messages.send_to_all(self.message_recipients,
-                       MSG_BUILD_FAILED_SUBJECT, MSG_BUILD_FAILED, info)
+               self.backend.messages.send_template_to_many(self.message_recipients,
+                       "messages/jobs/failed", job=self)
 
        def get_build_repos(self):
                """
index 14f63436d543b7859ff4a2f570ef8408f63b95cb..6a90fb87fd9681881f5f508436e40e2f310d1ece 100644 (file)
@@ -144,6 +144,10 @@ class Messages(base.Object):
                # Send the message
                self.send_to(user.email.recipient if user else recipient, message, sender=sender, headers=headers)
 
+       def send_template_to_many(self, recipients, *args, **kwargs):
+               for recipient in recipients:
+                       self.send_template(recipient, *args, **kwargs)
+
        def queue(self, message):
                res = self.db.get("INSERT INTO messages(message) VALUES(%s) RETURNING id", message)
 
diff --git a/src/templates/messages/jobs/failed.markdown b/src/templates/messages/jobs/failed.markdown
new file mode 100644 (file)
index 0000000..3094a5c
--- /dev/null
@@ -0,0 +1,15 @@
+Subject: [{{ job.name }}] {{ _("Build job failed") }}
+
+{{ _("The build job %s has failed") % job.name }}.
+{{ _("This could have a couple of reasons and needs to be investigated by you.") }}
+
+{{ _("Here is more information about the incident:") }}
+
+* {{ _("Name") }}: {{ job.name }}
+{% if job.builder %}* {{ _("Builder") }}: {{ job.builder }}{% end %}
+
+{{ _("Click on this link to get all details about the build:") }}
+  {{ baseurl }}/job/{{ job.uuid }}
+
+{{ _("Sincerely,") }}  
+-{{ _("The Pakfire Build Service") }}
\ No newline at end of file
diff --git a/src/templates/messages/jobs/finished.markdown b/src/templates/messages/jobs/finished.markdown
new file mode 100644 (file)
index 0000000..bb7cf37
--- /dev/null
@@ -0,0 +1,11 @@
+Subject: [{{ job.name }}] {{ _("Build job finished") }}
+
+{{ _("The build job %s has finished") % job.name }}.
+
+{{ _("If you are the maintainer, it is up to you to push it to one or more repositories.") }}
+
+{{ _("Click on this link to get all details about the build:") }}
+  {{ baseurl }}/job/{{ job.uuid }}
+
+{{ _("Sincerely,") }}  
+-{{ _("The Pakfire Build Service") }}
\ No newline at end of file