To create an empty repository named some-example-repository in a self-hosted GitLab server, I wrote the following bash method:
create_repository() {
repo_name="$1"
# load personal_access_token (from hardcoded data)
personal_access_token=$(echo "$GITLAB_PERSONAL_ACCESS_TOKEN" | tr -d '\r')
# Create the repository in the GitLab server
{ # try
output=$(curl -H "Content-Type:application/json" http://127.0.0.1/api/v4/projects?private_token="$personal_access_token" -d "{ \"name\": \"$repo_name\" }")
echo "output=$output"
true
} || { # catch
true
}
}
However, it is not functioning reliably, and occasionally it indicates a limit is reached. Hence, I would like to ask: how could I reliably create an empty GitLab repository in a self-hosted GitLab server using Bash and a personal access token?