Skip to content

Commit

Permalink
Refactor Update-Gitbutler script to use JSON for version retrieval an…
Browse files Browse the repository at this point in the history
…d format release notes in YAML
  • Loading branch information
Utesgui committed Jan 9, 2025
1 parent 7161e82 commit f4f6760
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions scripts/Packages/Update-Gitbutler.GitButler.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@

$websiteURL = "https://app.gitbutler.com/releases/release"
$releaseNotesURL = "https://github.com/gitbutlerapp/gitbutler/releases"


# Follow redirect of https://app.gitbutler.com/downloads/release/windows/x86_64/msi
$website = $WebsiteURL
$absolutURL=[System.Net.HttpWebRequest]::Create($website).GetResponse().ResponseUri.AbsoluteUri
$website = Invoke-WebRequest -Uri $websiteURL -UseBasicParsing
$WebsiteContent = $website.Content
$LatestJSON = $WebsiteContent | ConvertFrom-Json

# regex to check if variable absolutURL is valid URL
$regex = "^(http|https)://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"
if ($absolutURL -match $regex) {
$latestVersionUrl = $absolutURL
Write-Host "URL is valid"
}
else {
Write-Host "URL is not valid"
exit 1
$latestVersionUrl = ($LatestJSON.platforms.'windows-x86_64'.url).Replace(".zip", "")
$releaseNotesJSON = $LatestJSON.notes


$latestVersion = $LatestJSON[0].Version


# Convert the extracted content to YAML format
$yamlContent = "ReleaseNotes: |-`n"
$lines = $releaseNotesJSON -split "`n"
foreach ($line in $lines) {
$yamlContent += " $line`n"
}

$releaseNotes = $yamlContent.trim() + "`nReleaseNotesUrl: $releaseNotesURL"


return $latestVersion, $latestVersionUrl, $releaseNotes


### Old Version with HTML Parsing of Website for future reference

# # Follow redirect of https://app.gitbutler.com/downloads/release/windows/x86_64/msi
# $website = $WebsiteURL
# $absolutURL=[System.Net.HttpWebRequest]::Create($website).GetResponse().ResponseUri.AbsoluteUri

# # regex to check if variable absolutURL is valid URL
# $regex = "^(http|https)://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"
# if ($absolutURL -match $regex) {
# $latestVersionUrl = $absolutURL
# Write-Host "URL is valid"
# }
# else {
# Write-Host "URL is not valid"
# exit 1
# }


# get full name of file from link
$fileName = $latestVersionUrl.Split("/")[-1]
# # get full name of file from link
# $fileName = $latestVersionUrl.Split("/")[-1]

# Get Version via Regex. The version is the part betweet "GitButler_" and "_x64"
$latestVersion = $fileName -replace ".*GitButler_(.*)_(x64|x86).*", '$1'
# # Get Version via Regex. The version is the part betweet "GitButler_" and "_x64"
# $latestVersion = $fileName -replace ".*GitButler_(.*)_(x64|x86).*", '$1'

return $latestVersion, $latestVersionUrl
# return $latestVersion, $latestVersionUrl

0 comments on commit f4f6760

Please sign in to comment.