[英]Azure Devops API: get latest action on the repository
我正在使用 Azure Devops Rest API 並且我正在嘗試找出在特定存儲庫上獲取最新操作時間戳(日期)的最佳方法。
現在我正在嘗試獲取提交和標簽並檢查那里的操作數據。 但我看到 azure 不支持僅獲取最新的,所以我必須對所有標簽進行分頁,例如。
我正在使用這些端點:
所有這些處理在內存方面都非常繁重,所以我需要一些不同的東西。
可能有人可以提出一個如何完成的想法。
謝謝
您可以嘗試在調用 REST searchCriteria
時指定 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.