How to delete every closed milestone

Since we’re a small team, we set the milestone with the number of the week. ex: week - 12.

But then, when started a new year, we cannot create those milestone anymore because they already exists and are closed.

I would like to delete every closed milestone and tried to use the giltab API for this purpose.

I’ve created the follwing script :

requesting every closed milestone working

# global.sh
get_closed_milestones(){
  curl -s -H "$private_token" \
  -X GET \
  "$base_url"'groups/'"$group_name"''/milestones?state=closed'
}

remove_milestone() {
  curl -H "$private_token" \
  -X DELETE \
  "$base_url"'groups/'"$group_name"''/milestones/'"$1"''
}

making a loop and deleting it

# milestone-remover.sh
#!/bin/bash

# Importes
source ./includes/global.sh

issues=$(get_closed_milestones)

  for milestone_id in $(jq -c '.[] | .id'<<< "$issues"); do

  milestone_id= echo ${milestone_id%/r}


  # If not null
    if [ ! "$milestone_id" == "null/r" ];
    then
     remove_milestone $milestone_id
    fi

  done

I had to use the ! "$milestone_id" == "null/r" cause I realize I did get null like this.
It is looking a bit stang but it did send the request. I’ll then had this response

https://gitlab.entepriseName.ch/api/v4/groups/entepriseName/milestones/279
curl: (3) URL using bad/illegal format or missing URL

Does somebody see an error?

Is it correct that the groupname is also the enterprisename? I’d expect that the groupname is different, and that the $1 var doesn’t contain the correct groupname.

Edit: sorry I read that wrong, but I can’t see how you’ve put the group_name into the script, but you’d expect that to be the same as during the getting, so if you have a list of milestone_id’s, you’d expect that part to work

created a testgroup and milestone and could remove the milestone with a DELETE query to api/v4/groups/testgroup/milestones/milestone_id (I did use the group_name and not the group ID). I did add a Content-Type application/json header, I can’t see whether you included that.

Not sure where the /r is needed for.

When I pipe json replies through jq, I usually do it when creating a list of ID’s (directly after the curl request or in a separate processing step, not storing the raw json and use an inline processing, but that might be more a personal preference.