如何使用Powershell获取用户提交更改的Azure devops git repo文件夹名称Azure devops REST API

问题描述

我正在研究要查找用户提交更改的文件夹名称的脚本

$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,但在路径中仅返回/)

path = /;

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

它返回-

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

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

谢谢

解决方法

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

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

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

,

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

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

结果:

enter image description here

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

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

结果:

enter image description here

更新1

获取提交者名称

我用邮递员来跟踪这些结果,并且我也尝试过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)"

结果:

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...