diff --git a/Netkan/Extensions/JObjectExtensions.cs b/Netkan/Extensions/JObjectExtensions.cs index 7fe538d59..5f687c33e 100644 --- a/Netkan/Extensions/JObjectExtensions.cs +++ b/Netkan/Extensions/JObjectExtensions.cs @@ -81,13 +81,11 @@ public static void SafeMerge(this JObject jobject, string propertyName, JToken? } } - public static JToken? FromMessyList(T? first, IEnumerable? rest) where T: notnull + public static JToken? ToJValueOrJArray(this IEnumerable source) where T: notnull { - var items = (rest ?? Enumerable.Empty()) - .Append(first) - .OfType() - .Distinct() - .ToList(); + var items = source.OfType() + .Distinct() + .ToList(); return items.Count switch { 0 => null, diff --git a/Netkan/Transformers/GithubTransformer.cs b/Netkan/Transformers/GithubTransformer.cs index 664b91ae5..a7eb53b30 100644 --- a/Netkan/Transformers/GithubTransformer.cs +++ b/Netkan/Transformers/GithubTransformer.cs @@ -234,21 +234,22 @@ public static void SetRepoResources(GithubRepo repo, JObject resources) } } - private JToken? GetAuthors(GithubRepo repo, GithubRelease release) - => JObjectExtensions.FromMessyList( - release.Author, - repo.TraverseNodes(r => r.ParentRepo == null - ? null - : _api.GetRepo(new GithubRef($"#/ckan/github/{r.ParentRepo.FullName}", - false, _matchPreleases))) - .Reverse() - .SelectMany(r => r.Owner?.Type switch - { - userType => Enumerable.Repeat(r.Owner.Login, 1), - orgType => _api.getOrgMembers(r.Owner) - .Select(u => u.Login), - _ => Enumerable.Empty() - })); + private JToken? GetAuthors(GithubRepo repo, + GithubRelease release) + => repo.TraverseNodes(r => r.ParentRepo == null + ? null + : _api.GetRepo(new GithubRef($"#/ckan/github/{r.ParentRepo.FullName}", + false, _matchPreleases))) + .Reverse() + .SelectMany(r => r.Owner?.Type switch + { + userType => Enumerable.Repeat(r.Owner.Login, 1), + orgType => _api.getOrgMembers(r.Owner) + .Select(u => u.Login), + _ => Enumerable.Empty() + }) + .Append(release.Author) + .ToJValueOrJArray(); private const string userType = "User"; private const string orgType = "Organization"; diff --git a/Netkan/Transformers/SpacedockTransformer.cs b/Netkan/Transformers/SpacedockTransformer.cs index 3e70ee316..986ecba0f 100644 --- a/Netkan/Transformers/SpacedockTransformer.cs +++ b/Netkan/Transformers/SpacedockTransformer.cs @@ -186,8 +186,10 @@ private static void TryAddResourceURL(string identifier, JObject? resources, str } private static JToken? GetAuthors(SpacedockMod mod) - => JObjectExtensions.FromMessyList(mod.author, - mod.shared_authors?.Select(i => i.Username)); + => Enumerable.Repeat(mod.author, 1) + .Concat(mod.shared_authors?.Select(i => i.Username) + ?? Enumerable.Empty()) + .ToJValueOrJArray(); private static readonly Regex githubUrlPathPattern = new Regex("^/(?[^/]+)/(?[^/]+)",