Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): Allow downloading from private repositories #4254

Merged
merged 17 commits into from
Mar 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated url to pull filename
  • Loading branch information
thad committed Mar 11, 2022
commit f52453410a68efc03a74b2c221f6c3a7871171c6
7 changes: 4 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1032,18 +1032,19 @@ function handle_special_urls($url)
}

# Github.com
if ($url -match "github.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/releases\/download\/(?<tag>[^\/]+)\/(?<file>.*)" -and (get_config 'gh_api_token')) {
if ($url -match "github.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/releases\/download\/(?<tag>[^\/]+)\/(?<file>[^\/#]+)(?<filename>.*)" -and (get_config 'gh_api_token')) {
tmsmith marked this conversation as resolved.
Show resolved Hide resolved
$headers = @{
"Authorization" = "token $(get_config 'gh_api_token')"
"Authorization" = "token $(get_config 'gh_api_token')"
tmsmith marked this conversation as resolved.
Show resolved Hide resolved
}
$privateUrl = "https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])"
$assetUrl="https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])/releases/tags/$($matches['tag'])"

$isPrivate = (Invoke-RestMethod -Uri $privateUrl -Headers $headers).private
if ($isPrivate) {
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).assets | Where-Object { $_.name -eq $matches['file'] }).url
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).assets | Where-Object { $_.name -eq $matches['file'] }).url + $($matches['filename'])
}
}

return $url
}

Expand Down