【问题标题】:Azure Devops API: get latest action on the repositoryAzure Devops API:获取存储库的最新操作
【发布时间】:2022-08-19 16:46:38
【问题描述】:

我正在使用 Azure Devops Rest API,并试图找出在特定存储库上获取最新操作时间戳(日期)的最佳方法。

现在我正在尝试获取提交和标签并检查那里的操作数据。但是我看到 azure 不支持仅获取最新的,所以我必须对所有标签进行分页,例如。

我正在使用这些端点:

所有这些处理在内存方面都非常繁重,所以我需要一些不同的东西。

可能有人可以提出一个如何完成的想法。

谢谢

    标签: azure azure-devops git-commit git-tag


    【解决方案1】:

    您可以尝试在调用 REST API 时指定searchCriteria

    例如,要从特定存储库获取最新提交,请参阅Commits - Get Commits 了解详细信息。

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?searchCriteria.$top={searchCriteria.$top}&api-version=6.0
    

    以下 PowerShell 供您参考:

    Param(
    [string]$orgurl = “https://dev.azure.com/{organization}",
    [string]$project = “Test0924”,
    [string]$repoid = “e7ad43eb-ecad-4098-93b4-b63fdf88711a”,
    [string]$user = “”,
    [string]$token = “xxx”
    )
    
    # Base64-encodes the Personal Access Token (PAT) appropriately
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
    
    $searchCriteria = "$" + "top=1"
    
    #Get the latest commit from a specific repo 
    $Url = "$orgurl/$project/_apis/git/repositories/$repoid/commits?searchCriteria.$searchCriteria&api-version=6.0" 
        
    $commit = Invoke-RestMethod -Uri $Url -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
    cls
    $commit.value.committer | select name, email, date
    

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 2021-12-10
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多