Skip to content

Instantly share code, notes, and snippets.

@corycollier
Created June 21, 2019 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corycollier/dac5f7042ff30e64f91cbc284f94a116 to your computer and use it in GitHub Desktop.
Save corycollier/dac5f7042ff30e64f91cbc284f94a116 to your computer and use it in GitHub Desktop.
Script to bulk delete gitlab issues.
#!/usr/bin/env bash
declare -i _page=0
declare -i _number_of_pages=0
declare _person_access_token="asdfasdfasdfsadf"
declare _gitlab_host="https://gitlab.example.com/api/v4"
declare _assignee="12345"
declare _url="${_gitlab_host}/issues?private_token=${_person_access_token}&assignee=${_assignee}&per_page=100"
_number_of_pages=$(curl -i -I "${_url}" | grep x-total-pages | awk '{print $2}' | sed 's/[^0-9]*//g')
while [ $_page -lt "$_number_of_pages" ]; do
_page=$((_page+1))
_url="${_gitlab_host}/v4/issues?private_token=${_person_access_token}&assignee=${_assignee}&per_page=100&page=${_page}"
_data=$(curl "${_url}" | jq -r '.[] | "\(.iid) \(.project_id)"')
while read -r _info; do
echo "Project [${_project_id}] Issue [${_issue_iid}]"
_issue_iid=$(echo "${_info}" | awk '{print $1}')
_project_id=$(echo "${_info}" | awk '{print $2}')
_url="${_gitlab_host}/projects/${_project_id}/issues/${_issue_iid}"
curl --request DELETE --header "PRIVATE-TOKEN: ${_person_access_token}" "${_url}"
done <<< "${_data}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment