diff --git a/osc/core.py b/osc/core.py index 27ba092b..682b0096 100644 --- a/osc/core.py +++ b/osc/core.py @@ -4634,53 +4634,37 @@ def create_submit_request( src_package: Optional[str] = None, dst_project: Optional[str] = None, dst_package: Optional[str] = None, - message="", - orev=None, - src_update=None, - dst_updatelink=None, + message: str = "", + orev: Optional[str] = None, + src_update: Optional[str] = None, + dst_updatelink: Optional[bool] = None, ): - options_block = "" - package = "" - if src_package: - package = f"""package="{src_package}" """ - options_block = "" - if src_update: - options_block += f"""{src_update}""" - if dst_updatelink: - options_block += """true""" - options_block += "" + from . import obs_api - # Yes, this kind of xml construction is horrible - targetxml = "" - if dst_project: - packagexml = "" - if dst_package: - packagexml = f"""package="{dst_package}" """ - targetxml = f""" """ - # XXX: keep the old template for now in order to work with old obs instances - xml = """\ - - - - %s - %s - - - %s - -""" % (src_project, - package, - orev or show_upstream_rev(apiurl, src_project, src_package), - targetxml, - options_block, - _html_escape(message)) + req = obs_api.Request( + action_list=[ + { + "type": "submit", + "source": { + "project": src_project, + "package": src_package, + "rev": orev or show_upstream_rev(apiurl, src_project, src_package), + }, + "target": { + "project": dst_project, + "package": dst_package, + }, + "options": { + "sourceupdate": src_update, + "updatelink": "true" if dst_updatelink else None, + } + }, + ], + description=message, + ) - u = makeurl(apiurl, ["request"], query={"cmd": "create"}) - r = None try: - f = http_POST(u, data=xml) - root = ET.parse(f).getroot() - r = root.get('id') + new_req = req.cmd_create(apiurl) except HTTPError as e: if e.hdrs.get('X-Opensuse-Errorcode') == "submit_request_rejected": 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.") tproject = project.get('name') r = create_maintenance_request(apiurl, src_project, [src_package], tproject, dst_project, src_update, message, rev=orev) - r = r.reqid + return r.reqid else: raise - return r + return new_req.id def get_request(apiurl: str, reqid): diff --git a/osc/obs_api/request.py b/osc/obs_api/request.py index 76b4935a..62d8e9cd 100644 --- a/osc/obs_api/request.py +++ b/osc/obs_api/request.py @@ -116,3 +116,25 @@ class Request(XmlModel): for issue in action.sourcediff.issue_list or []: result.append(issue) 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)