Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Created September 29, 2023 16:38
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 infamousjoeg/394bb4f05cdb6544e20b0e8a926f855a to your computer and use it in GitHub Desktop.
Save infamousjoeg/394bb4f05cdb6544e20b0e8a926f855a to your computer and use it in GitHub Desktop.
GitLab Delete Projects with Last Activity Before Specific Date
#!/bin/bash
# Set your personal access token here
personalAccessToken="<personal-access-token>"
# Get the list of project IDs for owned projects with last activity before 2020-01-01
project_ids=$(curl --header "PRIVATE-TOKEN: $personalAccessToken" "https://gitlab.com/api/v4/projects?simple=true&per_page=100&owned=true&last_activity_before=2020-01-01T00:00:00Z" | jq -r '.[] | select(.last_activity_at < "2020-01-01T00:00:00Z") | .id')
# Loop through each project ID and delete the project
for project_id in $project_ids; do
echo "Deleting project ID: $project_id"
curl --request DELETE --header "PRIVATE-TOKEN: $personalAccessToken" "https://gitlab.com/api/v4/projects/$project_id"
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment