-
-
Save devlead/02ce5e9921bd8422a6fea59e8ccfab05 to your computer and use it in GitHub Desktop.
Tests if web hook exists on supplied repository
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
[OutputType([bool])] | |
Param( | |
[parameter(Mandatory=$true)] | |
[string] | |
[ValidateNotNullOrEmpty()] $BitbucketUser, | |
[parameter(Mandatory=$true)] | |
[string] | |
[ValidateNotNullOrEmpty()] $BitbucketPassword, | |
[parameter(Mandatory=$true)] | |
[string] | |
[ValidateNotNullOrEmpty()] $RepositoryUserSlug, | |
[parameter(Mandatory=$true)] | |
[string] | |
[ValidateNotNullOrEmpty()] $WebHookUrl | |
) | |
[string] $RepositoryHooksUrl = "https://api.bitbucket.org/2.0/repositories/$RepositoryUserSlug/hooks" | |
[string] $BasicAuth = [System.Convert]::ToBase64String( | |
[System.Text.Encoding]::UTF8.GetBytes("${BitbucketUser}:${BitbucketPassword}") | |
) | |
[hashtable] $RequestHeaders = @{"Authorization" = "Basic $BasicAuth"} | |
[string[]] $Urls = @() | |
[bool] $HasMorePages = $false | |
Do { | |
$Result = Invoke-RestMethod -Uri $RepositoryHooksUrl -Headers $RequestHeaders -Method Get | |
if (($Result.values|Measure-Object).Count -gt 0) | |
{ | |
$Urls += ($Result.values| % url) | |
} | |
$HasMorePages = (![string]::IsNullOrWhiteSpace($Result.Next)) | |
$RepositoryHooksUrl = $Result.Next | |
} While($HasMorePages) | |
($Urls | Where-Object { $WebHookUrl -eq $_ } | Measure-Object).Count -gt 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment