2017-03-16 14:43:28 +01:00
|
|
|
import osc
|
2018-11-05 15:46:50 +01:00
|
|
|
|
2019-12-04 15:09:12 +01:00
|
|
|
from urllib.error import HTTPError
|
2017-03-16 14:43:28 +01:00
|
|
|
|
2022-02-18 17:15:48 +01:00
|
|
|
|
2017-03-16 14:43:28 +01:00
|
|
|
class PrioCommand(object):
|
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2019-12-04 15:09:12 +01:00
|
|
|
def _setprio(self, status, priority):
|
2017-03-16 14:43:28 +01:00
|
|
|
"""
|
|
|
|
Set prios for requests that are still in review
|
|
|
|
:param project: project to check
|
|
|
|
|
|
|
|
"""
|
2024-05-07 17:55:17 +02:00
|
|
|
message = f"raising priority for {status.get('name')}"
|
2019-12-04 15:09:12 +01:00
|
|
|
for r in status.findall('missing_reviews/review'):
|
|
|
|
reqid = r.get('request')
|
2017-03-16 14:43:28 +01:00
|
|
|
req = osc.core.get_request(self.api.apiurl, reqid)
|
2019-12-04 15:09:12 +01:00
|
|
|
if req.priority == priority:
|
|
|
|
continue
|
2022-02-18 17:23:02 +01:00
|
|
|
query = {'cmd': 'setpriority', 'priority': priority}
|
2019-12-04 15:09:12 +01:00
|
|
|
url = osc.core.makeurl(self.api.apiurl, ['request', reqid], query)
|
|
|
|
print(f"raising priority of {r.get('package')} [{r.get('request')}] to {priority}")
|
|
|
|
try:
|
|
|
|
osc.core.http_POST(url, data=message)
|
|
|
|
except HTTPError as e:
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
def perform(self, projects, priority):
|
2017-03-16 14:43:28 +01:00
|
|
|
"""
|
2017-03-17 14:11:55 -05:00
|
|
|
Set priority on specific stagings or all of them at once
|
|
|
|
:param projects: projects on which to set priority, None for all
|
2017-03-16 14:43:28 +01:00
|
|
|
"""
|
2018-08-16 18:01:25 -05:00
|
|
|
if not priority:
|
|
|
|
priority = 'important'
|
|
|
|
|
2017-03-17 14:11:55 -05:00
|
|
|
for project in projects:
|
2019-12-04 15:09:12 +01:00
|
|
|
project = self.api.prj_from_short(project)
|
|
|
|
info = self.api.project_status(project, status=False)
|
2018-08-16 18:01:25 -05:00
|
|
|
self._setprio(info, priority)
|
2017-03-16 14:43:28 +01:00
|
|
|
|
|
|
|
return True
|