I have just got the responsibility for around 100 different repositories (applications), distributed on about 20 project in Azure DevOps.
I want to get some (very) basic metrics on each project:
Just simple counting and listing. Nothing fancy as test coverage etc. So far all my searching has only given results about code analysis and other advanced stuff. It's not where I am in my tasks right now.
Is there a way to do it in Azure DevOps?
Azure DevOps doesn’t directly provide a built-in feature to summarize the information you need. If you need a more automated way, consider using Azure DevOps REST API.
The following is an example PowerShell script using the Azure DevOps Git API to obtain the repositories and branch numbers:
# Define organization, PAT
$orgUrl = "https://dev.azure.com/orgname"
$pat = "xxx"
$APIVersion = "api-version=6.1-preview.1"
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
}
# Function to make REST API requests
function Invoke-AzureDevOpsAPI {
param (
[string]$url,
[string]$method
)
try {
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method $method
return $response
}
catch {
Write-Host "Error calling API: $($_.Exception.Message)"
return $null
}
}
# Get the list of all projects
$projectsUrl = "$orgUrl/_apis/projects?$APIVersion"
$projectsResponse = Invoke-AzureDevOpsAPI -url $projectsUrl -method "GET"
if ($projectsResponse) {
Write-Host "Projects in your organization:"
foreach ($project in $projectsResponse.value) {
Write-Host " $($project.name)"
# Get repositories for the current project
$reposUrl = "$orgUrl/$($project.name)/_apis/git/repositories?$APIVersion"
$reposResponse = Invoke-AzureDevOpsAPI -url $reposUrl -method "GET"
if ($reposResponse) {
Write-Host " Repositories in project:"
foreach ($repo in $reposResponse.value) {
Write-Host " $($repo.name)"
# Get branches for the current repository
$branchesUrl = "$orgUrl/$($project.name)/_apis/git/repositories/$($repo.id)/refs?filter=heads&api-version=6.0"
$branchesResponse = Invoke-AzureDevOpsAPI -url $branchesUrl -method "GET"
if ($branchesResponse) {
$branchCount = $branchesResponse.count
Write-Host " Number of branches: $branchCount"
}
else {
Write-Host " Failed to retrieve branch information for $($repo.name)."
}
}
}
else {
Write-Host " Failed to retrieve repository information for $($project.name)."
}
}
}
else {
Write-Host "Failed to retrieve project information."
}
For the developers information, you can try with this API Commits - Get Commits.
For the Number of Files in a Branch and Number of Code Lines in a Branch, it seems no API is related to it. You can clone the repository and run git command to get the information.
You can also check the Azure DevOps extension Marketplace to find the appropriate extension. If there is no extension that you are satisfied with, you can also develop your own extension.