To teach the assistant about all the repositories and wikis in your Azure AD organization, you can utilize the Azure DevOps REST API to fetch the necessary details. Below is a PowerShell script that retrieves information about all repositories and wikis in your Azure DevOps organization. It assumes you have an Azure DevOps personal access token (PAT) for authentication.
Prerequisites
Azure DevOps Personal Access Token (PAT): You need a PAT with at least Read permissions for Repositories and Wikis.
Organization URL: Your Azure DevOps organization URL, e.g., https://dev.azure.com/YourOrganization.
PowerShell Script
powershell
# Variables
$organization = "YourOrganization" # Replace with your Azure DevOps organization name
$pat = "YourPersonalAccessToken" # Replace with your Azure DevOps Personal Access Token
$baseURL = "https://dev.azure.com/$organization"
# Encode the PAT for Basic Auth
$authHeader = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
}
# Fetch all projects in the organization
Write-Output "Fetching all projects in the organization..."
$projectsURL = "$baseURL/_apis/projects?api-version=7.0"
$projectsResponse = Invoke-RestMethod -Uri $projectsURL -Headers $authHeader -Method Get
$projects = $projectsResponse.value
if (-not $projects) {
Write-Output "No projects found in the organization."
return
}
# Fetch repositories and wikis for each project
foreach ($project in $projects) {
$projectName = $project.name
Write-Output "Processing project: $projectName"
# Fetch repositories in the project
Write-Output " Fetching repositories..."
$reposURL = "$baseURL/$projectName/_apis/git/repositories?api-version=7.0"
$reposResponse = Invoke-RestMethod -Uri $reposURL -Headers $authHeader -Method Get
$repositories = $reposResponse.value
foreach ($repo in $repositories) {
Write-Output " Repository: $($repo.name)"
Write-Output " ID: $($repo.id)"
Write-Output " Default Branch: $($repo.defaultBranch)"
Write-Output " URL: $($repo.webUrl)"
}
# Fetch wikis in the project
Write-Output " Fetching wikis..."
$wikisURL = "$baseURL/$projectName/_apis/wiki/wikis?api-version=7.0"
$wikisResponse = Invoke-RestMethod -Uri $wikisURL -Headers $authHeader -Method Get
$wikis = $wikisResponse.value
foreach ($wiki in $wikis) {
Write-Output " Wiki: $($wiki.name)"
Write-Output " ID: $($wiki.id)"
Write-Output " Type: $($wiki.type)"
Write-Output " Mapped Path: $($wiki.mappedPath)"
Write-Output " URL: $($wiki.url)"
}
}
Write-Output "Done!"
How It Works
Authentication: The script uses a PAT to authenticate with the Azure DevOps REST API.
Fetch Projects: It starts by retrieving all projects in the specified Azure DevOps organization.
Fetch Repositories: For each project, it retrieves all Git repositories using the repositories API.
Fetch Wikis: For each project, it retrieves all wikis using the wikis API.
Output: It outputs the details of each repository and wiki in the console.
REST API Version: The script uses api-version=7.0. Update it if a newer version is available and required.
Permissions: Ensure your PAT has sufficient permissions to access repositories and wikis.
Error Handling: You can add error handling to manage API failures or missing data gracefully.
This script gives a comprehensive overview of available repositories and wikis in your Azure DevOps organization. You can further modify it to save the output to a file or integrate it with other tools like aider.