Skip to content

Commit

Permalink
Fix Native API calls to Chocolatey.org
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbergstrom committed Apr 3, 2021
1 parent fa79d06 commit 6168877
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.1] - 2021-04-03
#### Fixed
* No longer throws an error when searching for or installing packages from Chocolatey.org using the native API

## [2.1.0] - 2021-01-23
#### Changed
* Change default search to use exact package name if both package name and required version are specified (#20)
Expand Down
2 changes: 1 addition & 1 deletion src/ChocolateyGet.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'ChocolateyGet.psm1'
ModuleVersion = '2.1.0'
ModuleVersion = '2.1.1'
GUID = 'c1735ed7-8b2f-426a-8cbc-b7feb6b8288d'
Author = 'Jianyun'
Copyright = ''
Expand Down
11 changes: 6 additions & 5 deletions src/private/Invoke-Choco.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ function Invoke-Choco {
Write-Debug ("Invoking the Choco API with the following configuration: $($ChocoAPI.GetConfiguration() | Out-String)")
# This invocation looks gross, but PowerShell currently lacks a clean way to call the parameter-less .NET generic method that Chocolatey uses for returning data
$ChocoAPI.GetType().GetMethod('List').MakeGenericMethod([chocolatey.infrastructure.results.PackageResult]).Invoke($ChocoAPI,$null) | ForEach-Object {
# If searching local packages, we need to spoof the source name returned by the API with a generic default
if ($LocalOnly) {

# Attempt to translate the source URL back into a human-readable source name
$_.Source = $ChocoAPI.GetConfiguration().MachineSources | Where-Object Key -eq $_.Source | Select-Object -ExpandProperty Name

# If searching local packages, or nothing got returned, we need to spoof the source name returned by the API with a generic default
if ((-not $_.Source) -or $LocalOnly) {
$_.Source = $script:PackageSourceName
} else {
# Otherwise, convert the source URI returned by Choco to a source name
$_.Source = $ChocoAPI.GetConfiguration().MachineSources | Where-Object Key -eq $_.Source | Select-Object -ExpandProperty Name
}

$swid = @{
Expand Down

0 comments on commit 6168877

Please sign in to comment.