Reputation: 39
We have repository mirroring to Azure set up on quite a few projects in our internal GitLab. I just discovered that generated credentials from Azure Git can be used to mirror other repositories too (not just the ones where the credentials were generated) if you have higher permissions. But I have already setup a lot of projects with different credentials and I would like to use just one pair of credentials and document where they were used. Problem is that now mirroring is set up on some projects and not set up on others.
Is there a way to display all the projects that have some kind of mirroring enabled so I don't have to go trough every single project and check manually?
We are running GitLab14.3.2-ee and I wasn't able to find anything like this in the Admin center
Upvotes: 1
Views: 1011
Reputation: 11
using the api this can be done without having gitlab premium (it just slower since you cannot query the mirror property on the project)
Using Powershell
# variables
$headers = @{
Authorization="Bearer [user gitlab token]"
}
$hasPages = $true;
$pageNumber = 1;
$countPerPage = 100; #max value is 100
# keep calling api untill we have loop all pages
while($hasPages) {
# call get project
$reponse = Invoke-WebRequest ("https://gitlab.company.com/api/v4/projects?page={0}&per_page={1}&simple=false" -f $pageNumber, $countPerPage) -Headers $headers
$json = $reponse | Select-Object -Expand Content | ConvertFrom-Json
# foreach project, get the mirroring details
foreach ($project in $json) {
$jsonMirror = Invoke-WebRequest ("https://gitlab.company.com/api/v4/projects/{0}/remote_mirrors" -f $project.id) -Headers $headers | Select-Object -Expand Content| ConvertFrom-Json
# if project has mirroring setup, display it
if ($jsonMirror.Count -gt 0) {
Write-Host("{0}" -f $project.name)
Write-Host(" Repo : {0}" -f $project.web_url)
Write-Host(" Mirror : {0}" -f $jsonMirror[0].url)
}
}
# get the next page number
$pageNumber = $reponse.Headers["X-Next-Page"]
# did we reach the last page
if ([string]::IsNullOrEmpty($pageNumber)) {
$hasPages = $false
}
}
output :
Azure DevOps Project Template
Repo : https://gitlab.company.com/devops-internal/azure-devops-project-template
Mirror : https://*****:*****@dev.azure.com/DevOpsMacBuilds/Name/_git/Name
Mobile-Lib-Android
Repo : https://gitlab.company.com/applications/mobile-lib-android
Mirror : https://*****:*****@dev.azure.com/DevOpsMacBuilds/Mobile-Lib-Android/_git/Mobile-Lib-Android
Mobile-Lib-iOS
Repo : https://gitlab.company.com/applications/mobile-lib-ios
Mirror : https://*****:*****@dev.azure.com/DevOpsMacBuilds/Mobile-Lib-iOS/_git/Mobile-Lib-iOS
Install-Android
Repo : https://gitlab.company.com/applications/install-android
Mirror : https://*****:*****@dev.azure.com/DevOpsMacBuilds/Install-Android/_git/Install-Android
Upvotes: 1
Reputation: 15995
Here's my version, written in shell.
Requirements:
PRIVATE_TOKEN
GITLAB_API_URL
# Results are paginated; get number of pages
number_of_pages=$(curl -s --head --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "${GITLAB_API_URL}/projects?archived=false" | grep x-total-pages | awk '{print $2}' | tr -d '\r\n')
for page in $(seq 1 $number_of_pages); do
project_urls=$(curl -s --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "${GITLAB_API_URL}/projects?archived=false&page=${page}" | jq -r '.[] | select(.mirror == true) | .web_url')
if [[ -n "${project_urls}" ]]; then
echo "${project_urls}" | tr ' ' '\n'
fi
done
Tweak it as needed (e.g. remove archived=false
if you want to include archived projects)
Upvotes: 0
Reputation: 3230
There isn't a way to easily display only repositories with mirroring enabled within the UI. However, you can access this information from the APIs. Calling the list-all-projects API returns a list of projects that you will need to paginate through. Each project has a mirror
attribute that will be set to true or false, along with info about the mirror URL.
Upvotes: 0