Skip to content

Commit 5dde8fa

Browse files
committed
#19 Adding method to get branches for repository
1 parent f7734b6 commit 5dde8fa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

GitHubAnalytics.psm1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,54 @@ function Get-GitHubOrganizationRepository
971971
return $resultToReturn
972972
}
973973

974+
function Get-GitHubRepositoryBranch
975+
{
976+
param
977+
(
978+
[Parameter(Mandatory=$true)]
979+
[ValidateNotNullOrEmpty()]
980+
[String] $owner,
981+
[Parameter(Mandatory=$true)]
982+
[ValidateNotNullOrEmpty()]
983+
[String] $repository,
984+
$gitHubAccessToken = $script:gitHubToken
985+
)
986+
987+
$resultToReturn = @()
988+
989+
$query = "$script:gitHubApiUrl/repos/$owner/$repository/branches?"
990+
991+
if (![string]::IsNullOrEmpty($gitHubAccessToken))
992+
{
993+
$query += "&access_token=$gitHubAccessToken"
994+
}
995+
996+
do
997+
{
998+
try
999+
{
1000+
$jsonResult = Invoke-WebRequest $query
1001+
$branches = (ConvertFrom-Json -InputObject $jsonResult.content)
1002+
}
1003+
catch [System.Net.WebException] {
1004+
Write-Error "Failed to execute query with exception: $($_.Exception)`nHTTP status code: $($_.Exception.Response.StatusCode)"
1005+
return $null
1006+
}
1007+
catch {
1008+
Write-Error "Failed to execute query with exception: $($_.Exception)"
1009+
return $null
1010+
}
1011+
1012+
foreach($branch in $branches)
1013+
{
1014+
$resultToReturn += $branch
1015+
}
1016+
$query = Get-NextResultPage -jsonResult $jsonResult
1017+
} while ($query -ne $null)
1018+
1019+
return $resultToReturn
1020+
}
1021+
9741022
<#
9751023
.SYNOPSIS Function to get next page with results from query to GitHub API
9761024

0 commit comments

Comments
 (0)