获取自上次标签提交以来的所有主分支提交,通过 Azure DevOps REST API。

huangapple go评论50阅读模式
英文:

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"

huangapple
  • 本文由 发表于 2023年2月16日 04:54:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定