Skip to content

Commit

Permalink
Support to move one staging into another
Browse files Browse the repository at this point in the history
osc staging select --move adi:26 adi:14

If move is given, all staging projects given after the first will
be seen as source

Fixes openSUSE#1105
  • Loading branch information
coolo committed Feb 15, 2022
1 parent bf7c5e1 commit 01e2495
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/staging.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ osc staging select --move B 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 --move B A C
--------------------------------------------------------------------------------

Unselect
~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion osc-staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 21 additions & 3 deletions osclib/request_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def find_request_project(self, source_project, newcand):

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
Expand All @@ -146,6 +146,8 @@ def find(self, pkgs, newcand):
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):
Expand All @@ -172,16 +174,32 @@ def find_via_stagingapi(self, pkgs):
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
Expand Down
2 changes: 1 addition & 1 deletion osclib/select_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def perform(self, requests, move=False,
# 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='')
Expand Down

0 comments on commit 01e2495

Please sign in to comment.