Skip to content

Commit

Permalink
fix: Properly support archived versions in the new issue prompt (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Dec 28, 2021
1 parent 4a62d17 commit 649f4f5
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

🎉🎉 YAML typed manifest and archived manifest installation support 🎉🎉

- Prompt for the new issue now has correct version in title in case of archived manifest is being downloaded/installed/...
- **Unix**:
- Fix `--version` command under *nix
- Supress errors about environment variables, until fully implemented.
Expand Down
2 changes: 1 addition & 1 deletion bin/update-supporting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ foreach ($sup in $Sups) {
} catch {
++$problems
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Version $manifest.version

continue
}
Expand Down
62 changes: 41 additions & 21 deletions lib/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function New-IssuePrompt {
<#
.SYNOPSIS
Prompt user to report a manifest problem to it's maintaners.
Post direct link in case of supported source control provides.
Post direct link in case of supported source control providers.
.PARAMETER Application
Specifies the application name.
.PARAMETER Bucket
Expand All @@ -319,23 +319,34 @@ function New-IssuePrompt {
Specifies the title of newly created issue.
.PARAMETER Body
Specifies more details to be posted as issue body.
.PARAMETER Version
Specifies the exact version to be shown in the title of issue.
#>
param([String] $Application, [String] $Bucket, [String] $Title, [String[]] $Body)

$Bucket = $Bucket.Trim()
# TODO: Adopt-ManifestResolveInformation
$app, $manifest, $Bucket, $url = Find-Manifest $Application $Bucket
$url = known_bucket_repo $Bucket
$bucketPath = Join-Path $SCOOP_BUCKETS_DIRECTORY $Bucket

if ((Test-Path $bucketPath) -and (Join-Path $bucketPath '.git' | Test-Path -PathType 'Container')) {
$remote = Invoke-GitCmd -Repository $bucketPath -Command 'config' -Argument '--get', 'remote.origin.url'
# Support ssh and http syntax
# git@PROVIDER:USER/REPO.git
# https://PROVIDER/USER/REPO.git
# https://regex101.com/r/OMEqfV
if ($remote -match '(?:@|:\/\/)(?<provider>.+?)[:\/](?<user>.*)\/(?<repo>.+?)(?:\.git)?$') {
$url = "https://$($Matches.Provider)/$($Matches.User)/$($Matches.Repo)"
param([String] $Application, [String] $Bucket, [String] $Title, [String[]] $Body, [String] $Version)

$url = $null
if ($Bucket) {
$Bucket = $Bucket.Trim()
if (!$Version) {
try {
$Version = (manifest_path $Application $Bucket | ConvertFrom-Manifest).version
} catch {
$Version = $null
}
}

$url = known_bucket_repo $Bucket
$bucketPath = Join-Path $SCOOP_BUCKETS_DIRECTORY $Bucket

if ((Test-Path -LiteralPath $bucketPath) -and (Join-Path $bucketPath '.git' | Test-Path -PathType 'Container')) {
$remote = Invoke-GitCmd -Repository $bucketPath -Command 'config' -Argument '--get', 'remote.origin.url'
# Support ssh and http syntax
# git@PROVIDER:USER/REPO.git
# https://PROVIDER/USER/REPO.git
# https://regex101.com/r/OMEqfV
if ($remote -match '(?:@|:\/\/)(?<provider>.+?)[:\/](?<user>.*)\/(?<repo>.+?)(?:\.git)?$') {
$url = "https://$($Matches.Provider)/$($Matches.User)/$($Matches.Repo)"
}
}
}

Expand All @@ -344,7 +355,8 @@ function New-IssuePrompt {
return
}

$Title = [System.Web.HttpUtility]::UrlEncode("$Application@$($Manifest.version): $Title")
$_v = if ($Version) { "$Application@$Version" } else { $Application }
$Title = [System.Web.HttpUtility]::UrlEncode("${_v}: $Title")
$Body = [System.Web.HttpUtility]::UrlEncode($Body)
$msg = "`nPlease try again"

Expand Down Expand Up @@ -373,14 +385,16 @@ function New-IssuePromptFromException {
[AllowNull()]
[String] $Application,
[AllowNull()]
[String] $Bucket
[String] $Bucket,
[AllowNull()]
[String] $Version
)

process {
$title, $body = $ExceptionMessage -split '\|-'
if (!$body) { $body = $title }
if ($body -ne 'Ignore') { Write-UserMessage -Message $body -Err }
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $Application -Bucket $Bucket -Title $title -Body $body }
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $Application -Bucket $Bucket -Title $title -Body $body -Version $Version }
}
}

Expand All @@ -401,10 +415,16 @@ function Get-NotePropertyEnumerator {

#region Exceptions
class ScoopException: System.Exception {
$Message
[String] $Message
[String] $Version

ScoopException([String] $Message) {
$this.Message = $Message
}

ScoopException([String] $Message, [String] $Version) {
$this.Message = $Message
$this.Version = $Version
}
}
#endregion Exceptions
2 changes: 1 addition & 1 deletion lib/Installation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Install-ScoopApplication {
$version = $ResolvedObject.ManifestObject.version

if ($version -match '[^\w\.\-\+_]') {
throw [ScoopException]::new("Invalid manifest|-Manifest version has unsupported character '$($matches[0])'.") # TerminatingError thrown
throw [ScoopException]::new("Invalid manifest|-Manifest version has unsupported character '$($Matches[0])'.", $version) # TerminatingError thrown
}

if ($version -eq 'nightly') {
Expand Down
4 changes: 2 additions & 2 deletions lib/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function Update-App {

# TODO: Could this ever happen?
if (!$Force -and ($oldVersion -eq $version)) {
throw [ScoopException]::new("The Latest version of '$App' ($version) is already installed.") # TerminatingError thrown
throw [ScoopException]::new("The Latest version of '$App' ($version) is already installed.", $version) # TerminatingError thrown
}

# TODO:???
Expand Down Expand Up @@ -373,7 +373,7 @@ function Update-App {
if ($url -like '*sourceforge.net*') {
Write-UserMessage -Message 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.' -Warning
}
throw [ScoopException]::new("Hash check failed|-$err") # TerminatingError thrown
throw [ScoopException]::new("Hash check failed|-$err", $version) # TerminatingError thrown
}
}
}
Expand Down
41 changes: 9 additions & 32 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,18 @@ function Test-Aria2Enabled {
process { return (Test-HelperInstalled -Helper 'Aria2') -and (get_config 'aria2-enabled' $true) }
}

function Find-Manifest($app, $bucket) {
$manifest, $url = $null, $null

# Check if app is a URL or UNC path
if ($app -match '^(ht|f)tps?://|\\\\') {
$url = $app
$app = appname_from_url $url
$manifest = url_manifest $url
} else {
# Check buckets
$manifest, $bucket = find_manifest $app $bucket

if (!$manifest) {
# Could not find app in buckets: check if it's a local path
$path = $app
# TODO: YAML
if (!$path.endswith('.json')) { $path += '.json' }
if (Test-Path $path) {
$url = "$(Resolve-Path $path)"
$app = appname_from_url $url
$manifest, $bucket = url_manifest $url
}
}
}

return $app, $manifest, $bucket, $url
}

#region TODO: Extract lib/Download.ps1
function dl_with_cache($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {
$cached = cache_path $app $version $url
debug $cached

if (!(Test-Path $cached) -or !$use_cache) {
Confirm-DirectoryExistence -LiteralPath $SCOOP_CACHE_DIRECTORY | Out-Null
do_dl $url "$cached.download" $cookies
try {
do_dl $url "$cached.download" $cookies
} catch {
throw [ScoopException]::new($_.Exception.Message, $version) # TerminatingError thrown
}
Move-Item "$cached.download" $cached -Force
} else { Write-UserMessage -Message "Loading $(url_remote_filename $url) from cache" }

Expand Down Expand Up @@ -344,6 +320,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
Out-UTF8File -Path $urlstxt -Content $urlstxt_content

# Build aria2 command
# TODO: Adopt better approach
$aria2 = "& '$(Get-HelperPath -Helper Aria2)' $($options -join ' ')"

debug $aria2
Expand Down Expand Up @@ -384,7 +361,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
$aria2
)

throw [ScoopException]::new("Download via aria2 failed|-$mes") # TerminatingError thrown
throw [ScoopException]::new("Download via aria2 failed|-$mes", $version) # TerminatingError thrown
}

# Remove aria2 input file when done
Expand All @@ -408,7 +385,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
Write-UserMessage -Message 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.' -Color Yellow
}

throw [ScoopException]::new("Hash check failed|-$err") # TerminatingError thrown
throw [ScoopException]::new("Hash check failed|-$err", $version) # TerminatingError thrown
}
}

Expand Down Expand Up @@ -631,7 +608,7 @@ function dl_urls($app, $version, $manifest, $bucket, $architecture, $dir, $use_c
if ($url.Contains('sourceforge.net')) {
Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
}
throw [ScoopException]::new("Hash check failed|-$err") # TerminatingError thrown
throw [ScoopException]::new("Hash check failed|-$err", $version) # TerminatingError thrown
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libexec/scoop-download.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ foreach ($app in $application) {
}

debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket -Version $version

continue
}
Expand Down Expand Up @@ -126,7 +126,7 @@ foreach ($app in $application) {
}

debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket -Version $version

continue
}
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ foreach ($app in $toInstall.Resolved) {
}

debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $app.ApplicationName -Bucket $app.Bucket
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $app.ApplicationName -Bucket $app.Bucket -Version $app.Version

continue
}
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ foreach ($explode in $Applications) {
} catch {
++$Problems
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $app -Bucket $bucket
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $app -Bucket $bucket -Version $_.Exception.Version

continue
}
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (!$Applications) {
++$Problems
$failedApplications += $out[0]
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $out[0] -Bucket $out[2]
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $out[0] -Bucket $out[2] -Version $_.Exception.Version
}
}
}
Expand Down

0 comments on commit 649f4f5

Please sign in to comment.