Merge pull request #2696 from coolo/fix_1105

Support to move one staging into another
This commit is contained in:
Stephan Kulow 2022-02-15 15:37:42 +01:00 committed by GitHub
commit 34abdb2bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 6 deletions

View File

@ -159,12 +159,19 @@ selecting the request. If we want to move a request from one staging
project to another one, we need to use the parameter +--move+:
--------------------------------------------------------------------------------
osc staging select --move B 12345
osc staging select B --move 12345
--------------------------------------------------------------------------------
This command will move #12345 from openSUSE:Factory:Staging:A to
openSUSE:Factory:Staging:B
You can also merge staging projects by giving other staging projects as arguments:
--------------------------------------------------------------------------------
osc staging select B --move A C
--------------------------------------------------------------------------------
This moves all requests currently staged in A and C into B
Unselect
~~~~~~~~

View File

@ -449,7 +449,9 @@ def do_staging(self, subcmd, opts, *args):
# special staging with a capital letter which makes them unique.
# lastly adi stagings are consistently prefix with adi: which
# also makes it consistent to distinguish them from request IDs.
if arg in existing_stagings and arg not in stagings:
#
# also support --move passing 2 or more staging projects to merge
if arg in existing_stagings and arg not in stagings and (len(stagings) == 0 and opts.move):
stagings.append(api.extract_staging_short(arg))
elif arg not in requests:
requests.append(arg)

View File

@ -131,7 +131,7 @@ class RequestFinder(object):
return ret
def find(self, pkgs, newcand):
def find(self, pkgs, newcand, consider_stagings):
"""
Search for all various mutations and return list of SR#s
:param pkgs: mesh of argumets to search for
@ -146,6 +146,8 @@ class RequestFinder(object):
continue
if self.find_request_project(p, newcand):
continue
if consider_stagings and self.find_staging_project(p):
continue
raise oscerr.WrongArgs('No SR# found for: {}'.format(p))
def find_via_stagingapi(self, pkgs):
@ -172,16 +174,32 @@ class RequestFinder(object):
if not found:
raise oscerr.WrongArgs('No SR# found for: {}'.format(p))
def find_staging_project(self, project):
"""
Check if project is an existing staging project. If so, return
all requests staged in it
"""
project = self.api.prj_from_short(project)
url = self.api.makeurl(['staging', self.api.project, 'staging_projects', project], { 'requests': 1 })
try:
staging = ET.parse(self.api.retried_GET(url)).getroot()
except HTTPError:
return False
for request in staging.findall('staged_requests/request'):
self.srs[int(request.get('id'))] = {'staging': staging.get('name')}
return True
@classmethod
def find_sr(cls, pkgs, api, newcand=False):
def find_sr(cls, pkgs, api, newcand=False, consider_stagings=False):
"""
Search for all various mutations and return list of SR#s
:param pkgs: mesh of argumets to search for
:param api: StagingAPI instance
:param newcand: the review state of staging-group must be new
:param consider_stagings: consider names of staging projects
"""
finder = cls(api)
finder.find(pkgs, newcand)
finder.find(pkgs, newcand, consider_stagings)
return finder.srs
@classmethod

View File

@ -128,7 +128,7 @@ class SelectCommand(object):
# ie. the review state of staging-project must be new if newcand is True
newcand = not move
requests = RequestFinder.find_sr(requests, self.api, newcand)
requests = RequestFinder.find_sr(requests, self.api, newcand, consider_stagings=move)
requests_count = len(requests)
for index, request in enumerate(requests, start=1):
print('({}/{}) '.format(index, requests_count), end='')