如何使用 powershell 获取用户提交更改的 Azure devops git repo 文件夹名称(Azure devops REST API)
How to get Azure devops git repo folder name where user committed changes using powershell (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"
这是 returning(它 return 最近的提交 ID,对象 ID 但在路径中它仅 returns /)
path=/;
还有
$uriAccount = $UriOrga + "{Project Name}/_apis/git/repositories/{REPO ID}/commits?api-version=6.0-preview.1"
它returns -
author=; committer=; (Nothing for these values just blank)
Que - 我使用了错误的 API 电话吗?如何获取文件夹名称、提交者名称?
谢谢
您使用没有任何过滤器的请求。尝试添加额外的过滤器:
要搜索项目,您可以添加:
要搜索提交,您可以添加
我们可以通过commit ID获取commit文件夹名称
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)"
结果:
我正在编写脚本,我想找出用户提交更改的文件夹的名称
$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"
这是 returning(它 return 最近的提交 ID,对象 ID 但在路径中它仅 returns /)
path=/;
还有
$uriAccount = $UriOrga + "{Project Name}/_apis/git/repositories/{REPO ID}/commits?api-version=6.0-preview.1"
它returns -
author=; committer=; (Nothing for these values just blank)
Que - 我使用了错误的 API 电话吗?如何获取文件夹名称、提交者名称?
谢谢
您使用没有任何过滤器的请求。尝试添加额外的过滤器:
要搜索项目,您可以添加:
要搜索提交,您可以添加
我们可以通过commit ID获取commit文件夹名称
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)"
结果: