Skip to content

Commit

Permalink
(sourcetree) Fixes Issue #1261 (#1276)
Browse files Browse the repository at this point in the history
(sourcetree) Fixes Issue #1261
  • Loading branch information
AdmiringWorm authored May 14, 2019
2 parents bc8af2e + 65a8034 commit dc213b0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
32 changes: 3 additions & 29 deletions automatic/sourcetree/update.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import-module au

$releases = "https://www.sourcetreeapp.com/enterprise"
. ".\update_helper.ps1"

function global:au_SearchReplace {
@{
Expand All @@ -16,32 +15,7 @@ function global:au_SearchReplace {
}

function global:au_GetLatest {
$download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing

# https://downloads.atlassian.com/software/sourcetree/windows/ga/SourcetreeEnterpriseSetup_2.5.5.msi
$re32 = "SourcetreeEnterpriseSetup_(.*).msi"

# There are multiple download links on the page.
# We need to find the one with the highest version number in case not all of them are the same.
$msiLinks = @()
$download_page.links | Where-Object href -match $re32 | ForEach-Object {
$msiLinks += New-Object PSObject -Property @{
'href' = $_.href
'versionString' = [regex]::Matches($_.href, $re32).Groups[1].Value
'version' = [version]([regex]::Matches($_.href, $re32).Groups[1]).Value
}
}

$newestMsi = $msiLinks | Sort-Object version -descending | Select-Object -First 1

$url32 = $newestMsi.href
$version32 = $newestMsi.versionString
@{
Version = $version32
URL32 = $url32
PackageName = 'SourceTree'
ReleaseNotes = "https://www.sourcetreeapp.com/update/windows/ga/ReleaseNotes_$version32.html"
}
return Get-JavaSiteUpdates -Package "sourcetree" -Title "Sourcetree for Windows Enterprise"
}

update -NoCheckChocoVersion
update
54 changes: 54 additions & 0 deletions automatic/sourcetree/update_helper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function Get-PackageName() {
param(
[string]$a
)

switch -w ( $a ) {
'sourcetree' {
$PackageUrl = "https://www.sourcetreeapp.com/enterprise"
}
}

return $PackageUrl
}

function Get-JavaSiteUpdates {
param(
[string]$Package,
[string]$Title,
[string]$Wait = 4
)

$regex = '([\d]{0,2}[\.][\d]{0,2}[\.][\d]{0,2}[\.][\d]{0,5})'
$url = Get-PackageName $Package
$ie = New-Object -comobject InternetExplorer.Application
$ie.Navigate2($url)
$ie.Visible = $false

while($ie.ReadyState -ne $Wait) {
Start-Sleep -Seconds 20
}

foreach ( $_ in $ie.Document.getElementsByTagName("a") ) {
$url = $_.href;
if ( $url -match $regex) {
$yes = $url | Select-Object -last 1
$version = $Matches[0]
break;
}
}

$ie.quit()

if ( $version.endswith(".") ) {
$version = Get-Version $yes
}

@{
PackageName = $Package
Title = $Title
Version = $version
URL32 = $yes
ReleaseNotes = "https://www.sourcetreeapp.com/update/windows/ga/ReleaseNotes_$version.html"
}
}

0 comments on commit dc213b0

Please sign in to comment.