From: Michael Tremer Date: Wed, 1 Nov 2017 17:55:37 +0000 (+0000) Subject: jobs: Use templates to sender job status emails X-Git-Url: http://git.ipfire.org/?p=pbs.git;a=commitdiff_plain;h=1f43964c69a4ea7382048df1b0ba7a7dba94bd0a jobs: Use templates to sender job status emails Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 075c805..6a3f3f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/buildservice/constants.py.in b/src/buildservice/constants.py.in index d62a9c9..8e2a689 100644 --- a/src/buildservice/constants.py.in +++ b/src/buildservice/constants.py.in @@ -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. diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index e0b3af4..a6b0be0 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -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): """ diff --git a/src/buildservice/messages.py b/src/buildservice/messages.py index 14f6343..6a90fb8 100644 --- a/src/buildservice/messages.py +++ b/src/buildservice/messages.py @@ -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 index 0000000..3094a5c --- /dev/null +++ b/src/templates/messages/jobs/failed.markdown @@ -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 index 0000000..bb7cf37 --- /dev/null +++ b/src/templates/messages/jobs/finished.markdown @@ -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