Closed evelyn-bi closed 2 months ago
Thanks @evelyn-bi , feel free to open a PR with this fix-- thanks
Thanks @evelyn-bi , feel free to open a PR with this fix-- thanks
@SydneyhSmith I haven't had a chance to figure out the tests in this project, if there are simulated server responses it should just be a matter of duplicating some existing test but removing the 'tags' element from the server response to make sure the old code fails the test and the new code passes it. I don't know when I will have time to figure that stuff out, do you think this pull request is worth it without the test?
@evelyn-bi yeah feel free to open without the tests
Prerequisites
Steps to reproduce
We use a Gitea NuGet package repository using the NuGet V3 API protocol. Apparently Gitea is not returning tags when it gives search results.
Using the new PSResourceGet's
Find-PSResource
using just-Name
or both-Name
and-Version
I get an error saying 'tags' must be in the response. This is with version 1.0.3 Microsoft.PowerShell.PSResourceGet. Note that using the old PowerShellGetRegister-PSRepository
to register this same Gitea repository works when searching for a PowerShell NuGet package, e.g.,Find-Script -Repository $repo -Name $script -RequiredVersion 1.0.0
.According to https://learn.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result, only id, version, versions, and packageTypes are required, 'tags' is optional.
Possible Fix
The V3ServerAPICalls.cs maybe just has a bug in both FindVersionHelper at https://github.com/PowerShell/PSResourceGet/blob/ce1d459e28c07c2cf35cdf75b1244695e0a3d70e/src/code/V3ServerAPICalls.cs#L564, and FindNameHelper at https://github.com/PowerShell/PSResourceGet/blob/ce1d459e28c07c2cf35cdf75b1244695e0a3d70e/src/code/V3ServerAPICalls.cs#L467, both of these have callers with
tags: Utils.EmptyStrArray
but the FindHelper methods always look for the 'tags' element in the server response.From a quick look it seems
IsRequiredTagSatisfied()
will work with empty tags, so maybe the only code that needs fixed are the two copies of the below code (FindName and FindVersion helpers) to only execute if thestring[] tags
parameter isn't empty:Likely just needs to be:
I tested building the module using the above code and it seems to work fine for me, Find-PSResource now finds the script on my Gitea server despite the server not returning 'tags' in the response. Main thing is to ensure
&& tags.Length != 0
is second becauseout JsonElement tagsItem
has to run to prevent an "Use of unassigned local variable 'tagsItem'" error during build.Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response