Created
June 21, 2020 16:39
-
-
Save smaglio81/3cf3986ff2ca5f64e7b31605c13fbf96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-AzDServiceHook { | |
[CmdletBinding(DefaultParameterSetName = "ProjectName")] | |
param( | |
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)] | |
[string] $ProjectName = $null, | |
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)] | |
[string] $ProjectId = $null, | |
[Parameter(ValueFromPipelineByPropertyName = $true)] | |
[ValidateSet("git.push","git.pullrequest.created","git.pullrequest.updated","build.complete")] | |
[string] $EventType = $null, | |
[Parameter(ValueFromPipelineByPropertyName = $true)] | |
[string] $ToUrl = $null, | |
[Parameter(ValueFromPipelineByPropertyName = $true)] | |
[switch] $Exact | |
) | |
$shpClient = $global:AzDModule.ServiceHooksPublisherClient | |
$inputFilters = New-Object 'System.Collections.Generic.List[Microsoft.VisualStudio.Services.FormInput.InputFilter]' | |
$response = $shpClient.QuerySubscriptionsAsync("tfs", $inputFilters, $null) | |
if($null -ne $response.Exception) { | |
if($null -ne $response.Exception.InnerException) { | |
throw $response.Exception.InnerException.Message | |
} else { | |
throw $response.Exception.Message | |
} | |
} | |
$serviceHooks = $response.Result | |
if(-not [string]::IsNullOrWhitespace($EventType)) { | |
$serviceHooks = $serviceHooks |? { $_.EventType -eq $EventType } | |
} | |
if(-not [string]::IsNullOrWhitespace($ToUrl)) { | |
if(-not $Exact) { | |
if(-not $ToUrl.StartsWith("*")) { $ToUrl = "*" + $ToUrl } | |
if(-not $ToUrl.EndsWith("*")) { $ToUrl = $ToUrl + "*" } | |
} | |
$serviceHooks = $serviceHooks |? { $_.ConsumerInputs.url -like $ToUrl } | |
} | |
if(-not [string]::IsNullOrWhitespace($ProjectName)) { | |
$project = Get-AzDProject -ProjectName $ProjectName | |
$ProjectId = $project.Id.ToString() | |
} | |
if(-not [string]::IsNullOrWhitespace($ProjectId)) { | |
$serviceHooks = $serviceHooks |? { $_.PublisherInputs.projectId -eq $ProjectId } | |
} | |
return $serviceHooks | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment