Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created January 29, 2016 17:59
Show Gist options
  • Save Jaykul/598e409b11cd1eec8df5 to your computer and use it in GitHub Desktop.
Save Jaykul/598e409b11cd1eec8df5 to your computer and use it in GitHub Desktop.
GitHub Helper Functions
function Get-GithubRelease {
[CmdletBinding()]
param(
# The user or organization that owns the repository
[Parameter(Mandatory)]
$Owner,
# The name of the project repository
[Parameter(Mandatory)]
$Repo,
# The release id. Defaults to "latest" (e.g. v15.0 or "latest")
$Release = "latest",
# A personal access token instead of your password (https://github.com/settings/tokens)
# I recommend you store this in your PSDefaultParameters['Get-GithubRelease:AccessToken']
[Parameter(Mandatory)]
$AccessToken,
# The FOLDER to download to
[String]$Output = $(Get-Location -PSProvider FileSystem)
)
$GithubHeaders = @{ Accept = "application/vnd.github.v3+json"; Authorization = "token $AccessToken" }
$ReleaseUrl = "https://api.github.com/repos/$owner/$repo/releases/$Release"
$Release = Invoke-RestMethod $ReleaseUrl -Headers $GithubHeaders
Write-Verbose "Release Response: $Release"
$OutFile = Join-Path $Output $Release.assets[0].name
$GithubHeaders.Accept = "application/octet-stream"
Invoke-WebRequest $Release.assets[0].url -OutFile $OutFile -Headers $GithubHeaders
Get-Item $OutFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment