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

时间:2017-10-19 10:47:15

标签: azure-devops tfvc

我想下载已提交给我的所有文件(超过100个)以进行代码审查。

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

1 个答案:

答案 0 :(得分:0)

您可以通过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"
相关问题