From 0a90897985dddb8a55ab2dad20c30572926d333b Mon Sep 17 00:00:00 2001 From: chtof Date: Sun, 3 May 2020 15:34:56 +0200 Subject: [PATCH] Create au_Helper_GitHub.ps1 --- helpers/au_Helper_GitHub.ps1 | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 helpers/au_Helper_GitHub.ps1 diff --git a/helpers/au_Helper_GitHub.ps1 b/helpers/au_Helper_GitHub.ps1 new file mode 100644 index 000000000..f00157b23 --- /dev/null +++ b/helpers/au_Helper_GitHub.ps1 @@ -0,0 +1,41 @@ +# Author: Christophe Lefebvre +# Last Change: 03-May-2020. + +<# +.SYNOPSIS + Get URL32 and/or URL64 and Version from a GitHub repository. + +.DESCRIPTION + This function helps to get URL 32 and/or URL64 from the latest release available on a GitHub repository. +#> +function global:au_Helper_GitHub () { + Param( + [parameter(position=0)] + $GitHubRepository, + [parameter(position=1)] + $RegexFile32, + [parameter(position=2)] + $RegexFile64 + ) + + if ((-Not ($RegexFile32)) -And (-Not ($RegexFile64))) { + throw ("You must use `"-RegexFile32`" and/or `"-RegexFile64`" switchs.") + } + + $releases = 'https://github.com/' + $GitHubRepository + '/releases/latest' + $regexVersion = "/$GitHubRepository/tree/(?[\d\.]+)" + $download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing + $download_page.Content -match "$regexVersion" + $result += @{Version = $matches.Version} + + foreach ($arch in "32", "64") { + $regexFile = (Get-Variable -Name "RegexFile$arch").Value + + if ($regexFile) { + $url = $download_page.links | ? href -match "/$regexFile" + $result += @{"URL$arch" = $('https://github.com' + $url.href)} + } + } + + return $result +} \ No newline at end of file