Skip to content

Commit

Permalink
Merge #3957 Re-sort module properties after merging
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 15, 2023
2 parents c831d80 + 94e9e91 commit d43a2ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.

## v1.34.3

### Internal

- [Netkan] Re-sort module properties after merging (#3957 by: HebaruSan)

## v1.34.2 (Minkowski²)

Expand Down
6 changes: 4 additions & 2 deletions Netkan/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using CKAN.Versioning;
using CKAN.NetKAN.Extensions;
using CKAN.NetKAN.Transformers;

namespace CKAN.NetKAN.Model
{
Expand Down Expand Up @@ -124,8 +125,9 @@ public Metadata(YamlMappingNode yaml) : this(yaml?.ToJObject())

public static Metadata Merge(Metadata[] modules)
=> modules.Length == 1 ? modules[0]
: new Metadata(MergeJson(modules.Select(m => m._json)
.ToArray()));
: PropertySortTransformer.SortProperties(
new Metadata(MergeJson(modules.Select(m => m._json)
.ToArray())));

private static JObject MergeJson(JObject[] jsons)
{
Expand Down
3 changes: 1 addition & 2 deletions Netkan/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public static int Main(string[] args)
);
inf.ValidateCkan(ckan);
Console.WriteLine(QueueHandler.serializeCkan(
new PropertySortTransformer().Transform(ckan, null).First()
));
PropertySortTransformer.SortProperties(ckan)));
return ExitOk;
}

Expand Down
4 changes: 4 additions & 0 deletions Netkan/Transformers/PropertySortTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
yield return new Metadata(sortedJson);
}

public static Metadata SortProperties(Metadata metadata)
=> new PropertySortTransformer().Transform(metadata, null)
.First();

private static double GetPropertySortOrder(string propertyName)
=> PropertySortOrder.TryGetValue(propertyName, out int sortOrder)
? sortOrder
Expand Down

0 comments on commit d43a2ac

Please sign in to comment.