I'm using GitLab 11.9 (it's old, I know ....), and I need to list all the repositories that have been created but that are empty o with zero commits.
Is it possible to list them from admin interface o via API?
I'm using GitLab 11.9 (it's old, I know ....), and I need to list all the repositories that have been created but that are empty o with zero commits.
Is it possible to list them from admin interface o via API?
To achieve this with Gitlab API we will combine Projects API https://docs.gitlab.com/ee/api/projects.html#list-all-projects
And the Commits API https://docs.gitlab.com/ee/api/projects.html#list-all-projects
To the following bash script (Make sure you have curl and jq installed)
#!/bin/bash
ACCESS_TOKEN=$1
GITLAB_URL=$2
curl -s --header "PRIVATE-TOKEN: $ACCESS_TOKEN" $GITLAB_URL/api/v4/projects/?per_page=50000 | jq '.[] | "\(.id) \(.web_url) \(.name)"' | sed 's/^"\(.*\)"$/\1/'| while read line
do
PROJECT_ID=$(echo $line | cut -d " " -f1 )
PROJECT_NAME=$(echo $line | cut -d " " -f3- )
REPO_URL=$(echo $line | cut -d " " -f2 )
COMMIT_IDS=$(curl -s --header "PRIVATE-TOKEN: $ACCESS_TOKEN" $GITLAB_URL/api/v4/projects/$PROJECT_ID/repository/commits | jq '.[].id')
if [[ $COMMIT_IDS == "" ]]; then echo "$PROJECT_ID $PROJECT_NAME $REPO_URL";fi
done
Execution Example:
./my_script.sh "<your_access_token>" "https://gitlab.example.com"
The output of this script will be the Project ID Project Name and Project URL of the repos with 0 commits
E.G.
33294654 project-for-issues-286e58fd4f6a5603 https://gitlab.com/gitlab-qa-sandbox-group/qa-test-2022-01-31-18-09-07-311cfe607ff3ce9b/project-for-issues-286e58fd4f6a5603
33294612 project-with-ci-variables-c1b233588d3fbce7 https://gitlab.com/gitlab-qa-sandbox-group/qa-test-2022-01-31-18-09-05-68cad66167d10aa2/project-with-ci-variables-c1b233588d3fbce7
Note: This script assumes that you have less than 50.000 repositories in your Gitlab