It is not uncommon for a request to be in a pending state which requires action beyond the scope of the staging workflow, but does not make sense to deny the request. For lack of a "postponed" or "pending" state on OBS a sudo-state of "ignore" is provided for the staging workflow. The ignore state will remove a request from the "list" and "adi" commands so as not to be accidentally staged. This avoids the need for keeping a context of what requests should be ignored in one's memory. It is expected that an ignored request will have comments reflecting what is to be done or one should be added via the -m option of ignore command.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from osc.core import get_request
|
|
from osclib.comments import CommentAPI
|
|
|
|
|
|
class IgnoreCommand(object):
|
|
def __init__(self, api):
|
|
self.api = api
|
|
self.comment = CommentAPI(self.api.apiurl)
|
|
|
|
def perform(self, request_ids, message=None):
|
|
"""
|
|
Ignore a request from "list" and "adi" commands until unignored.
|
|
"""
|
|
|
|
requests_ignored = self.api.get_ignored_requests()
|
|
length = len(requests_ignored)
|
|
|
|
for request_id in request_ids:
|
|
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
|
|
|
|
diff = len(requests_ignored) - length
|
|
if diff > 0:
|
|
print('Ignoring {} requests'.format(diff))
|
|
self.api.set_ignored_requests(requests_ignored)
|
|
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
|