From 5692ec1cc62734fedcb479a34491478a5f604a80 Mon Sep 17 00:00:00 2001 From: Max Lin Date: Mon, 18 Jul 2016 17:43:02 +0800 Subject: [PATCH] Use newcand param make sure don't select the processed requests --- osclib/request_finder.py | 18 +++++++++++++----- osclib/select_command.py | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/osclib/request_finder.py b/osclib/request_finder.py index 3b3bbfac..1695fc4e 100644 --- a/osclib/request_finder.py +++ b/osclib/request_finder.py @@ -93,10 +93,11 @@ class RequestFinder(object): request = int(requests[0]) if requests else None return request - def find_request_project(self, source_project): + def find_request_project(self, source_project, newcand): """ Look up the source project by its name and return the SR#(s) :param source_project: name of the source project + :param newcand: the review state of staging-group must be new """ query = 'states=new,review&project={}&view=collection'.format(self.api.project) @@ -106,6 +107,11 @@ class RequestFinder(object): ret = None for sr in root.findall('request'): + # ensure staging tool don't picks the processed request again + if newcand: + staging_group_states = [review.get('state') for review in root.findall('review') if review.get('by_group') == self.cstaging_group] + if 'new' not in staging_group_states: + continue for act in sr.findall('action'): src = act.find('source') if src is not None and src.get('project') == source_project: @@ -116,10 +122,11 @@ class RequestFinder(object): return ret - def find(self, pkgs): + def find(self, pkgs, newcand): """ Search for all various mutations and return list of SR#s :param pkgs: mesh of argumets to search for + :param newcand: the review state of staging-group must be new This function is only called for its side effect. """ @@ -128,7 +135,7 @@ class RequestFinder(object): continue if self.find_request_id(p): continue - if self.find_request_project(p): + if self.find_request_project(p, newcand): continue raise oscerr.WrongArgs('No SR# found for: {}'.format(p)) @@ -159,14 +166,15 @@ class RequestFinder(object): raise oscerr.WrongArgs('No SR# found for: {}'.format(p)) @classmethod - def find_sr(cls, pkgs, api): + def find_sr(cls, pkgs, api, newcand=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 """ finder = cls(api) - finder.find(pkgs) + finder.find(pkgs, newcand) return finder.srs @classmethod diff --git a/osclib/select_command.py b/osclib/select_command.py index 2f79ce7c..2bee7e9a 100644 --- a/osclib/select_command.py +++ b/osclib/select_command.py @@ -125,7 +125,11 @@ class SelectCommand(object): return False # FreezeCommand(self.api).perform(self.target_project) - for request in RequestFinder.find_sr(requests, self.api): + # picks new candidate requests only if it's not to move requests + # ie. the review state of staging-project must be new if newcand is True + newcand = not move + + for request in RequestFinder.find_sr(requests, self.api, newcand): if not self.select_request(request, move, from_): return False