我正在使用 Azure Devops Rest API,并且正在尝试找出在特定存储库上获取最新操作时间戳(日期)的最佳方法。
现在我正在尝试获取提交和标签并检查那里的操作数据。但我发现 azure 不支持仅获取最新的,因此我必须对所有标签进行分页。
我正在使用这些端点:
- https://learn.microsoft.com/en-us/rest/api/azure/devops/git/refs/list?view=azure-devops-rest-6.0&tabs=HTTP
- https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get-commits?view=azure-devops-rest-6.0&tabs=HTTP
所有这些处理在内存方面都非常繁重,所以我需要一些不同的东西。
也许有人可以提出如何完成的想法。
谢谢
最佳答案
您可以尝试在调用 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
关于Azure DevOps API : get latest action on the repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73386140/