如何下载所有VSTS代码审查/搁置文件

问题描述:

我想下载所有提交给我的代码审查文件(超过100个)。如何下载所有VSTS代码审查/搁置文件

我知道我可以下载单个文件,但这会慢。我可以只下载代码评论的shelveset中的所有文件吗?我们使用VS2015和VS版本控制(不是GIT)。

您可以通过编程方式通过VSTS Rest API下载文件:Get shelveset changesGet a file

简单的样品做的PowerShell通过:

function DownloadShelvesetFiles{ 
param(
[string]$shelveUrl 
) 
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 'test','[personal access token]'))) 
$shelveChanges = Invoke-RestMethod -Method GET -Uri $shelveUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} 
foreach($c in $shelveChanges.value){ 
$filepath=$c.item.path -replace "\$","D:/shelveFiles" 
$folderPath=$filepath.subString(0,$filePath.LastIndexof("/")) 
if(!(Test-Path -PathType Container $folderPath)){ 
    new-item -ItemType Directory -force $folderPath 
} 
    Invoke-RestMethod -Method GET -Uri $c.item.url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | Out-File -filepath $filepath 
} 
} 

DownloadShelvesetFiles -shelveUrl "https://XXX.visualstudio.com/DefaultCollection/_apis/tfvc/shelvesets/CodeReview_2017-10-20_10.00.50.5978;af97843e-4341-49f4-a11d-283a7ba6da57/changes?maxChangeCount=100&api-version=1.0-preview.1" 
+0

喜@ starain-MSFT谢谢你的样品。看起来像我需要的东西。但是我不确定如何去认证?我们已经整合了基于Azure AD运行的单一标志。 – Karl

+0

@Karl您可以使用[个人访问令牌](https://docs.microsoft.com/en-us/vsts/accounts/use-personal-access-tokens-to-authenticate)。 (将[个人访问令牌]替换为您的令牌) –

+0

@Karl使用个人访问令牌尝试后会出现什么结果? –