Categories
t3ch

GitLab Delete Bulk Issues

At the time of this writing (June 20, 2019), GitLab doesn’t have a feature to bulk delete issues. This is a real challenge for me right now. I’ve got builds auto-creating issues that have been ignored for months. I now have thousands of issues to remove.

Save me  your lectures about maintenance and architecture. Let’s just fix this issue.

You’ll need to get your own personal access token. You can get that by going to https://example.gitlab.com/profile/personal_access_tokens.

Screen Shot 2019-06-20 at 9.35.15 PM

 

You’ll also need to know your user Id. You can get that by going to https://example.gitlab.com/profile

Screen Shot 2019-06-20 at 9.35.03 PM

Once you have all that, fill in the appropriate variables and fire away 😀

#!/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

By ftpcory

I am a fitness, technology, and music enthusiast. I enjoy introspection and reflection. I believe in decentralization of the web and freedom of expression.

2 replies on “GitLab Delete Bulk Issues”

Leave a Reply

Your email address will not be published. Required fields are marked *