【问题标题】:How to get Azure devops git repo folder name where user committed changes using powershell (Azure devops REST API)如何获取用户使用 powershell 提交更改的 Azure devops git repo 文件夹名称(Azure devops REST API)
【发布时间】:2020-12-08 06:44:38
【问题描述】:

我正在编写脚本,我想找出用户提交更改的文件夹名称

$AzureDevOpsPAT = ""
 
$OrganizationName = ""

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$UriOrga = "https://dev.azure.com/$($OrganizationName)/"

$uriAccount = $UriOrga + "{Project Name}/_apis/git/repositories/{RepositoryID}/items?api-version=6.0-preview.1"

Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json"    

这正在返回(它确实返回最近的提交 ID、对象 ID 但在路径中它只返回 /)

路径=/;

还有

$uriAccount = $UriOrga + "{Project Name}/_apis/git/repositories/{REPO ID}/commits?api-version=6.0-preview.1"

它返回 -

 author=; committer=; (Nothing for these values just blank)

Que - 我是否使用了错误的 API 调用?如何获取文件夹名称、提交者名称?

谢谢

【问题讨论】:

    标签: powershell azure-devops azure-powershell azure-devops-rest-api azure-repos


    【解决方案1】:

    我们可以通过提交ID获取提交文件夹名称

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=6.0-preview.1
    

    结果:

    并通过以下 API 获取提交者名称

    Get https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=6.0-preview.1 
    

    结果:

    更新1

    获取提交者名称

    我用postman跟踪这些结果,我也试过powershell脚本,请检查一下。

    $url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=6.0-preview.1"
    $connectionToken="PAT"
    $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
    $CommitInfo = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
    Write-Host "CommitInfo = $($CommitInfo | ConvertTo-Json -Depth 100)"
    

    结果:

    【讨论】:

    • 嗨@vito 你在哪里跟踪这些结果?我尝试在本地部署 PS 脚本,它还为我提供了所有空白值并添加了提交 ID。
    • 嗨@megha我已经更新了答案并添加了powershell脚本,请检查一下。
    【解决方案2】:

    您使用没有任何过滤器的请求。尝试添加额外的过滤器:

    1. 要搜索项目,您可以添加:

    2. 要搜索提交,可以添加

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多