Querying A Specific Git Branch in TFS 2015 with Rest API v2.0 (Powershell)

  • Thread starter Thread starter HDOlsen
  • Start date Start date
H

HDOlsen

Guest
I have a list of git repositories in TFS 2015 that I have accessed with the TFS Rest API v. 2.0 in Powershell. I would like only to return the most recent release branch for each repository, and these do not match the value of the 'defaultBranch' property. I have tried setting the value of the 'versionDescriptor.version' uri parameter to a regular expression that matches this branch, but the items still return 'defaultBranch.' Our release branches take the generic pattern, "releases/x.x.xx," so my regex would need to find the highest digit for each 'x.' Can this parameter accept such an expression? (The below variable $branchName is the regex I created.)

[hashtable] $repoResponse
$teamProject = @{}

$tfsUrl = 'http://tfs.infosys.com:8080/tfs/'
$collectionName = 'BCSA'
$collectionUrl = "$($tfsUrl)$($collectionName)"
$getProjectsUrl = "$($collectionUrl)/BHBs/_apis/git/repositories/?api-version=2.0"
$getItemsURL = "$($collectionUrl)/BHBs/_apis/git/repositories/"
[datetime]$dateTime = Get-Date -Format u
$refDate = $dateTime.AddYears(-2)
[regex]$branchName = "^releases/d[3].\d[0-9].\d[0-9]$"

$response = Invoke-RestMethod -UseDefaultCredentials -uri $getProjectsUrl

foreach ($repository in $response.value)
{
$itemsURI = "$($getItemsURL)$($repository.id)" + "/items? recursionLevel=full&versionDescriptor.versionType=branch&versionDescriptor.version=$branchName&latestProcessedChange=true&includeContent=true&api-version=2.0"
$repoResponse = Invoke-RestMethod -UseDefaultCredentials -uri $itemsURI
$repoResponse = $repoResponse.value | Where-Object {$_.gitObjectType -eq "blob" -and [datetime]$_.latestProcessedChange.author.date -gt $refDate} |
Select-Object -Property Path, latestProcessedChange
}

Continue reading...
 
Back
Top