简体   繁体   中英

How to get Azure devops git repo folder name where user committed changes using powershell (Azure devops REST API)

I am working on script where I want to find out name of folder where user committed changes

$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"    

This is returning (It does return recent commit ID, Object ID but in path it returns only /)

path=/;

Also with

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

It returns -

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

Que - Am I using wrong API call? How can I get Folder name, Committer name?

Thanks

You use request without any filters. Try to add additional filters:

  1. To search for items, you can add:

  2. To search for commits, you can add

We can get the commit Folder name via commit ID

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

Result:

在此处输入图像描述

And get the committer name via below API

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

Result:

在此处输入图像描述

Update1

get the committer name

I used postman to track these results, and I also tried powershell script, please check it.

$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)"

Result:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM