-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort public registry module version completion items (#15400)
The current sortText is not based on semantic versioning and lacks zero-padding, leading to incorrect client-side module version ordering. This PR resolves those issues. Before: ![image](https://github.com/user-attachments/assets/1749d7eb-af40-4884-978d-42e1e07894b9) After: ![image](https://github.com/user-attachments/assets/9a5acf00-d680-4039-803c-e4ea6512ecb9) Closes #14530. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15400)
- Loading branch information
Showing
17 changed files
with
187 additions
and
189 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
src/Bicep.Core.UnitTests/Mock/PublicRegistryModuleIndexClientMock.cs
This file contains 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,33 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using Bicep.Core.Registry.PublicRegistry; | ||
using Bicep.Core.UnitTests.Mock; | ||
using Moq; | ||
|
||
namespace Bicep.Core.UnitTests.Mock; | ||
|
||
public static class PublicRegistryModuleIndexClientMock | ||
{ | ||
// CONSIDER: Mock HttpClient rather than the typed client | ||
|
||
public static Mock<IPublicRegistryModuleIndexClient> Create(IEnumerable<PublicRegistryModuleIndexEntry> metadata) | ||
{ | ||
var mock = StrictMock.Of<IPublicRegistryModuleIndexClient>(); | ||
mock | ||
.Setup(client => client.GetModuleIndexAsync()) | ||
.ReturnsAsync(() => metadata.ToImmutableArray()); | ||
return mock; | ||
} | ||
|
||
public static Mock<IPublicRegistryModuleIndexClient> CreateToThrow(Exception exception) | ||
{ | ||
var mock = StrictMock.Of<IPublicRegistryModuleIndexClient>(); | ||
mock | ||
.Setup(client => client.GetModuleIndexAsync()) | ||
.ThrowsAsync(exception); | ||
return mock; | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/Bicep.Core.UnitTests/Mock/PublicRegistryModuleMetadataClientMock.cs
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
54 changes: 54 additions & 0 deletions
54
src/Bicep.Core/Registry/PublicRegistry/IPublicRegistryModuleIndexClient.cs
This file contains 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,54 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
using Bicep.Core.Extensions; | ||
using Bicep.Core.Registry.Oci; | ||
using Semver; | ||
|
||
namespace Bicep.Core.Registry.PublicRegistry; | ||
|
||
public readonly record struct PublicRegistryModuleProperties(string Description, string DocumentationUri); | ||
|
||
public record PublicRegistryModuleIndexEntry( | ||
[property:JsonPropertyName("moduleName")]string ModulePath, // e.g. "avm/app/dapr-containerapp" | ||
ImmutableArray<string> Tags, // e.g. "1.0.0" (not guaranteed to be in that format, although it currently is for public modules) | ||
[property: JsonPropertyName("properties")] ImmutableDictionary<string, PublicRegistryModuleProperties> PropertiesByTag // Module properties per tag | ||
) | ||
{ | ||
private static readonly SemVersion DefaultVersion = new(0); | ||
|
||
// Sort tags by version numbers in descending order. | ||
public ImmutableArray<string> Versions { get; } = [.. Tags.OrderByDescending(x => SemVersion.TryParse(x, SemVersionStyles.AllowV, out var version) ? version : DefaultVersion)]; | ||
|
||
public string? GetDescription(string? version = null) => this.GetProperty(version, x => x.Description); | ||
|
||
public string? GetDocumentationUri(string? version = null) => this.GetProperty(version, x => x.DocumentationUri); | ||
|
||
private string? GetProperty(string? version, Func<PublicRegistryModuleProperties, string> propertySelector) | ||
{ | ||
if (version is null) | ||
{ | ||
// Get description for most recent version with a description | ||
foreach (var tag in this.Versions) | ||
{ | ||
if (this.PropertiesByTag.TryGetValue(tag, out var propertiesEntry)) | ||
{ | ||
return propertySelector(propertiesEntry); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
else | ||
{ | ||
return this.PropertiesByTag.TryGetValue(version, out var propertiesEntry) ? propertySelector(propertiesEntry) : null; | ||
} | ||
} | ||
} | ||
|
||
public interface IPublicRegistryModuleIndexClient | ||
{ | ||
Task<ImmutableArray<PublicRegistryModuleIndexEntry>> GetModuleIndexAsync(); | ||
} |
20 changes: 0 additions & 20 deletions
20
src/Bicep.Core/Registry/PublicRegistry/IPublicRegistryModuleMetadataClient.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.