英文:
Get all master branch commit's since the last commit with tag via Azure DevOps REST API
问题
我试图使用Azure DevOps REST API版本7来获取主分支上自上次标签以来的所有提交。使用获取提交端点,并通过PowerShell,我只能检索两个日期之间的所有提交(请参见我的PS脚本)。
理想情况下,我想运行一个脚本,它会检测分支中最新标签的名称,然后将该值用作输入以获取自添加该标签值以来的所有分支提交。
如果Azure REST API没有现成的解决方案,也许有某种git命令可以至少给我提供相关标签的提交日期,并将其插入到下面的脚本中?
$AzureDevOpsPAT = "PAT值"
$OrganizationName = "组织名称"
$GitProject = "项目名称"
$RepositoryId = "存储库ID"
$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" = "2023-02-08T00:00:00Z"
"searchCriteria.toDate" = "2023-02-14T00:00:00Z"
}
$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
英文:
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
答案1
得分: 1
你需要向你的$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"
英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论