我正在使用 Azure Devops Rest API,我正在尝试找出在特定存储库上获取最新操作时间戳(日期)的最佳方法。
现在我正在尝试获取提交和标签并检查那里的操作数据。但我发现 azure 不支持仅获取最新的,因此我必须对所有标签进行分页。
我正在使用这些端点:
所有这些处理在内存方面都非常繁重,所以我需要一些不同的东西。
也许有人可以提出如何做到这一点的想法。
谢谢
您可以尝试在调用REST API时指定
searchCriteria
。
例如,要从特定存储库获取最新提交,请参阅提交 - 获取提交了解详细信息。
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