-
Notifications
You must be signed in to change notification settings - Fork 270
(#1137) Fix package gallery details url not showing on gallery packages #1138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vexx32
merged 5 commits into
chocolatey:develop
from
AdmiringWorm:map-package-gallery-details-url
May 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8bd7ec2
(maint) Add unit test projects to solution
AdmiringWorm 8cfc0b1
( #1137) Map PackageDetailsUrl to GalleryDetailsUrl
AdmiringWorm ebd1d2b
(maint) Add GalleryUriBuilder utility
AdmiringWorm df07a54
(#1137) Add gallery URL building logic
AdmiringWorm 5a9465c
(maint) Extract mapper configuration to separate class
AdmiringWorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Source/ChocolateyGui.Common.Tests/ChocolateyGui.Common.Tests.csproj
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net48</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
|
|
||
| <Configurations>Debug;Release;ReleaseOfficial</Configurations> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.msbuild" Version="10.0.1"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
| <PackageReference Include="FluentAssertions.Analyzers" Version="0.34.1"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Moq" Version="4.20.72" /> | ||
| <PackageReference Include="NUnit" Version="3.14.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="6.2.0" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
| <PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.41" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ChocolateyGui.Common\ChocolateyGui.Common.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| namespace ChocolateyGui.Common.Tests | ||
| { | ||
| using NUnit.Framework; | ||
|
|
||
| public class Tests | ||
| { | ||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test1() | ||
| { | ||
| Assert.Pass(); | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
Source/ChocolateyGui.Common.Windows.Tests/ChocolateyGui.Common.Windows.Tests.csproj
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net48</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
|
|
||
| <Configurations>Debug;Release;ReleaseOfficial</Configurations> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.msbuild" Version="10.0.1"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
| <PackageReference Include="FluentAssertions.Analyzers" Version="0.34.1"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Moq" Version="4.20.72" /> | ||
| <PackageReference Include="NUnit" Version="3.14.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="6.2.0" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
| <PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.41" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ChocolateyGui.Common.Windows\ChocolateyGui.Common.Windows.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
20 changes: 20 additions & 0 deletions
20
Source/ChocolateyGui.Common.Windows.Tests/ChocolateyTestSetup.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using AutoMapper; | ||
| using ChocolateyGui.Common.Windows.Startup; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace ChocolateyGui.Common.Windows.Tests | ||
| { | ||
| [SetUpFixture] | ||
| public class ChocolateyTestSetup | ||
| { | ||
| public static IMapper Mapper { get; private set; } | ||
|
|
||
| [OneTimeSetUp] | ||
| public void SetupAutomapper() | ||
| { | ||
| var mapperConfiguration = ChocolateyGuiMapper.CreateConfiguration(); | ||
|
|
||
| Mapper = mapperConfiguration.CreateMapper(); | ||
| } | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
Source/ChocolateyGui.Common.Windows.Tests/Utilities/GalleryUriBuilderTests.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using System.Collections; | ||
| using ChocolateyGui.Common.Windows.Utilities; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace ChocolateyGui.Common.Windows.Tests.Utilities | ||
| { | ||
| [TestFixture] | ||
| [TestOf(typeof(GalleryUriBuilder))] | ||
| public class GalleryUriBuilderTests | ||
| { | ||
| public static IEnumerable EmptyValues => new[] | ||
| { | ||
| null, | ||
| string.Empty, | ||
| " " | ||
| }; | ||
|
|
||
| [TestCaseSource(nameof(EmptyValues))] | ||
| public void BuildFromPackageAndSource_ReturnsNull_ForNullOrWhitespacePackageId(string packageId) | ||
| { | ||
| GalleryUriBuilder.BuildFromPackageAndSource(packageId, "https://community.chocolatey.org/").Should().BeNull(); | ||
| } | ||
|
|
||
| [TestCaseSource(nameof(EmptyValues))] | ||
| public void BuildFromPackageAndSource_ReturnsNull_ForNullOrWhitespaceSource(string source) | ||
| { | ||
| GalleryUriBuilder.BuildFromPackageAndSource("some-package", source).Should().BeNull(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildFromPackageAndSource_ReturnsValidUri_ForValidPackageIdAndSource() | ||
| { | ||
| var uri = GalleryUriBuilder.BuildFromPackageAndSource("some-package", "https://community.chocolatey.org/"); | ||
| uri.Should().NotBeNull(); | ||
| uri.ToString().Should().Be("https://community.chocolatey.org/packages/some-package"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildFromPackageAndSource_ReturnsValidUri_WithUnknownSource() | ||
| { | ||
| var uri = GalleryUriBuilder.BuildFromPackageAndSource("some-package", "https://myget.org/F/chocolatey/api/v2/"); | ||
| uri.Should().NotBeNull(); | ||
| uri.ToString().Should().Be("https://myget.org/packages/some-package"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildFromPackageAndSource_ReturnsValidUri_WithVersion() | ||
| { | ||
| var uri = GalleryUriBuilder.BuildFromPackageAndSource("some-package", "https://community.chocolatey.org/", new NuGet.Versioning.NuGetVersion(1, 2, 3)); | ||
| uri.Should().NotBeNull(); | ||
| uri.ToString().Should().Be("https://community.chocolatey.org/packages/some-package/1.2.3"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildFromPackageSource_ReturnsValidUri_WithPreReleaseVersion() | ||
| { | ||
| var uri = GalleryUriBuilder.BuildFromPackageAndSource("some-package", "https://community.chocolatey.org/", new NuGet.Versioning.NuGetVersion(1, 2, 3, "beta")); | ||
| uri.Should().NotBeNull(); | ||
| uri.ToString().Should().Be("https://community.chocolatey.org/packages/some-package/1.2.3-beta"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsKnownSource_ReturnsFalse_ForInvalidUri() | ||
| { | ||
| GalleryUriBuilder.IsKnownSource("not a valid uri").Should().BeFalse(); | ||
| } | ||
|
|
||
| [TestCaseSource(nameof(EmptyValues))] | ||
| public void IsKnownSource_ReturnsFalse_ForNullOrWhitespace(string source) | ||
| { | ||
| GalleryUriBuilder.IsKnownSource(source).Should().BeFalse(); | ||
| } | ||
|
|
||
| [TestCase("https://blog.chocolatey.org/api/v2/")] | ||
| [TestCase("http://myget.org/F/chocolatey/api/v2/")] | ||
| public void IsKnownSource_ReturnsFalse_ForUnknownSources(string source) | ||
| { | ||
| GalleryUriBuilder.IsKnownSource(source).Should().BeFalse(); | ||
| } | ||
|
|
||
| [TestCase("https://chocolatey.org/api/v2/")] | ||
| [TestCase("https://community.chocolatey.org/api/v2/")] | ||
| [TestCase("https://community-test.chocolatey.org/api/v2/")] | ||
| public void IsKnownSource_ReturnsTrue_ForKnownSources(string source) | ||
| { | ||
| GalleryUriBuilder.IsKnownSource(source).Should().BeTrue(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
72 changes: 72 additions & 0 deletions
72
Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiMapper.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using AutoMapper; | ||
| using chocolatey.infrastructure.app.configuration; | ||
| using chocolatey.infrastructure.app.nuget; | ||
| using ChocolateyGui.Common.Models; | ||
| using ChocolateyGui.Common.ViewModels.Items; | ||
| using ChocolateyGui.Common.Windows.ViewModels; | ||
| using NuGet.Protocol.Core.Types; | ||
| using ChocolateySource = chocolatey.infrastructure.app.configuration.ChocolateySource; | ||
| using Environment = System.Environment; | ||
|
|
||
| namespace ChocolateyGui.Common.Windows.Startup | ||
| { | ||
| public static class ChocolateyGuiMapper | ||
| { | ||
| public static MapperConfiguration CreateConfiguration() | ||
| { | ||
| var mapperConfiguration = new MapperConfiguration(config => | ||
| { | ||
| config.ForAllMaps((_, mapping) => mapping.MaxDepth(64)); | ||
|
|
||
| config.CreateMap<IPackageViewModel, IPackageViewModel>() | ||
| .ForMember(vm => vm.IsInstalled, options => options.Ignore()); | ||
|
|
||
| config.CreateMap<IPackageSearchMetadata, Package>() | ||
| .ForMember(dest => dest.Version, opt => opt.MapFrom(src => src.Identity.Version)) | ||
| .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Identity.Id)) | ||
| .ForMember(dest => dest.Authors, opt => opt.MapFrom(src => src.Authors.Split(','))) | ||
| .ForMember(dest => dest.Owners, opt => opt.MapFrom(src => src.Owners.Split(','))) | ||
| .ForMember(dest => dest.GalleryDetailsUrl, opt => opt.MapFrom(src => src.PackageDetailsUrl == null ? null : src.PackageDetailsUrl.AbsoluteUri)); | ||
|
|
||
| config.CreateMap<ConfigFileFeatureSetting, ChocolateyFeature>(); | ||
| config.CreateMap<ConfigFileConfigSetting, ChocolateySetting>(); | ||
| config.CreateMap<ConfigFileSourceSetting, Common.Models.ChocolateySource>() | ||
| .ForMember(dest => dest.Password, opt => opt.MapFrom(src => NugetEncryptionUtility.DecryptString(src.Password))) | ||
| .ForMember(dest => dest.CertificatePassword, opt => opt.MapFrom(src => NugetEncryptionUtility.DecryptString(src.CertificatePassword))); | ||
|
|
||
| config.CreateMap<ChocolateySource, Common.Models.ChocolateySource>() | ||
| .ForMember(dest => dest.VisibleToAdminsOnly, opt => opt.MapFrom(src => src.VisibleToAdminOnly)); | ||
|
|
||
| config.CreateMap<AdvancedInstallViewModel, AdvancedInstall>() | ||
| .ForMember( | ||
| dest => dest.DownloadChecksum, | ||
| opt => opt.Condition(source => !source.IgnoreChecksums)) | ||
| .ForMember( | ||
| dest => dest.DownloadChecksumType, | ||
| opt => opt.Condition(source => | ||
| !source.IgnoreChecksums && !string.IsNullOrEmpty(source.DownloadChecksum))) | ||
| .ForMember( | ||
| dest => dest.DownloadChecksum64bit, | ||
| opt => opt.Condition(source => | ||
| Environment.Is64BitOperatingSystem | ||
| && !source.IgnoreChecksums | ||
| && !source.Forcex86)) | ||
| .ForMember( | ||
| dest => dest.DownloadChecksumType64bit, | ||
| opt => opt.Condition(source => | ||
| Environment.Is64BitOperatingSystem | ||
| && !source.IgnoreChecksums | ||
| && !source.Forcex86 | ||
| && !string.IsNullOrEmpty(source.DownloadChecksum64bit))) | ||
| .ForMember( | ||
| dest => dest.PackageParameters, | ||
| opt => opt.Condition(source => !source.SkipPowerShell)) | ||
| .ForMember( | ||
| dest => dest.InstallArguments, | ||
| opt => opt.Condition(source => !source.SkipPowerShell && !source.NotSilent)); | ||
| }); | ||
|
|
||
| return mapperConfiguration; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.