Created
January 29, 2016 17:59
-
-
Save Jaykul/598e409b11cd1eec8df5 to your computer and use it in GitHub Desktop.
GitHub Helper Functions
This file contains hidden or 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-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