Skip to content

Instantly share code, notes, and snippets.

@jeroensmink98
Created May 12, 2023 10:05
Show Gist options
  • Save jeroensmink98/3e06f2f596375c6411d459c6c1f0eb3d to your computer and use it in GitHub Desktop.
Save jeroensmink98/3e06f2f596375c6411d459c6c1f0eb3d to your computer and use it in GitHub Desktop.
Fetch all Azure Repos and branches for a project
$project = "PROJECT_NAME"
try {
$repos = az repos list -p $project | ConvertFrom-Json
} catch {
Write-Host "Failed to fetch repositories for project $project"
exit
}
$results = @()
Write-Host "Project: $project"
foreach ($repo in $repos) {
Write-Host "Repository: $($repo.name)"
try {
$refs = az repos ref list -p $project -r $repo.name --filter heads | ConvertFrom-Json
Write-Host "Found $($refs.count) refs"
} catch {
Write-Host "Failed to fetch refs for repository $($repo.name)"
continue
}
foreach($ref in $refs) {
Write-Host "Ref: $($ref.name)"
$objectId = $ref.objectId
# sleep 100 ms
Start-Sleep -Milliseconds 100
# fetch individual commit details
try {
$commit = az devops invoke `
--area git `
--resource commits `
--route-parameters `
project=$project `
repositoryId=$($repo.name) `
commitId=$objectId |
ConvertFrom-Json
} catch {
Write-Host "Failed to fetch commit details for ref $objectId"
continue
}
$result = [PSCustomObject]@{
repository = $repo.name
name = $ref.name
creator = $ref.creator.uniqueName
lastAuthor = $commit.committer.email
lastModified = $commit.push.date
}
$results += ,$result
}
}
$results | Sort-Object -Property lastModified -Descending | Format-Table -AutoSize
# Write to CSV
$results | Sort-Object -Property lastModified -Descending | Export-Csv -Path "output.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment