1- param ([string ] $Version )
1+ param ([string ] $Version , [ string ] $Source = " github " )
22
3- If (-not ($Version ))
3+ if (-not ($Version ))
44{
55 Throw " Parameter -Version is required" ;
66}
77
8+ if (-not ($Source -eq " github" ) -and -not ($Source -eq " appveyor" ))
9+ {
10+ Throw " Parameter -Source must be either 'github' or 'appveyor'" ;
11+ }
12+
813Set-Location $PSScriptRoot
914
1015[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
@@ -21,28 +26,63 @@ if (Test-Path $DownloadFilePath)
2126 exit ;
2227}
2328
24- # Find release and asset.
25- $Releases = Invoke-RestMethod - Uri ' https://api.github.com/repos/gitextensions/gitextensions/releases '
26- foreach ($Release in $Releases )
29+ Write-Host ( ' Searching for GitExtensions release on " ' + $Source + ' ". ' );
30+
31+ if ($Source -eq " github " )
2732{
28- if ($Release.tag_name -eq $Version )
29- {
30- Write-Host (' Selected release "' + $Release.name + ' ".' );
31- foreach ($Asset in $Release.assets )
33+ # Find release and asset.
34+ $Releases = Invoke-RestMethod - Uri ' https://api.github.com/repos/gitextensions/gitextensions/releases'
35+ foreach ($Release in $Releases )
36+ {
37+ if ($Release.tag_name -eq $Version )
3238 {
33- if ($Asset.content_type -eq " application/zip" -and $Asset.name.Contains (' Portable' ))
39+ Write-Host (' Selected release "' + $Release.name + ' ".' );
40+ foreach ($Asset in $Release.assets )
41+ {
42+ if ($Asset.content_type -eq " application/zip" -and $Asset.name.Contains (' Portable' ))
43+ {
44+ Write-Host (' Selected asset "' + $Asset.name + ' ".' );
45+ $AssetToDownloadUrl = $Asset.browser_download_url ;
46+ break ;
47+ }
48+ }
49+
50+ if (! ($null -eq $AssetToDownloadUrl ))
3451 {
35- Write-Host (' Selected asset "' + $Asset.name + ' ".' );
36- $AssetToDownloadUrl = $Asset.browser_download_url ;
3752 break ;
3853 }
3954 }
55+ }
56+ }
57+ elseif ($Source -eq " appveyor" )
58+ {
59+ $UrlVersion = $Version ;
60+ if ($UrlVersion.StartsWith (" v" ))
61+ {
62+ $UrlVersion = $UrlVersion.Substring (1 );
63+ }
64+
65+ $UrlBase = " https://ci.appveyor.com/api" ;
66+
67+ $BuildInfo = Invoke-RestMethod - Uri " $UrlBase /projects/gitextensions/gitextensions/build/$UrlVersion " ;
68+ $Job = $BuildInfo.build.jobs [0 ];
69+ if ($Job.Status -eq " success" )
70+ {
71+ $JobId = $Job.jobId ;
72+ Write-Host (' Selected build job "' + $JobId + ' ".' );
4073
41- if (! ($null -eq $AssetToDownloadUrl ))
74+ $AssetsUrl = " $UrlBase /buildjobs/$JobId /artifacts" ;
75+ $Assets = Invoke-RestMethod - Method Get - Uri $AssetsUrl
76+ foreach ($Asset in $Assets )
4277 {
43- break ;
78+ if ($Asset.type -eq " zip" -and $Asset.FileName.Contains (' Portable' ))
79+ {
80+ Write-Host (' Selected asset "' + $Asset.FileName + ' ".' );
81+ $AssetToDownloadUrl = $AssetsUrl + " /" + $Asset.FileName ;
82+ break ;
83+ }
4484 }
45- }
85+ }
4686}
4787
4888# Download and extract zip.
0 commit comments