该功能目前在 Azure DevOps 网页中不可用。
以下是一个 PowerShell 脚本,它使用 Azure DevOps REST API 来查找包含您需要的关键字的注释。我过滤了前 1000 条记录。您也可以参考这里的示例来过滤您需要的记录。
$Orgname = "Orgname"
$projectname="projectname"
$reponame="reponame"
$keyword="sonar"
$PAT = "xxxxx"
$PATGetBytes = [System.Text.Encoding]::ASCII.GetBytes(":$PAT")
$Authentication = [System.Convert]::ToBase64String($PATGetBytes)
$Headers = @{Authorization = ("Basic {0}" -f $Authentication) }
$commits = Invoke-RestMethod "https://dev.azure.com/$Orgname/$projectname/_apis/git/repositories/$reponame/commits?`$top=1000&api-version=6.0" -Method 'GET' -Headers $Headers -ContentType 'application/json'
foreach($commit in $commits.value)
{
if ($commit.comment -match $keyword)
{
Write-Output "$($commit.commitId) $($commit.remoteUrl) $($commit.comment)"
}
}
我的测试结果:
这是交叉搜索给定组织的所有项目和存储库的示例。它还过滤了每个存储库的前 1000 条记录。
$organization = "xxxx"
$PAT = "xxxx"
$keyword="sonar"
$PATGetBytes = [System.Text.Encoding]::ASCII.GetBytes(":$PAT")
$Authentication = [System.Convert]::ToBase64String($PATGetBytes)
$Headers = @{Authorization = ("Basic {0}" -f $Authentication) }
# get all projects of the organization
$uri = "https://dev.azure.com/$($organization)/_apis/projects?api-version=6.0"
$projects = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $Headers -ContentType 'application/json'
foreach($project in $projects.value)
{
# get all repos of the project
$uri = "https://dev.azure.com/$($organization)/$($project.id)/_apis/git/repositories?api-version=6.0"
$repos = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $Headers -ContentType 'application/json'
foreach($repo in $repos.value)
{
Write-Output "Project: $($project.name), Repo: $($repo.name)"
# get the commits of the repo
$uri = "https://dev.azure.com/$($organization)/$($project.id)/_apis/git/repositories/$($repo.id)/commits?`$top=1000&api-version=6.0"
$commits = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $Headers -ContentType 'application/json'
foreach($commit in $commits.value)
{
if ($commit.comment -match $keyword)
{
Write-Output "Commit: $($commit.commitId), url: $($commit.remoteUrl), comment: $($commit.comment)"
}
}
Write-Output "-----------------------------------------------------------------------------"
}
}
不,它在 Azure DevOps 中不可用。您可以使用 Visual Studio Git 历史记录搜索。您的案例有一个功能请求:搜索/过滤提交消息