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
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)
"""
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):