在 Azure Devops Repos 中查找按评论过滤的提交

问题描述 投票:0回答:2

众所周知,存储库中的每个提交都有一条注释:

Azure Repos 中有没有办法找到按评论过滤的所有提交?例如:

查找所有带有包含关键字“sonar”的评论的提交

azure-devops commit azureportal azure-repos
2个回答
1
投票

该功能目前在 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 "-----------------------------------------------------------------------------"

    }
}

0
投票

不,它在 Azure DevOps 中不可用。您可以使用 Visual Studio Git 历史记录搜索。您的案例有一个功能请求:搜索/过滤提交消息

© www.soinside.com 2019 - 2024. All rights reserved.