Skip to content

Instantly share code, notes, and snippets.

@tmeckel
Created May 31, 2019 13:51
Show Gist options
  • Save tmeckel/c4fa457f20a546613491a1bb04a1f006 to your computer and use it in GitHub Desktop.
Save tmeckel/c4fa457f20a546613491a1bb04a1f006 to your computer and use it in GitHub Desktop.
Get project release numbers from GitHub
[System.Net.ServicePointManager]::SecurityProtocol += 'Tls12'
$owner = 'microsoft' # 'microsoft' # 'golang'
$repo = 'Git-Credential-Manager-for-Windows' #'Git-Credential-Manager-for-Windows' #'go'
$relList = $null
$limitAll = $true
$relUrl = (Invoke-RestMethod -Uri "https://api.github.com/repos/$owner/$repo").releases_url
if ($relUrl) {
$idx = $relUrl.IndexOf('{')
if (0 -lt $idx) {
$relUrl = $relUrl.Substring(0, $idx)
}
$relList = @(Invoke-RestMethod -Uri $relUrl).tag_name
}
if (-not $relList -or 0 -ge $relList.Count) {
if (-not (Get-Command -Name 'ConvertFrom-Html' -ErrorAction:SilentlyContinue)) {
Import-Module PowerHTML -ErrorAction:Stop
}
$relList = @() # New-Object System.Collections.ArrayList
$lastRel = $null
do {
#$url = "https://github.com/$owner/$repo/releases"
$url = "https://github.com/$owner/$repo/tags"
if ($lastRel) {
$url += "?after=$lastRel"
}
$doc = ConvertFrom-Html -URI $url
$lastRel = $null
if ($doc) {
#$relItems = $doc.SelectNodes('//div[@class="release-entry"]//div[contains(@class, "Details")]//a[contains(@href, "/releases/tag/")]')
$relItems = $doc.SelectNodes('//div[contains(@class, "Details")]//div[@class="d-flex"]//a[contains(@href, "/releases/tag/")]')
if ($relItems) {
$crelList = @($relItems.GetAttributeValue("href", [string]::Empty) `
| ForEach-Object {
$href = $_.TrimEnd('/')
$href = $href.Substring($href.LastIndexOf('/')+1)
$href
})
$lastRel = $crelList[-1]
$relList += $crelList
}
}
} while ($lastRel -and $limitAll)
}
$relList
<#
$os = 'windows'
$arch = 'amd64'
$fmt = 'zip'
# https://dl.google.com/go/go1.12.5.windows-amd64.zip
$dlUrl = "https://dl.google.com/go/$($relList[0]).$os-$arch.$fmt"
Write-Host "Download URL [$dlUrl]"
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment