From: Michael Tremer Date: Thu, 6 Feb 2025 22:59:25 +0000 (+0000) Subject: builds: Send a push notification when a build is ready X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18651eac6b8f76a582d9c0b1ab72a18708baccae;p=pbs.git builds: Send a push notification when a build is ready Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 61500ec9..28d45da0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,7 @@ pkgpython_PYTHON = \ src/buildservice/errors.py \ src/buildservice/events.py \ src/buildservice/httpclient.py \ + src/buildservice/i18n.py \ src/buildservice/images.py \ src/buildservice/jobs.py \ src/buildservice/keys.py \ diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index c55263d4..e14e456e 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -19,6 +19,7 @@ from . import packages from . import repos from . import users +from .i18n import N_ from .constants import * from .decorators import * @@ -712,9 +713,23 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Notify everyone this build has finished... if success: + # Send a push notification + await self._send_push_message( + title = N_("Build Successful"), + body = "%s" % self, + ) + + # Send an email await self._send_email("builds/messages/finished.txt") # ... or that it has failed else: + # Send a push notification + await self._send_push_message( + title = N_("Build Failed"), + body = "%s" % self, + ) + + # Send an email await self._send_email("builds/messages/failed.txt") # Create any test builds @@ -762,6 +777,20 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin): """ return self.has_finished() and self.failed is True + async def _send_push_message(self, *args, exclude=None, **kwargs): + """ + Convenience function which sends a push notification to everybody + """ + watchers = await self.get_watchers() + + for watcher in watchers: + # Skip some people + if exclude and watcher.user in exclude: + continue + + # Send a push notification + await watcher.user.send_push_message(*args, **kwargs) + async def _send_email(self, *args, exclude=None, **kwargs): """ Convenience function which sends an email to everybody who would care diff --git a/src/buildservice/i18n.py b/src/buildservice/i18n.py new file mode 100644 index 00000000..3f769b4e --- /dev/null +++ b/src/buildservice/i18n.py @@ -0,0 +1,22 @@ +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2025 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +# Don't translate anything, yet +N_ = lambda x: x