2017-10-19 37 views
0

我想下載所有提交給我的代碼審查文件(超過100個)。如何下載所有VSTS代碼審查/擱置文件

我知道我可以下載單個文件,但這會慢。我可以只下載代碼評論的shelveset中的所有文件嗎?我們使用VS2015和VS版本控制(不是GIT)。

回答

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" 
+0

喜@ starain-MSFT謝謝你的樣品。看起來像我需要的東西。但是我不確定如何去認證?我們已經整合了基於Azure AD運行的單一標誌。 – Karl

+0

@Karl您可以使用[個人訪問令牌](https://docs.microsoft.com/en-us/vsts/accounts/use-personal-access-tokens-to-authenticate)。 (將[個人訪問令牌]替換爲您的令牌) –

+0

@Karl使用個人訪問令牌嘗試後會出現什麼結果? –