Merge pull request #765 from jberry-suse/cleanup-ignore
Cleanup ignore and always provide a comment.
This commit is contained in:
commit
99c358703f
@ -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)
|
||||
@ -17,30 +19,20 @@ 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
|
||||
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:
|
||||
print('Ignoring {} requests'.format(diff))
|
||||
self.api.set_ignored_requests(requests_ignored)
|
||||
print('Ignored {} requests'.format(diff))
|
||||
else:
|
||||
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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -2,13 +2,18 @@ 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, request_ids, cleanup=False):
|
||||
def perform(self, requests, cleanup=False):
|
||||
"""
|
||||
Unignore a request by removing from ignore list.
|
||||
"""
|
||||
@ -16,14 +21,14 @@ 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))
|
||||
print('{}: unignored'.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()
|
||||
@ -39,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')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user