Skip to content

Commit

Permalink
osclib/list_command.py: Allow overriding reviews filter from the comm…
Browse files Browse the repository at this point in the history
…and line.

This patch implements overriding of the filter on reviews set up by the
staging plugin. It is now possible to filter requests that have been
reviewed by more than one group, for example; or to filter requests that
have lack a request by a specific group or bot.
  • Loading branch information
gleidi-suse committed Nov 7, 2024
1 parent 88108f7 commit e9905c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 8 additions & 2 deletions osc-staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def clean_args(args):
@cmdln.option('--merge', action='store_true', help='propose merge where applicable and store details to allow future merges')
@cmdln.option('--try-strategies', action='store_true', default=False, help='apply strategies and keep any with desireable outcome')
@cmdln.option('--strategy', help='apply a specific strategy')
@cmdln.option('--review-filter', help='xpath by which to filter requests on the basis of the reviews they received', default=None)
@cmdln.option('--no-color', action='store_true', help='strip colors from output (or add staging.color = 0 to the .oscrc general section')
@cmdln.option('--remove-exclusion', action='store_true', help='unignore selected requests automatically', default=False)
@cmdln.option('--save', action='store_true', help='save the result to the pseudometa package')
Expand Down Expand Up @@ -157,6 +158,11 @@ def do_staging(self, subcmd, opts, *args):
changed from state new or review more than 3 days ago will be removed.
"list" will list/supersede requests for ring packages or all if no rings.
As an example, the following would list all packages which have received a
positive review from a member of the licensedigger group or the factory-auto
one
list --review-filter "review[(@by_group='factory-auto' or @by_group='licensedigger') and @state='accepted']"
"lock" acquire a hold on the project in order to execute multiple commands
and prevent others from interrupting. An example:
Expand Down Expand Up @@ -309,7 +315,7 @@ def do_staging(self, subcmd, opts, *args):
osc staging frozenage [STAGING...]
osc staging ignore [-m MESSAGE] REQUEST...
osc staging unignore [--cleanup] [REQUEST...|all]
osc staging list [--supersede] [--adi-details]
osc staging list [--adi-details] [--review-filter] [--supersede]
osc staging lock [-m MESSAGE]
osc staging select [--no-freeze] [--remove-exclusion] [--move [--filter-from STAGING]]
STAGING REQUEST...
Expand Down Expand Up @@ -580,7 +586,7 @@ def do_staging(self, subcmd, opts, *args):
elif cmd == 'unignore':
UnignoreCommand(api).perform(args[1:], opts.cleanup)
elif cmd == 'list':
ListCommand(api).perform(supersede=opts.supersede, adi_details=opts.adi_details)
ListCommand(api).perform(adi_details=opts.adi_details, review_filter=opts.review_filter, supersede=opts.supersede)
elif cmd == 'lock':
lock.hold(opts.message)
elif cmd == 'adi':
Expand Down
4 changes: 2 additions & 2 deletions osclib/list_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def print_request(self, request):

print(' ', line)

def perform(self, supersede=False, adi_details=False):
def perform(self, adi_details=False, review_filter=None, supersede=False):
"""
Perform the list command
"""

if supersede:
SupersedeCommand(self.api).perform()

requests = self.api.get_open_requests()
requests = self.api.get_open_requests(review_filter=review_filter)
if not len(requests):
return

Expand Down
10 changes: 7 additions & 3 deletions osclib/stagingapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def del_ignored_request(self, request_id):
http_DELETE(url, data=ET.tostring(root))

@memoize(session=True, add_invalidate=True)
def get_open_requests(self, query_extra=None):
def get_open_requests(self, review_filter=None, query_extra=None):
"""
Get all requests with open review for staging project
that are not yet included in any staging project
Expand All @@ -587,10 +587,14 @@ def get_open_requests(self, query_extra=None):
requests = []

# xpath query, using the -m, -r, -s options
where = f"@by_group='{self.cstaging_group}' and @state='new'"
if review_filter:
review_where = review_filter
else:
review_where = f"review[@by_group='{self.cstaging_group}' and @state='new']"

target = f"target[@project='{self.project}']"

query = {'match': f"state/@name='review' and review[{where}] and {target}"}
query = {'match': f"state/@name='review' and {review_where} and {target}"}
if query_extra is not None:
query.update(query_extra)
url = self.makeurl(['search', 'request'], query)
Expand Down

0 comments on commit e9905c6

Please sign in to comment.