Reputation: 2713
I'm trying to use Azure DevOps REST API version 7 to get all commit since the last tag in a master branch. Using the Get Commit end point and through PowerShell I only able to retrieve all commits between two dates (see my PS script).
Ideally, I want to run a script which detects the name of the latest tag in the branch and then use that value as input to get all the branch commit since that tag value added.
If there isn't any out-of-box solution with Azure REST API, perhaps there is certain git command that at least gives me the commit date of the associated tag and plug that into the script below?
$AzureDevOpsPAT = "PAT value"
$OrganizationName = "OrgName"
$GitProject = "ProjectName"
$RepositoryId = "02cu3246-0000-4863-9d19-5d1ajs5e6979"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$UriOrga = "https://dev.azure.com/$($OrganizationName)/$($GitProject)/"
$uriAccount = $UriOrga + "_apis/git/repositories/$($RepositoryId)/commits?&api-version=7.0"
$Body = @{
"searchCriteria.includeWorkItems" = "true"
"searchCriteria.itemVersion.version" = "master"
"searchCriteria.fromDate" = "2/8/2023 12:00:00 AM"
"searchCriteria.toDate" = "2/14/2023 12:00:00 AM"
}
$Params = @{
Method = "Get"
Uri = $uriAccount
Headers = $AzureDevOpsAuthenicationHeader
Body = $Body
}
$response = Invoke-RestMethod @Params
$CommitIDsInfo = $response.value | Where-Object{$_.workitems -ne ""} | select comment, commitid, workitems
$WorkItems = $CommitIDsInfo | ConvertTo-Json -Depth 100
Write-Host $WorkItems
Upvotes: 2
Views: 1347
Reputation: 16133
You have to add search criteria to your $uriAccount:
$uriAccount = $UriOrga + "_apis/git/repositories/$($RepositoryId)/commits?searchCriteria.compareVersion.versionType=branch&searchCriteria.compareVersion.version=master&searchCriteria.itemVersion.versionType=tag&searchCriteria.itemVersion.version=YOUR_TAG_NAME&api-version=7.0"
Upvotes: 3