PR#3009: listBuilds/list-builds filtering via CG

Merges #3009
https://pagure.io/koji/pull-request/3009

Fixes: #1401
https://pagure.io/koji/issue/1401
[RFE] add the ability to query builds by Content Generator
This commit is contained in:
Tomas Kopecek 2021-10-05 12:28:09 +02:00
commit 52ae5616dc
2 changed files with 12 additions and 1 deletions

View file

@ -3293,6 +3293,8 @@ def anon_handle_list_builds(goptions, session, args):
parser.add_option("--type", help=_("List builds of this type."))
parser.add_option("--prefix", help=_("Only builds starting with this prefix"))
parser.add_option("--pattern", help=_("Only list builds matching this GLOB pattern"))
parser.add_option("--cg",
help=_("Only list builds imported by matching content generator name"))
parser.add_option("--source", help=_("Only builds where the source field matches "
"(glob pattern)"))
parser.add_option("--owner", help=_("List builds built by this owner"))
@ -3313,6 +3315,8 @@ def anon_handle_list_builds(goptions, session, args):
value = getattr(options, key)
if value is not None:
opts[key] = value
if options.cg:
opts['cgID'] = options.cg
if options.package:
try:
opts['packageID'] = int(options.package)

View file

@ -11582,7 +11582,7 @@ class RootExports(object):
volumeID=None, source=None,
createdBefore=None, createdAfter=None,
completeBefore=None, completeAfter=None, type=None, typeInfo=None,
queryOpts=None, pattern=None):
queryOpts=None, pattern=None, cgID=None):
"""
Return a list of builds that match the given parameters
@ -11596,6 +11596,7 @@ class RootExports(object):
:param str prefix: only builds whose package name starts with that prefix
:param str pattern: only builds whose nvr matches the glob pattern
:param int state: only builds in the given state
:param int|str cgID: only build from given content generator
Timestamp filter parameters
- these limit the results to builds where the corresponding
@ -11725,6 +11726,12 @@ class RootExports(object):
if not isinstance(completeAfter, str):
completeAfter = datetime.datetime.fromtimestamp(completeAfter).isoformat(' ')
clauses.append('build.completion_time > %(completeAfter)s')
if cgID:
cgID = lookup_name('content_generator', cgID, strict=False)
if not cgID:
return []
cgID = cgID['id']
clauses.append('build.cg_id = %(cgID)s')
if type is None:
pass
elif type == 'maven':