Azure / Azure/azure-devops-cli-extension

Error on mass fetching az repos ref list

Aperta
#1,355 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
682
Fork
278
Merge medio
3g 23h
PR unite (30g)
3

Descrizione

### **This is autogenerated. Please review and update as needed.**

## Describe the bug
(See the additional content for my script) which uses the Azure CLI

I have a custom script which I use to fetch all branches for all my repositories under my project. The end goal would be to see what branches haven't been commited to in the last 120 days so we can mark them for deletion as part of our internal policy.

For that I wrote a custom script which fetches all repositories under a project and then fetches each branch for a repository but the Azure CLI doesn't really seem to like this. approach

**Command Name**
`az devops invoke
Extension Name: azure-devops. Version: 0.26.0.`

**Errors:**
```
The command failed with an unexpected error. Here is the traceback:
'defaultBranch=refs/heads/main; id=6b9be419-daf8-480a-aee6-01d369a64384; isDisabled=False; isFork=; isInMaintenance=False; name=tres-internet-terraform; parentRepository=; project=; remoteUrl=https'
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 718, in _run_job
File "C:\Users\JeroenSmink\.azure\cliextensions\azure-devops\azext_devops\dev\common\exception_handler.py", line 31, in azure_devops_exception_handler
reraise(*sys.exc_info())
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\six.py", line 703, in reraise
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "C:\Users\JeroenSmink\.azure\cliextensions\azure-devops\azext_devops\dev\team\invoke.py", line 101, in invoke
response = client._send(http_method=http_method,
File "C:\Users\JeroenSmink\.azure\cliextensions\azure-devops\azext_devops\devops_sdk\client.py", line 60, in _send
request = self._create_request_message(http_method=http_method,
File "C:\Users\JeroenSmink\.azure\cliextensions\azure-devops\azext_devops\devops_sdk\client.py", line 117, in _create_request_message
request = ClientRequest(method=http_method, url=self._client.format_url(url))
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/service_client.py", line 151, in format_url
KeyError: 'defaultBranch=refs/heads/main; id=6b9be419-daf8-480a-aee6-01d369a64384; isDisabled=False; isFork=; isInMaintenance=False; name=tres-internet-terraform; parentRepository=; project=; remoteUrl=https'

```

## To Reproduce:
Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

- _Put any pre-requisite steps here..._
- `az devops invoke --area {} --resource {} --route-parameters {} {} {}`

## Expected Behavior

## Environment Summary
```
Windows-10-10.0.22621-SP0
Python 3.10.5
Installer: MSI

azure-cli 2.40.0 *

Extensions:
azure-devops 0.26.0

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1
```
## Additional Context

This is my powershell script

```ps1
$project = "SOME_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
} catch {
Write-Host "Failed to fetch refs for repository $($repo.name)"
continue
}

foreach($ref in $refs) {
$objectId = $ref.objectId

# 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
}
# add a 500ms wait
Start-Sleep -Milliseconds 500
}

$results | Sort-Object -Property lastModified -Descending | Format-Table -AutoSize

# Write to CSV
$results | Sort-Object -Property lastModified -Descending | Export-Csv -Path "output.csv" -NoTypeInformation
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalle posizioni del traceback in azext_devops/dev/team/invoke.py e devops_sdk/client.py, quindi esegui il ciclo PowerShell fornito e il comando az devops invoke con un repository rappresentativo. Conferma come vengono analizzati i parametri della route e riproduci il KeyError; il lavoro è completato quando la richiesta di commit termina e restituisce JSON senza questa eccezione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
azure, git, powershell, python
Ambito
ci-cd, cli, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.