【问题标题】:Capture commit count per pull request in Azure DevOps在 Azure DevOps 中捕获每个拉取请求的提交计数
【发布时间】:2020-06-19 03:16:51
【问题描述】:

我想获取有关每个拉取请求的提交次数的信息。目前,半自动化就可以了。只是在寻找一种简单的方法,例如 PowerShell 脚本。将来我可能需要使用不同的数据创建类似类型的报告。

是否有任何方法适合这种快速而肮脏的 Azure DevOps 数据方法?

【问题讨论】:

    标签: azure-devops azure-devops-rest-api


    【解决方案1】:

    为此有一个特殊的 Rest API:Pull Request Commits - Get Pull Request Commits:

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits?api-version=5.1
    

    所以,简单的 PowerShell 脚本:

    $pat = "YOUR-PERSONAL-ACCESS-TOKEN"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,"$pat")))
    $headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
    
    $url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits?api-version=5.1"
    
    $commitsCount = (Invoke-RestMethod -Method Get -Uri $url -Headers $headers -Body $jsonBody -ContentType 'application/json').count
    

    【讨论】:

    • 哇!这比我尝试过的任何方法都简单!
    猜你喜欢
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 2021-02-14
    相关资源
    最近更新 更多