Unverified Commit ab9185e8 authored by Guilhem Bonnefille's avatar Guilhem Bonnefille Committed by GitLab
Browse files

fix: avoid request source API for release info

The API calls are rate limited.
The content of a release is already fetched while listing the releases.

With this patch, we reuse directly this content avoiding a call to the API.
parent 50ea5781
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -106,14 +106,14 @@ function maybe_create_group() {
# Synchronize a Release for a project
# $1: source project ID
# $2: destination project ID
# $3: release tag name
# $3: release (as JSON object)
function sync_release() {
  src_project_id=$1
  dest_project_id=$2
  tag_name=$3
  src_release=$3

  tag_name=$(echo "$src_release" | jq -r .tag_name)
  log_info "Synchronizing release \\e[33;1m${tag_name}\\e[0m to project ID \\e[33;1m${dest_project_id}\\e[0m)"
  src_release=$(curl ${INSECURE:+-k} -sSf -H "${SRC_TOKEN:+PRIVATE-TOKEN: $SRC_TOKEN}" "$SRC_GITLAB_API/projects/$src_project_id/releases/$tag_name")

  dest_release_status=$(curl ${INSECURE:+-k} -s -o /dev/null -I -w "%{http_code}" -H "${DEST_TOKEN:+PRIVATE-TOKEN: $DEST_TOKEN}" "$DEST_GITLAB_API/projects/$dest_project_id/releases/$tag_name")
  if [[ "$dest_release_status" == 404* ]]
@@ -274,7 +274,7 @@ function sync_project() {
    fi

    # 3: sync Releases
    curl ${INSECURE:+-k} -sSf -H "${SRC_TOKEN:+PRIVATE-TOKEN: $SRC_TOKEN}" "$SRC_GITLAB_API/projects/$src_project_id/releases?per_page=100" | jq -r '.[].tag_name' | while read -r release; do
    curl ${INSECURE:+-k} -sSf -H "${SRC_TOKEN:+PRIVATE-TOKEN: $SRC_TOKEN}" "$SRC_GITLAB_API/projects/$src_project_id/releases?per_page=100" | jq -c '.[]' | while read -r release; do
      sync_release "$src_project_id" "$dest_project_id" "$release"
    done
  fi