0

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

Amruta
  • 1,128
  • 1
  • 9
  • 19
megha
  • 621
  • 2
  • 11
  • 36

2 Answers2

0

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

Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
0

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:

enter image description here

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:

enter image description here

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:

enter image description here

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • Hi @vito Where are you tracking these results? I tried deploying PS scripts locally and it gives me all blank values with adding commit ID as well. – megha Aug 19 '20 at 14:47
  • Hi @megha I have updated the answer and add the powershell script, please check it. – Vito Liu Aug 20 '20 at 02:26