Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from jberry-suse/request-ignore
Provide ignore/unignore request staging commands.
- Loading branch information
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from osc.core import get_request | ||
|
||
|
||
class UnignoreCommand(object): | ||
def __init__(self, api): | ||
self.api = api | ||
|
||
def perform(self, request_ids): | ||
""" | ||
Unignore a request by removing from ignore list. | ||
""" | ||
|
||
requests_ignored = self.api.get_ignored_requests() | ||
length = len(requests_ignored) | ||
|
||
if len(request_ids) == 1 and request_ids[0] == 'all': | ||
requests_ignored = {} | ||
else: | ||
for request_id in request_ids: | ||
request_id = int(request_id) | ||
if request_id in requests_ignored: | ||
print('Removing {}'.format(request_id)) | ||
del requests_ignored[request_id] | ||
|
||
diff = length - len(requests_ignored) | ||
if diff > 0: | ||
print('Unignoring {} requests'.format(diff)) | ||
self.api.set_ignored_requests(requests_ignored) | ||
else: | ||
print('No requests to unignore') | ||
|
||
return True |