I have number of projects in Azure DevOps. I want to able to iterate through all Repos in Azure DevOps and get the name of the Repo, Creator of Repo and Last Updated/commit.
And get a notification when some one created new Repo?
2 Answers
We can list the repo info via REST API
List all repositories and get the name of the repo:
GET GET Note: we can get the branch creator via this API, I didn't find any APIs to get the repo creator.
GET Get a notification when some one created new Repo
We cannot create this notification, we can get a notification when someone updated the repo code. Please refer this link for more details: Supported event types
Update1
//List project name $connectionToken="PAT" $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)")) $ProjectUrl = "" $Repo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) $RepoName= $Repo.value.name Write-Host $RepoName //get latest commit info and branch creator $RepoID=$Repo.value.id Write-Host $RepoID ForEach ($Id in $RepoID) { //Get latest commit info $ProjectUrl = "" $CommitInfo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) $CommitID = $CommitInfo.value.commitId | Select-Object -first 1 Write-Host $CommitID $CommitUrl = "($CommitID)?api-version=6.0-preview.1" $LatestCommitInfo = (Invoke-RestMethod -Uri $CommitUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) Write-Host "LatestCommitInfo = $($LatestCommitInfo | ConvertTo-Json -Depth 100)" //Get branch name and creatot $BarchCreatorUrl = "" $CreateorInfo = (Invoke-RestMethod -Uri $BarchCreatorUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) Write-Host $CreateorInfo.value.name Write-Host $CreateorInfo.value.creator.displayName } 7Another option (easier with the Auth part) is to retrieve your Azure Repositories is through the AZ CLI using following commands:
Log into Azure
az login -t $tenantFirst configure default values for organization and project, this will help you to not specify
--projectand--organizationparameters in every az devops/repos command:az devops configure -d organization=$organizationUrl project=$projectList repositories of your subscription and default project and organization
az repos list --subscription $subscription