diff --git a/tools/apertis-pkg-merge-upstream-to-downstreams b/tools/apertis-pkg-merge-upstream-to-downstreams index d265bed359d3d30177644510ce008bd56a674c7d..fdc31a0c3b538299c54562d7e98b8573418d8b5d 100755 --- a/tools/apertis-pkg-merge-upstream-to-downstreams +++ b/tools/apertis-pkg-merge-upstream-to-downstreams @@ -183,6 +183,32 @@ def ensure_downstream_branch(project_url, downstream, dry_run): raise +def get_path_with_namespace(project_url): + url = urllib.parse.urlsplit(project_url) + project_id = urllib.parse.quote(removesuffix(url.path.strip("/"), ".git"), safe="") + # drop the inline auth data as urllib does not like it + auth, netloc_no_auth = url.netloc.split("@", 1) + token = auth.split(":", 1)[-1] + url = url._replace( + path=f"/api/v4/projects/{project_id}", + netloc=netloc_no_auth, + ) + project_metadata = url.geturl() + req_project_metadata = urllib.request.Request( + url=project_metadata, + headers={"PRIVATE-TOKEN": token}, + ) + try: + res = urllib.request.urlopen(req_project_metadata) + json_res = json.load(res) + path_with_namespace = json_res["path_with_namespace"] + except urllib.error.HTTPError as e: + print("ERROR:", e.read().decode()) + raise + + return path_with_namespace + + def push_merge_request( project_url, proposed_branch, upstream, downstream, auto_merge="", dry_run=False ): @@ -213,8 +239,11 @@ def push_merge_request( ensure_downstream_branch(project_url, downstream, dry_run) + project_path = get_path_with_namespace(project_url) + print( - f"Create merge request from '{proposed_branch}' to '{downstream}'", flush=True + f"Create merge request from '{proposed_branch}' to '{project_path}/{downstream}'", + flush=True, ) git_push_custom( "-o", @@ -224,6 +253,8 @@ def push_merge_request( "-o", f"merge_request.target={downstream}", "-o", + f"merge_request.target_project={project_path}", + "-o", f"merge_request.title={title}", project_url, f"{proposed_branch}:{proposed_branch}",