How to list/delete all empty repositories in GitLab. I have multiple empty repros in my GitLab. Is there any way to delete them all instead of deleting them manually?
How to list/delete all empty repositories in GitLab. I have multiple empty repros in my GitLab. Is there any way to delete them all instead of deleting them manually?
I am not providing you the script here, as i have not written one, i just outline the process i would choose and the APIs which would be useful for this job.
The question first to ask is, how do you define an empty repository - lets assume you say a repository with a certain amount of commits.
For this you can use the projects API https://docs.gitlab.com/ee/api/projects.html#list-all-projects - where you can get a list of all projects, with some statistics and generate a list out of those who matches your characteristics. (statistics.commits is a nice field for that)
GET /users/:user_id/projects
With this list of projects IDs you can start deleting them with the project API for deleting https://docs.gitlab.com/ee/api/projects.html#delete-project
DELETE /projects/:id
GitLab's /projects API returns a property called empty_repo on each project. I didn't find a reasonable way to query according to it in the API itself (although I may be missing something), but you could script it with a tool like jq.
E.g., to get the ids of all the empty projects:
curl --header "PRIVATE-TOKEN: <yourtoken>" -k https://gitlab.com/api/v4/projects | jq '.[] | select(.empty_repo==true) | .id'
In addition to Simon's answer, The most import thing is to define empty repos. Besides the number of commits, you can also use last_activity_at to filter the time.
After you've find the projects. You may delete them by using the DELETE projects API.