-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Update-Gitbutler script to use JSON for version retrieval an…
…d format release notes in YAML
- Loading branch information
Showing
1 changed file
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |