-
Notifications
You must be signed in to change notification settings - Fork 89
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 #372 from openSUSE/coolo_adi
add adi command to create an ad interim staging prj for all non-ring …
- Loading branch information
Showing
5 changed files
with
138 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import json | ||
|
||
from osc import oscerr | ||
from osc.core import delete_project | ||
|
||
from osclib.select_command import SelectCommand | ||
from osclib.request_finder import RequestFinder | ||
|
||
class AdiCommand: | ||
def __init__(self, api): | ||
self.api = api | ||
|
||
def check_adi_project(self, project): | ||
query_project = 'adi:' + project.split(':adi:')[1] | ||
query = {'format': 'json'} | ||
url = self.api.makeurl(('project', 'staging_projects', self.api.project, | ||
query_project), query=query) | ||
info = json.load(self.api.retried_GET(url)) | ||
if len(info['building_repositories']): | ||
print project, "still building" | ||
return | ||
if len(info['broken_packages']): | ||
print "https://build.opensuse.org/project/show/{}".format(project), "has broken packages" | ||
return | ||
for review in info['missing_reviews']: | ||
print project, "has at least one missing review by", review['by'], "in", review['request'] | ||
return | ||
if len(info['untracked_requests']) or len(info['obsolete_requests']): | ||
print project, "has inconsistent requests" | ||
return | ||
print project, "is ready" | ||
for req in info['selected_requests']: | ||
print req['id'] | ||
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept') | ||
delete_project(self.api.apiurl, project) | ||
|
||
def check_adi_projects(self): | ||
for p in self.api.get_adi_projects(): | ||
self.check_adi_project(p) | ||
|
||
def create_new_adi(self, wanted_requests): | ||
all_requests = self.api.get_open_requests() | ||
|
||
non_ring_packages = [] | ||
non_ring_requests = [] | ||
|
||
for request in all_requests: | ||
# Consolidate all data from request | ||
request_id = int(request.get('id')) | ||
if len(wanted_requests) and request_id not in wanted_requests: | ||
continue | ||
action = request.findall('action') | ||
if not action: | ||
msg = 'Request {} has no action'.format(request_id) | ||
raise oscerr.WrongArgs(msg) | ||
# we care only about first action | ||
action = action[0] | ||
|
||
# Where are we targeting the package | ||
target_package = action.find('target').get('package') | ||
|
||
if not self.api.ring_packages.get(target_package): | ||
non_ring_packages.append(target_package) | ||
non_ring_requests.append(request_id) | ||
|
||
if len(non_ring_packages): | ||
print "Not in a ring:", ' '.join(sorted(non_ring_packages)) | ||
else: | ||
return | ||
|
||
name = self.api.create_adi_project(None) | ||
|
||
sc = SelectCommand(self.api, name) | ||
|
||
for request in non_ring_requests: | ||
if not self.api.rq_to_prj(request, name): | ||
return False | ||
|
||
# Notify everybody about the changes | ||
self.api.update_status_comments(name, 'select') | ||
|
||
|
||
def perform(self, packages): | ||
""" | ||
Perform the list command | ||
""" | ||
if len(packages): | ||
requests = set() | ||
for request, request_project in RequestFinder.find_sr(packages, | ||
self.api).items(): | ||
requests.add(request) | ||
self.create_new_adi(requests) | ||
else: | ||
self.check_adi_projects() | ||
self.create_new_adi(()) |
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