]> git.ipfire.org Git - pbs.git/commitdiff
builds: Send a push notification when a build is ready
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 22:59:25 +0000 (22:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 22:59:25 +0000 (22:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/builds.py
src/buildservice/i18n.py [new file with mode: 0644]

index 61500ec9908348e4f4bc3cc2c20ff15c2c2dd011..28d45da0413519668b8d4750b35c2ccca096fdd6 100644 (file)
@@ -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 \
index c55263d408e2562316cbb66c76ad2d645aa18ea4..e14e456e1381736ecedd453189cda86c9158731a 100644 (file)
@@ -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 (file)
index 0000000..3f769b4
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+# Don't translate anything, yet
+N_ = lambda x: x