mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-29 11:16:14 +01:00
Migrate core.create_submit_request() to obs_api.Request
This commit is contained in:
parent
9078bc257c
commit
d768eff371
74
osc/core.py
74
osc/core.py
@ -4634,53 +4634,37 @@ def create_submit_request(
|
|||||||
src_package: Optional[str] = None,
|
src_package: Optional[str] = None,
|
||||||
dst_project: Optional[str] = None,
|
dst_project: Optional[str] = None,
|
||||||
dst_package: Optional[str] = None,
|
dst_package: Optional[str] = None,
|
||||||
message="",
|
message: str = "",
|
||||||
orev=None,
|
orev: Optional[str] = None,
|
||||||
src_update=None,
|
src_update: Optional[str] = None,
|
||||||
dst_updatelink=None,
|
dst_updatelink: Optional[bool] = None,
|
||||||
):
|
):
|
||||||
options_block = ""
|
from . import obs_api
|
||||||
package = ""
|
|
||||||
if src_package:
|
|
||||||
package = f"""package="{src_package}" """
|
|
||||||
options_block = "<options>"
|
|
||||||
if src_update:
|
|
||||||
options_block += f"""<sourceupdate>{src_update}</sourceupdate>"""
|
|
||||||
if dst_updatelink:
|
|
||||||
options_block += """<updatelink>true</updatelink>"""
|
|
||||||
options_block += "</options>"
|
|
||||||
|
|
||||||
# Yes, this kind of xml construction is horrible
|
req = obs_api.Request(
|
||||||
targetxml = ""
|
action_list=[
|
||||||
if dst_project:
|
{
|
||||||
packagexml = ""
|
"type": "submit",
|
||||||
if dst_package:
|
"source": {
|
||||||
packagexml = f"""package="{dst_package}" """
|
"project": src_project,
|
||||||
targetxml = f"""<target project="{dst_project}" {packagexml} /> """
|
"package": src_package,
|
||||||
# XXX: keep the old template for now in order to work with old obs instances
|
"rev": orev or show_upstream_rev(apiurl, src_project, src_package),
|
||||||
xml = """\
|
},
|
||||||
<request>
|
"target": {
|
||||||
<action type="submit">
|
"project": dst_project,
|
||||||
<source project="%s" %s rev="%s"/>
|
"package": dst_package,
|
||||||
%s
|
},
|
||||||
%s
|
"options": {
|
||||||
</action>
|
"sourceupdate": src_update,
|
||||||
<state name="new"/>
|
"updatelink": "true" if dst_updatelink else None,
|
||||||
<description>%s</description>
|
}
|
||||||
</request>
|
},
|
||||||
""" % (src_project,
|
],
|
||||||
package,
|
description=message,
|
||||||
orev or show_upstream_rev(apiurl, src_project, src_package),
|
)
|
||||||
targetxml,
|
|
||||||
options_block,
|
|
||||||
_html_escape(message))
|
|
||||||
|
|
||||||
u = makeurl(apiurl, ["request"], query={"cmd": "create"})
|
|
||||||
r = None
|
|
||||||
try:
|
try:
|
||||||
f = http_POST(u, data=xml)
|
new_req = req.cmd_create(apiurl)
|
||||||
root = ET.parse(f).getroot()
|
|
||||||
r = root.get('id')
|
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.hdrs.get('X-Opensuse-Errorcode') == "submit_request_rejected":
|
if e.hdrs.get('X-Opensuse-Errorcode') == "submit_request_rejected":
|
||||||
print('WARNING: As the project is in maintenance, a maintenance incident request is')
|
print('WARNING: As the project is in maintenance, a maintenance incident request is')
|
||||||
@ -4700,11 +4684,11 @@ def create_submit_request(
|
|||||||
raise oscerr.APIError("Server did not define a default maintenance project, can't submit.")
|
raise oscerr.APIError("Server did not define a default maintenance project, can't submit.")
|
||||||
tproject = project.get('name')
|
tproject = project.get('name')
|
||||||
r = create_maintenance_request(apiurl, src_project, [src_package], tproject, dst_project, src_update, message, rev=orev)
|
r = create_maintenance_request(apiurl, src_project, [src_package], tproject, dst_project, src_update, message, rev=orev)
|
||||||
r = r.reqid
|
return r.reqid
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return r
|
return new_req.id
|
||||||
|
|
||||||
|
|
||||||
def get_request(apiurl: str, reqid):
|
def get_request(apiurl: str, reqid):
|
||||||
|
@ -116,3 +116,25 @@ class Request(XmlModel):
|
|||||||
for issue in action.sourcediff.issue_list or []:
|
for issue in action.sourcediff.issue_list or []:
|
||||||
result.append(issue)
|
result.append(issue)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def cmd_create(self,
|
||||||
|
apiurl: str,
|
||||||
|
*,
|
||||||
|
add_revision: Optional[bool] = None,
|
||||||
|
enforce_branching: Optional[bool] = None,
|
||||||
|
ignore_build_state: Optional[bool] = None,
|
||||||
|
ignore_delegate: Optional[bool] = None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
:param add_revision: Ask the server to add revisions of the current sources to the request.
|
||||||
|
:param ignore_build_state: Skip the build state check.
|
||||||
|
:param ignore_delegate: Enforce a new package instance in a project which has OBS:DelegateRequestTarget set.
|
||||||
|
"""
|
||||||
|
url_path = ["request"]
|
||||||
|
url_query = {
|
||||||
|
"cmd": "create",
|
||||||
|
"addrevision": add_revision,
|
||||||
|
"ignore_delegate": ignore_delegate,
|
||||||
|
}
|
||||||
|
response = self.xml_request("POST", apiurl, url_path, url_query, data=self.to_string())
|
||||||
|
return Request.from_file(response, apiurl=apiurl)
|
||||||
|
Loading…
Reference in New Issue
Block a user