Public/GitHub/Get-GitHubRelease.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
function Get-GitHubRelease { [CmdletBinding()] param ( # The GitHub repo to create the release against [Parameter( Mandatory = $true, Position = 0 )] [string] $RepoName, # The organisation that the repo lives in [Parameter( Mandatory = $true, Position = 1 )] [Alias('GitHubOrganisation','GitHubOrganization')] [string] $GitHubOrg, # The PAT to access the repo [Parameter( Mandatory = $true )] [string] $GitHubToken ) $Header = @{ Authorization = "token $GitHubToken" Accept = 'application/vnd.github.v3+json' } $URI = "https://api.github.com/repos/$GitHubOrg/$RepoName/releases" Write-Verbose "Attempting to fetch releases from $URI" try { $Request = Invoke-RestMethod -Headers $Header -Uri $URI -Method Get -FollowRelLink | Foreach-Object { $_ } # Needed because of https://github.com/PowerShell/PowerShell/issues/5526 } catch { Write-Error $_.Exception.Message } Return $Request } |