From 5927b2b283ce60fd4b5d47c9624c98bcf670f37f Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 17 Mar 2017 14:41:11 -0500 Subject: [PATCH 1/6] unignore: utilize RequestFinder. --- osclib/unignore_command.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osclib/unignore_command.py b/osclib/unignore_command.py index 89bdd087..fd32ee27 100644 --- a/osclib/unignore_command.py +++ b/osclib/unignore_command.py @@ -2,13 +2,14 @@ import dateutil.parser from datetime import datetime from osc.core import get_request +from osclib.request_finder import RequestFinder class UnignoreCommand(object): def __init__(self, api): self.api = api - def perform(self, request_ids, cleanup=False): + def perform(self, requests, cleanup=False): """ Unignore a request by removing from ignore list. """ @@ -16,11 +17,10 @@ class UnignoreCommand(object): requests_ignored = self.api.get_ignored_requests() length = len(requests_ignored) - if len(request_ids) == 1 and request_ids[0] == 'all': + if len(requests) == 1 and requests[0] == 'all': requests_ignored = {} else: - for request_id in request_ids: - request_id = int(request_id) + for request_id in RequestFinder.find_sr(requests, self.api): if request_id in requests_ignored: print('Removing {}'.format(request_id)) del requests_ignored[request_id] From 89c75ab227bbc0b58633b2dec869ef3b31993759 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 17 Mar 2017 14:41:43 -0500 Subject: [PATCH 2/6] unignore: add comment when a request is unignored. Without a comment the only indication of when a request was unignored is in the revision history of ignored_requests file. --- osclib/unignore_command.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osclib/unignore_command.py b/osclib/unignore_command.py index fd32ee27..654e1325 100644 --- a/osclib/unignore_command.py +++ b/osclib/unignore_command.py @@ -2,12 +2,16 @@ import dateutil.parser from datetime import datetime from osc.core import get_request +from osclib.comments import CommentAPI from osclib.request_finder import RequestFinder class UnignoreCommand(object): + MESSAGE = 'Unignored: returned to active backlog.' + def __init__(self, api): self.api = api + self.comment = CommentAPI(self.api.apiurl) def perform(self, requests, cleanup=False): """ @@ -24,6 +28,7 @@ class UnignoreCommand(object): if request_id in requests_ignored: print('Removing {}'.format(request_id)) del requests_ignored[request_id] + self.comment.add_comment(request_id=str(request_id), comment=self.MESSAGE) if cleanup: now = datetime.now() From 12cd69c6abf059015fe2d6ad6a2802514ab48702 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 17 Mar 2017 14:43:52 -0500 Subject: [PATCH 3/6] ignore: remove validation since that is handled by RequestFinder. --- osclib/ignore_command.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/osclib/ignore_command.py b/osclib/ignore_command.py index 38f00648..bb9eacca 100644 --- a/osclib/ignore_command.py +++ b/osclib/ignore_command.py @@ -17,13 +17,14 @@ class IgnoreCommand(object): length = len(requests_ignored) for request_id in RequestFinder.find_sr(requests, self.api): - request_id = str(request_id) - print('Processing {}'.format(request_id)) - check = self.check_and_comment(request_id, message) - if check is not True: - print('- {}'.format(check)) - elif request_id not in requests_ignored: - requests_ignored[int(request_id)] = message + if request_id in requests_ignored: + print('{}: already ignored'.format(request_id)) + continue + + print('{}: ignored'.format(request_id)) + requests_ignored[request_id] = message + if message: + self.comment.add_comment(request_id=str(request_id), comment=message) diff = len(requests_ignored) - length if diff > 0: @@ -33,14 +34,3 @@ class IgnoreCommand(object): print('No new requests to ignore') return True - - def check_and_comment(self, request_id, message=None): - request = get_request(self.api.apiurl, request_id) - if not request: - return 'not found' - if request.actions[0].tgt_project != self.api.project: - return 'not targeting {}'.format(self.api.project) - if message: - self.comment.add_comment(request_id=request_id, comment=message) - - return True From ee5f265265f3cf4a37adb55824790839984688c9 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 17 Mar 2017 14:44:27 -0500 Subject: [PATCH 4/6] ignore: add default comment message if none provided. --- osclib/ignore_command.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osclib/ignore_command.py b/osclib/ignore_command.py index bb9eacca..9c09ec48 100644 --- a/osclib/ignore_command.py +++ b/osclib/ignore_command.py @@ -4,6 +4,8 @@ from osclib.request_finder import RequestFinder class IgnoreCommand(object): + MESSAGE = 'Ignored: removed from active backlog.' + def __init__(self, api): self.api = api self.comment = CommentAPI(self.api.apiurl) @@ -23,8 +25,8 @@ class IgnoreCommand(object): print('{}: ignored'.format(request_id)) requests_ignored[request_id] = message - if message: - self.comment.add_comment(request_id=str(request_id), comment=message) + comment = message if message else self.MESSAGE + self.comment.add_comment(request_id=str(request_id), comment=comment) diff = len(requests_ignored) - length if diff > 0: From 76dc41ed456165ea526b46e47fafe47403e509b6 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 17 Mar 2017 14:45:31 -0500 Subject: [PATCH 5/6] ignore|uningore: use past tense in output. --- osclib/ignore_command.py | 2 +- osclib/unignore_command.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osclib/ignore_command.py b/osclib/ignore_command.py index 9c09ec48..a4d531e4 100644 --- a/osclib/ignore_command.py +++ b/osclib/ignore_command.py @@ -30,8 +30,8 @@ class IgnoreCommand(object): diff = len(requests_ignored) - length if diff > 0: - print('Ignoring {} requests'.format(diff)) self.api.set_ignored_requests(requests_ignored) + print('Ignored {} requests'.format(diff)) else: print('No new requests to ignore') diff --git a/osclib/unignore_command.py b/osclib/unignore_command.py index 654e1325..e6b05ef0 100644 --- a/osclib/unignore_command.py +++ b/osclib/unignore_command.py @@ -26,7 +26,7 @@ class UnignoreCommand(object): else: for request_id in RequestFinder.find_sr(requests, self.api): if request_id in requests_ignored: - print('Removing {}'.format(request_id)) + print('{}: unignored'.format(request_id)) del requests_ignored[request_id] self.comment.add_comment(request_id=str(request_id), comment=self.MESSAGE) @@ -44,8 +44,8 @@ class UnignoreCommand(object): diff = length - len(requests_ignored) if diff > 0: - print('Unignoring {} requests'.format(diff)) self.api.set_ignored_requests(requests_ignored) + print('Unignored {} requests'.format(diff)) else: print('No requests to unignore') From 8ebe94bc5ffaf7f9add631f76fd768b9ce4c930c Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Sat, 18 Mar 2017 21:01:53 -0500 Subject: [PATCH 6/6] stagingapi: get_ignored_requests() handle empty file. --- osclib/stagingapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 18617a78..89fbb18f 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -496,7 +496,7 @@ class StagingAPI(object): def get_ignored_requests(self): ignore = self.load_file_content('{}:Staging'.format(self.project), 'dashboard', 'ignored_requests') - if ignore is None: + if ignore is None or not ignore: return {} return yaml.safe_load(ignore)