]> git.ipfire.org Git - pbs.git/commitdiff
release monitoring: Implement following the current branch
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jun 2023 15:31:51 +0000 (15:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jun 2023 15:45:29 +0000 (15:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/distribution.py
src/buildservice/releasemonitoring.py
src/templates/monitorings/edit.html

index e98c7c7191dbcd1bea467b6a99a63583308eabcd..2b0063468edb0c5389b24b6be4284c8457c7482c 100644 (file)
@@ -318,27 +318,23 @@ class Distribution(base.DataObject):
 
        def get_builds_by_name(self, name, limit=None):
                """
-                       Returns all builds that match the name
+                       Returns all release builds that match the name
                """
                builds = self.backend.builds._get_builds("""
                        SELECT
                                builds.*
                        FROM
-                               repositories
-                       LEFT JOIN
-                               repository_builds ON repositories.id = repository_builds.repo_id
-                       LEFT JOIN
-                               builds ON repository_builds.build_id = builds.id
+                               builds
                        LEFT JOIN
                                packages ON builds.pkg_id = packages.id
                        WHERE
-                               repositories.deleted_at IS NULL
+                               builds.deleted_at IS NULL
                        AND
-                               repositories.distro_id = %s
+                               builds.owner_id IS NULL
                        AND
-                               repository_builds.removed_at IS NULL
+                               packages.deleted_at IS NULL
                        AND
-                               builds.deleted_at IS NULL
+                               packages.distro_id = %s
                        AND
                                packages.name = %s
                        ORDER BY
index 854d90d15bdc5daf98b0161a3d980f98a0cabfc0..c152d6b4bc8580b297ebce267a8d56ee56d44d45 100644 (file)
@@ -325,6 +325,8 @@ class Monitoring(base.DataObject):
                                                release = await self._follow_latest(versions)
                                        elif self.follow == "stable":
                                                release = await self._follow_stable(versions)
+                                       elif self.follow == "current-branch":
+                                               release = await self._follow_current_branch(versions)
                                        else:
                                                raise ValueError("Cannot handle follow: %s" % self.follow)
 
@@ -366,6 +368,68 @@ class Monitoring(base.DataObject):
                """
                return await self.create_release(versions.latest_version)
 
+       async def _follow_current_branch(self, versions):
+               """
+                       This will follow any minor releases in the same branch
+               """
+               # We cannot perform this if there is no recent build
+               if not self.latest_build:
+                       return
+
+               # Find the next version
+               next_version = self._find_next_version(
+                       self.latest_build.pkg.evr, versions.stable_versions)
+
+               # Create a new release with the next version
+               if next_version:
+                       return await self.create_release(next_version)
+
+       def _find_next_version(self, current_version, available_versions):
+               # Remove epoch
+               if ":" in current_version:
+                       epoch, delim, current_version = current_version.partition(":")
+
+               # Remove release
+               current_version, delim, release = current_version.rpartition("-")
+
+               # Split the current version into parts
+               current_version_parts = self._split_version(current_version)
+
+               versions = {}
+
+               # Find all versions that are interesting for us and store them with
+               # how many parts are matching against the current version
+               with self.backend.pakfire() as p:
+                       for version in available_versions:
+                               # Only consider later versions
+                               if p.version_compare(current_version, version) >= 0:
+                                       continue
+
+                               # Split the version into parts
+                               parts = self._split_version(version)
+
+                               # Count the number of parts that match at the beginning
+                               for i, (a, b) in enumerate(zip(current_version_parts, parts)):
+                                       if not a == b:
+                                               break
+
+                                       # Store the number of matching parts
+                                       versions[version] = i + 1
+
+               # Fetch all versions with the highest number of matches
+               versions = [v for v in versions if versions[v] == max(versions.values())]
+
+               # Return the latest version
+               for version in versions:
+                       return version
+
+       @staticmethod
+       def _split_version(version):
+               """
+                       Splits a version into its parts by any punctuation characters
+               """
+               return re.split(r"[\.\-_]", version)
+
        # Releases
 
        def _get_releases(self, query, *args, **kwargs):
index a207285a9c7ff230ef1f27e86b92ef62d35026f9..9690144b3514357c443f6a05d8558b5bdbff4c4a 100644 (file)
@@ -73,8 +73,9 @@
                        </div>
 
                        {% set follows = {
-                               "stable" : _("Stable - Follow all stable releases"),
-                               "latest" : _("Latest - Follow the latest releases (including pre-releases)"),
+                               "stable"         : _("Stable - Follow all stable releases"),
+                               "latest"         : _("Latest - Follow the latest releases (including pre-releases)"),
+                               "current-branch" : _("Current Branch - Follows minor releases only"),
                        } %}
 
                        {# Follow #}