【问题标题】:How to see commits by user accross multiple repositories in Azure DevOps?如何在 Azure DevOps 中查看用户跨多个存储库的提交?
【发布时间】:2021-03-29 07:33:52
【问题描述】:

我想在 Azure DevOps 中查看我组织中所有存储库的用户提交。我看不到此类可用选项。

我可以在 Azure DevOps 中看到以下选项,但它在单个存储库中显示提交。

我知道我们可以使用下面的 git 命令来查看单个存储库中的提交。

git log --author<AuthorName> --all ( or --branches)

【问题讨论】:

  • 嗨,这个问题怎么样?下面的答案是否解决了您的问题?如果没有,请告诉我有关此问题的最新信息吗?
  • @VitoLiu-MSFT 抱歉,我无法处理此项目,我今天将验证并更新您
  • 您好,您可以尝试并在此处分享结果。如果您有任何后续问题,您也可以在这里分享,我仍然会在这里为您提供帮助。祝你今天过得愉快。 :)

标签: git azure-devops git-log


【解决方案1】:

查看此 REST API 示例By author,它包含提交的作者,我们可以输入别名或显示作者的姓名以列出所有提交信息。

另外,我们可以将searchCriteria.itemVersion.version字段添加到过滤器分支中。

GET https://dev.azure.com/{Org name}/{project name}/_apis/git/repositories/{repo name}/commits?searchCriteria.author={searchCriteria.author}&searchCriteria.itemVersion.version={branch name}&api-version=6.0

我想在 Azure DevOps 中查看我组织中所有存储库的用户提交

一个。通过组织名称列出所有项目并获取项目名称。

GET https://dev.azure.com/{organization}/_apis/projects?api-version=6.0

b.通过组织名称和项目名称列出所有 repo 并获取 repo 名称。

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0

c。通过组织名称、项目名称和仓库名称列出所有分支,然后获取分支名称

GET https://dev.azure.com/{Org name}/{project name}/_apis/git/repositories/{repo name}/refs?filter=heads&api-version=6.1-preview.1

d。通过别名或作者的显示名称列出提交信息

GET https://dev.azure.com/{Org name}/{project name}/_apis/git/repositories/{repo name}/commits?searchCriteria.author={searchCriteria.author}&searchCriteria.itemVersion.version={branch name}&api-version=6.0

Power shell 脚本:

cls

#List all projects via org name
$ListAllProjectsURL="https://dev.azure.com/{org name}/_apis/projects?api-version=6.0"
$PAT="{pat}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

#get the project name
$ListAllProjects = Invoke-RestMethod -Uri $ListAllProjectsURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

ForEach ($ProjectName in $ListAllProjects.value.name){
    #Write-Host $ProjectName
    #List all repos via org name and project name and get the repo name.
    $ListAllRepoURL = "https://dev.azure.com/{org name}/$($ProjectName)/_apis/git/repositories?api-version=6.0"
    $ListAllRepo = Invoke-RestMethod -Uri $ListAllRepoURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

    ForEach ($RepoName in $ListAllRepo.value.name){
        #Write-Host $RepoName
        $ListAllBranchURL ="https://dev.azure.com/{org name}/$($ProjectName)/_apis/git/repositories/$($RepoName)/refs?filter=heads&api-version=6.1-preview.1"                          
        $ListBranchName = Invoke-RestMethod -Uri $ListAllBranchURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
        #get branch name
        foreach($Branch in $ListBranchName.value){
            $BranchName = $Branch.name.split("/",3)[-1]
            #write-host $BranchName

            #List the commits by a user across all repositories in one organization in Azure DevOps
            $ListCommitInfoViaUserURL = "https://dev.azure.com/{org name}/$($ProjectName)/_apis/git/repositories/$($RepoName)/commits?searchCriteria.author={User display name}&searchCriteria.itemVersion.version=$($BranchName)&api-version=6.0"
            $ListCommitInfo = Invoke-RestMethod -Uri $ListCommitInfoViaUserURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

            if($ListCommitInfo.count -eq 0){

            }else{
                Write-Host "Project name is:"$ProjectName "    repo name is:" $RepoName    "branch name is:" $BranchName    "and commit ID is:" $ListCommitInfo.value.commitId 
            }
        }
    }
}

结果:

【讨论】:

  • 谢谢,我试过 API 看起来不错。但我从未在 Powershell 上工作过,所以我请求您将其转换为 C# 代码,或者让我知道我该怎么做?
  • 我找到了this sample,它获取了一个 Azure DevOps Services 组织中的团队项目列表,您可以参考它来将 power shell 脚本转换为 C# 代码。
  • 什么是 PAT?认证机制?如果是这样,我该如何生成它?它是我需要在我的帐户下在 Azure DevOps 上生成的令牌吗?
猜你喜欢
  • 2021-10-09
  • 2021-10-29
  • 1970-01-01
  • 2022-10-24
  • 2022-11-15
  • 1970-01-01
  • 2021-10-24
  • 2021-11-05
  • 1970-01-01
相关资源
最近更新 更多