From: Matthias Kruk Date: Wed, 19 May 2021 23:32:28 +0000 (+0900) Subject: include/gitlab: Allow destination namespace to be passed to fork methods X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=5a43d0816fdd5b8f78fa28af3d323c3cc35116cf;p=toolbox include/gitlab: Allow destination namespace to be passed to fork methods The gitlab_fork() and gitlab_fork_sync() functions can only be used to for a project to the user's personal namespace, since they do not allow the destination namespace to be specified. This commit adds an argument for the destination namespace, so that the functions can be used to fork into arbitrary namespaces. --- diff --git a/include/gitlab.sh b/include/gitlab.sh index 00cac8e..e990dd9 100755 --- a/include/gitlab.sh +++ b/include/gitlab.sh @@ -183,43 +183,39 @@ gitlab_get_user_id() { } gitlab_fork() { - local host - local token - local project + local host="$1" + local token="$2" + local project="$3" + local namespace="$4" - local url - local id - local data - local resp + local url + local id + local data - host="$1" - token="$2" - project="$3" + id=$(_gitlab_urlencode "$project") + url="$host/api/v4/projects/$id/fork" - id=$(_gitlab_urlencode "$project") - url="$host/api/v4/projects/$id/fork" - data=$(json_make "id" "$id") + # json_object() will silently drop the namespace if "$namespace" is empty + data=$(json_object "id" "$id" \ + "namespace" "$namespace") - if ! _gitlab_post "$token" "$url" "$data"; then - return 1 - fi + if ! _gitlab_post "$token" "$url" "$data"; then + return 1 + fi - return 0 + return 0 } gitlab_fork_sync() { - local host - local token - local project + local host="$1" + local token="$2" + local project="$3" + local namespace="$4" local resp local fork_id - host="$1" - token="$2" - project="$3" - - if ! resp=$(gitlab_fork "$host" "$token" "$project"); then + if ! resp=$(gitlab_fork "$host" "$token" "$project" "$namespace"); then echo "Could not fork project" 1>&2 return 1 fi