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
This commit is contained in:
Tomas Kopecek 2020-01-16 14:27:30 +01:00
parent 5efa4a66a7
commit 512e43cbce

View file

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