From 15d68bdc23b310f0f153aa0bd87cd3a99f985110 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jan 23 2020 15:16:18 +0000 Subject: add strict to getChangelogEntries If srpm doesn't exist and strict is specified, raise GenericError instead of returning empty list. Fixes: https://pagure.io/koji/issue/1147 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 6f205b8..58d63ee 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10474,7 +10474,8 @@ class RootExports(object): addArchiveType = staticmethod(add_archive_type) - def getChangelogEntries(self, buildID=None, taskID=None, filepath=None, author=None, before=None, after=None, queryOpts=None): + def getChangelogEntries(self, buildID=None, taskID=None, filepath=None, author=None, + before=None, after=None, queryOpts=None, strict=False): """Get changelog entries for the build with the given ID, or for the rpm generated by the given task at the given path @@ -10486,6 +10487,7 @@ class RootExports(object): (a datetime object, a string in the 'YYYY-MM-DD HH24:MI:SS format, or integer seconds since the epoch) - queryOpts: query options used by the QueryProcessor + - strict: if srpm doesn't exist raise an error, otherwise return empty list If "order" is not specified in queryOpts, results will be returned in reverse chronological order. @@ -10502,9 +10504,13 @@ class RootExports(object): if buildID: build_info = get_build(buildID) if not build_info: + if strict: + raise koji.GenericError("Build %s doesn't exist" % buildID) return _applyQueryOpts([], queryOpts) srpms = self.listRPMs(buildID=build_info['id'], arches='src') if not srpms: + if strict: + raise koji.GenericError("Build %s doesn't have srpms" % buildID) return _applyQueryOpts([], queryOpts) srpm_info = srpms[0] srpm_path = joinpath(koji.pathinfo.build(build_info), koji.pathinfo.rpm(srpm_info)) @@ -10520,7 +10526,10 @@ class RootExports(object): raise koji.GenericError('either buildID or taskID and filepath must be specified') if not os.path.exists(srpm_path): - return _applyQueryOpts([], queryOpts) + if strict: + raise koji.GenericError("SRPM %s doesn't exist" % srpm_path) + else: + return _applyQueryOpts([], queryOpts) if before: if isinstance(before, datetime.datetime):