PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
486 stars 92 forks source link

Fix requiring 'tags' in server response #1627

Closed evelyn-bi closed 5 months ago

evelyn-bi commented 6 months ago

FindNameHelper and FindVersionHelper now properly allow a server response that has no 'tags' element. This fixes Install-PSResource not working, and fixes Find-PSResource not working in the case of the user not using the -Tag parameter. Using Find-PSResource with -Tag still properly errors out if the server does not respond with tags.

PR Summary

When the server response doesn't contain tags, the find helpers now only give an error if the user passed in -Tag {tags to find}, if the user is searching for a tag then it's necessary for the response to contain tags. But when -Tag is not used then the lack of 'tags' in the server response is now ignored and the code continues as expected. The rest of the code already handles no tags correctly.

This PR does not contain updated tests, someone responded in issue #1621 that this should be fine. Updated tests should just involve duplicating one or more existing tests around finding and installing packages but removing the 'tags' element in the server responses to verify the old code fails the test and new code passes.

PR Context

Resolves #1621

Tags are optional in the NuGet API as shown here. Before this fix, when using Find-PSResource against a server that does not return 'tags' would give an error saying the server response does not contain the 'tags' element, this occurred even in the case of the user not using the -Tag parameter to search for a tag. This behavior is seen on a local Gitea server where it does not include tags in the response for unknown reasons, but that is supposed to be allowed in the NuGet API. Also note that PowerShellGet was tested on the same server and it finds packages fine despite the server not returning the 'tags' element.

Without this fix, using PSResourceGet is unusable with Gitea for finding and installing packages with Find-PSResource and Install-PSResource because they both use the code that requires the 'tags' element and error out.

PR Checklist

alerickson commented 5 months ago

/azp run PowerShell.PSResourceGet

azure-pipelines[bot] commented 5 months ago
Azure Pipelines successfully started running 1 pipeline(s).