如何使用 rest API 从多个变更集中获取文件列表

How to get list of files form multiple changesets using rest API

我尝试使用 TFS rest API 获取文件列表以形成多个变更集。我能够使用以下 URL:

成功获取单个变更集的文件列表
https://company.visualstudio.com/DefaultCollection/_apis/tfvc/changesets/"{ChangesetsetID}/changes?api-version=4.1"

如何获取文件列表以形成多个变更集? 我是用JavascriptAjax获取和展示的

一般对于在源代码管理中添加的文件,您可以根据您的 requirement/debug 等更改它们,然后使用变更集签入。这意味着,几乎所有文件都属于多个变更集...

所以,在我看来,获取属于多个变更集的文件列表没有意义。相反,获取属于单个变更集的文件更有意义...

无论如何,您可以使用以下 REST API:

获取包含对指定 item/file 的更改的变更集
GET https://SERVER:8080/TFS/{CollectionName}/_apis/tfvc/changesets?searchCriteria.itemPath=$/Fabrikam-Fiber-TFVC/AuthSample/AuthSample/Program.cs&api-version=3.2

您可以获取文件名并在循环中调用 REST API 来检查每个文件,如果响应值的计数大于 1,则该文件应该是那个你想被找回...

PowerShell 示例供您参考:(更改正文中的 path,例如,在下面的示例中,我检查了路径下的文件:$/ScrumProject/ConsoleApplication1/ConsoleApplication1

Param(
   [string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
   [string]$user = "domain\name",
   [string]$token = "password",
   [string]$exportpath = "D:\temp"

)
$filename = (Get-Date).ToString("yyyyMMdd-HHmmss") + "-" + "FileList.csv"

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#Get path of the files from a sepcific folder 
$fileurl = "$collectionurl/_apis/tfvc/itemBatch?api-version=3.2"

$body = '{"includeContentMetadata":true,"includeLinks":null,"itemDescriptors":[{"path":"$/ScrumProject/ConsoleApplication1/ConsoleApplication1","versionType":5,"recursionLevel":4}]}'

$pathresponse = Invoke-RestMethod -Uri $fileurl -Method POST -Body $body -ContentType "application/json"-Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$paths = $pathresponse.value.path

Clear-Host
#Get changesets that contain changes to the specified item/file
foreach ($path in $paths )
{
$baseUrl = "$collectionurl/_apis/tfvc/changesets?searchCriteria.itemPath=$path&api-version=3.2" 
$changesetResponse = Invoke-RestMethod -Uri $baseUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$count = $changesetResponse.count

#Displsy and export the matching files to a *.csv file

 if ($count -gt 1)
 {
  Write-host $path
  $path | Add-Content $exportpath$filename
 }
}