Public/Get-AzureDevOpsCommitDetails.ps1
|
Function Get-AzureDevOpsCommitDetails{ [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [string] $APIver = "7.0" ) Begin{ #Define functions and veriables Write-Verbose "Initializing variables" $BaseURl = "$($Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$Env:SYSTEM_TEAMPROJECTID" $commitId = $Env:BUILD_SOURCEVERSION $RepositoryName= $($Env:BUILD_REPOSITORY_NAME) Write-Verbose "Base URL is - $BaseUrl" Write-Verbose "Commit ID is $commitId" Write-Verbose "Repository Name is - $RepositoryName" $CommitChangeURL = "$BaseURL/_apis/git/repositories/$RepositoryName/commits/$commitId/changes?api-version=$APIver" Write-verbose "Commit change url is - $CommitChangeURL" $CommitChangeData = @() #Function defenitions } Process{ try { Write-Verbose "Invoke-RestMethod, getting the change details from commit change API" $Commitchanges = Invoke-RestMethod -Uri $CommitChangeURL -Method Get -Headers @{Authorization="Bearer $Env:SYSTEM_ACCESSTOKEN"} -ErrorAction Stop Foreach($ChangeDetail in $Commitchanges.changes){ $CommitChangeData += [PSCustomObject]@{ FileName = $($ChangeDetail.item.path -replace "/","\" ) ChangeType = $ChangeDetail.changeType isFolder = If($ChangeDetail.item.isFolder){$true}else{$false} } } Return $CommitChangeData } catch { Write-Verbose "An error occured while Invoke-RestMethod, getting the change details from commit change API" Write-Error $($_.Exception.Message) } } End{ Write-Verbose "Invoke Get-AzureDevOpsCommitChangeDetails completed" } } |