From d23cb2066c02d5ab8fc0610809461a71ba04123d Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Wed, 26 Jun 2024 14:45:40 -0500 Subject: [PATCH] Store GitHub Discussions links and display in UIs --- CKAN.schema | 5 ++++ Cmdline/Action/Show.cs | 5 ++++ Cmdline/Properties/Resources.resx | 1 + ConsoleUI/ModInfoScreen.cs | 7 +++++ ConsoleUI/Properties/Resources.resx | 2 ++ .../DelimeterSeparatedValueExporter.cs | 7 +++++ Core/Types/ResourcesDescriptor.cs | 20 ++++++++----- GUI/Controls/ModInfoTabs/Metadata.cs | 1 + GUI/Properties/Resources.resx | 1 + Netkan/Sources/Github/GithubRepo.cs | 3 ++ Netkan/Transformers/GithubTransformer.cs | 30 ++++++++++++------- Netkan/Transformers/SpacedockTransformer.cs | 12 +------- Spec.md | 1 + 13 files changed, 65 insertions(+), 30 deletions(-) diff --git a/CKAN.schema b/CKAN.schema index a3b98e4153..695ef63f17 100644 --- a/CKAN.schema +++ b/CKAN.schema @@ -201,6 +201,11 @@ "type" : "string", "format" : "uri" }, + "discussions" : { + "description" : "Mod discussions", + "type" : "string", + "format" : "uri" + }, "license" : { "description" : "Mod license", "type" : "string", diff --git a/Cmdline/Action/Show.cs b/Cmdline/Action/Show.cs index 23ac4e0845..bfbd12c05e 100644 --- a/Cmdline/Action/Show.cs +++ b/Cmdline/Action/Show.cs @@ -281,6 +281,11 @@ private int ShowMod(CkanModule module, ShowOptions opts) user.RaiseMessage(Properties.Resources.ShowBugTracker, Net.NormalizeUri(module.resources.bugtracker.ToString())); } + if (module.resources.discussions != null) + { + user.RaiseMessage(Properties.Resources.ShowDiscussions, + Net.NormalizeUri(module.resources.discussions.ToString())); + } if (module.resources.curse != null) { user.RaiseMessage(Properties.Resources.ShowCurse, diff --git a/Cmdline/Properties/Resources.resx b/Cmdline/Properties/Resources.resx index de8b154718..92be68fcb9 100644 --- a/Cmdline/Properties/Resources.resx +++ b/Cmdline/Properties/Resources.resx @@ -349,6 +349,7 @@ Try `ckan list` for a list of installed mods. SpaceDock: {0} Repository: {0} Bug tracker: {0} + Discussions: {0} Curse: {0} Store: {0} Steam store: {0} diff --git a/ConsoleUI/ModInfoScreen.cs b/ConsoleUI/ModInfoScreen.cs index b81707930c..a8370035dc 100644 --- a/ConsoleUI/ModInfoScreen.cs +++ b/ConsoleUI/ModInfoScreen.cs @@ -150,6 +150,13 @@ public ModInfoScreen(GameInstanceManager mgr, Registry registry, ChangePlan cp, th => LaunchURL(th, mod.resources.bugtracker) )); } + if (mod.resources.discussions != null) { + opts.Add(new ConsoleMenuOption( + Properties.Resources.ModInfoDiscussions, "", Properties.Resources.ModInfoDiscussionsTip, + true, + th => LaunchURL(th, mod.resources.discussions) + )); + } if (mod.resources.spacedock != null) { opts.Add(new ConsoleMenuOption( Properties.Resources.ModInfoSpaceDock, "", Properties.Resources.ModInfoSpaceDockTip, diff --git a/ConsoleUI/Properties/Resources.resx b/ConsoleUI/Properties/Resources.resx index d8aed13430..5e37fb506b 100644 --- a/ConsoleUI/Properties/Resources.resx +++ b/ConsoleUI/Properties/Resources.resx @@ -262,6 +262,8 @@ If you uninstall it, CKAN will not be able to re-install it. Open the repository URL in a browser Bugtracker Open the bug tracker URL in a browser + Discussions + Open the discussions URL in a browser SpaceDock Open the SpaceDock URL in a browser Curse diff --git a/Core/Exporters/DelimeterSeparatedValueExporter.cs b/Core/Exporters/DelimeterSeparatedValueExporter.cs index 66cd5e1acf..c172d7cb80 100644 --- a/Core/Exporters/DelimeterSeparatedValueExporter.cs +++ b/Core/Exporters/DelimeterSeparatedValueExporter.cs @@ -50,6 +50,7 @@ public void Export(IRegistryQuerier registry, Stream stream) "repository", "homepage", "bugtracker", + "discussions", "spacedock", "curse"); @@ -74,6 +75,7 @@ public void Export(IRegistryQuerier registry, Stream stream) WriteRepository(mod.Module.resources), WriteHomepage(mod.Module.resources), WriteBugtracker(mod.Module.resources), + WriteDiscussions(mod.Module.resources), WriteSpaceDock(mod.Module.resources), WriteCurse(mod.Module.resources)); } @@ -100,6 +102,11 @@ private string WriteBugtracker(ResourcesDescriptor resources) ? QuoteIfNecessary(resources.bugtracker.ToString()) : string.Empty; + private string WriteDiscussions(ResourcesDescriptor resources) + => resources != null && resources.discussions != null + ? QuoteIfNecessary(resources.discussions.ToString()) + : string.Empty; + private string WriteSpaceDock(ResourcesDescriptor resources) => resources != null && resources.spacedock != null ? QuoteIfNecessary(resources.spacedock.ToString()) diff --git a/Core/Types/ResourcesDescriptor.cs b/Core/Types/ResourcesDescriptor.cs index 4c2ec9b684..2fa01a95e5 100644 --- a/Core/Types/ResourcesDescriptor.cs +++ b/Core/Types/ResourcesDescriptor.cs @@ -26,35 +26,39 @@ public class ResourcesDescriptor [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri bugtracker; - [JsonProperty("ci", Order = 6, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("discussions", Order = 6, NullValueHandling = NullValueHandling.Ignore)] + [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] + public Uri discussions; + + [JsonProperty("ci", Order = 7, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri ci; - [JsonProperty("license", Order = 7, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("license", Order = 8, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri license; - [JsonProperty("manual", Order = 8, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("manual", Order = 9, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri manual; - [JsonProperty("metanetkan", Order = 9, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("metanetkan", Order = 10, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri metanetkan; - [JsonProperty("remote-avc", Order = 10, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("remote-avc", Order = 11, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri remoteAvc; - [JsonProperty("remote-swinfo", Order = 11, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("remote-swinfo", Order = 12, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri remoteSWInfo; - [JsonProperty("store", Order = 12, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("store", Order = 13, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri store; - [JsonProperty("steamstore", Order = 13, NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("steamstore", Order = 14, NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri steamstore; } diff --git a/GUI/Controls/ModInfoTabs/Metadata.cs b/GUI/Controls/ModInfoTabs/Metadata.cs index ef9fbcc63b..d12866c33d 100644 --- a/GUI/Controls/ModInfoTabs/Metadata.cs +++ b/GUI/Controls/ModInfoTabs/Metadata.cs @@ -78,6 +78,7 @@ public void UpdateModInfo(GUIMod gui_module) AddResourceLink(Properties.Resources.ModInfoCurseLabel, res.curse); AddResourceLink(Properties.Resources.ModInfoRepositoryLabel, res.repository); AddResourceLink(Properties.Resources.ModInfoBugTrackerLabel, res.bugtracker); + AddResourceLink(Properties.Resources.ModInfoDiscussionsLabel, res.discussions); AddResourceLink(Properties.Resources.ModInfoContinuousIntegrationLabel, res.ci); AddResourceLink(Properties.Resources.ModInfoLicenseLabel, res.license); AddResourceLink(Properties.Resources.ModInfoManualLabel, res.manual); diff --git a/GUI/Properties/Resources.resx b/GUI/Properties/Resources.resx index d502b0bb41..81dc61781d 100644 --- a/GUI/Properties/Resources.resx +++ b/GUI/Properties/Resources.resx @@ -280,6 +280,7 @@ If you suspect a bug in the client: https://github.com/KSP-CKAN/CKAN/issues/new/ Curse: Repository: Bug tracker: + Discussions: Continuous integration: Licence: Manual: diff --git a/Netkan/Sources/Github/GithubRepo.cs b/Netkan/Sources/Github/GithubRepo.cs index cbc6e62b79..b69ab463b1 100644 --- a/Netkan/Sources/Github/GithubRepo.cs +++ b/Netkan/Sources/Github/GithubRepo.cs @@ -34,6 +34,9 @@ public sealed class GithubRepo [JsonProperty("has_issues")] public bool HasIssues { get; set; } + [JsonProperty("has_discussions")] + public bool HasDiscussions { get; set; } + [JsonProperty("archived")] public bool Archived { get; set; } } diff --git a/Netkan/Transformers/GithubTransformer.cs b/Netkan/Transformers/GithubTransformer.cs index 00582dd384..5c4788d6ef 100644 --- a/Netkan/Transformers/GithubTransformer.cs +++ b/Netkan/Transformers/GithubTransformer.cs @@ -154,18 +154,9 @@ private Metadata TransformOne( { json["resources"] = new JObject(); } - - var resourcesJson = (JObject)json["resources"]; - - if (!string.IsNullOrWhiteSpace(ghRepo.Homepage)) + if (json["resources"] is JObject resourcesJson) { - resourcesJson.SafeAdd("homepage", ghRepo.Homepage); - } - - resourcesJson.SafeAdd("repository", ghRepo.HtmlUrl); - if (ghRepo.HasIssues) - { - resourcesJson.SafeAdd("bugtracker", $"{ghRepo.HtmlUrl}/issues"); + SetRepoResources(ghRepo, resourcesJson); } if (ghRelease != null) @@ -219,6 +210,23 @@ private Metadata TransformOne( } } + public static void SetRepoResources(GithubRepo repo, JObject resources) + { + resources.SafeAdd("repository", repo.HtmlUrl); + if (!string.IsNullOrWhiteSpace(repo.Homepage)) + { + resources.SafeAdd("homepage", repo.Homepage); + } + if (repo.HasIssues) + { + resources.SafeAdd("bugtracker", $"{repo.HtmlUrl}/issues"); + } + if (repo.HasDiscussions) + { + resources.SafeAdd("discussions", $"{repo.HtmlUrl}/discussions"); + } + } + private JToken getAuthors(GithubRepo repo, GithubRelease release) { // Start with the user that published the release diff --git a/Netkan/Transformers/SpacedockTransformer.cs b/Netkan/Transformers/SpacedockTransformer.cs index 2759feb1c8..a3d3106210 100644 --- a/Netkan/Transformers/SpacedockTransformer.cs +++ b/Netkan/Transformers/SpacedockTransformer.cs @@ -152,17 +152,7 @@ private Metadata TransformOne(Metadata metadata, JObject json, SpacedockMod sdMo $"#/ckan/github/{owner}/{repo}", false, false )); - if (sdMod.source_code != repoInfo.HtmlUrl) - { - TryAddResourceURL(metadata.Identifier, resourcesJson, "repository", repoInfo.HtmlUrl); - } - // Fall back to homepage from GitHub - TryAddResourceURL(metadata.Identifier, resourcesJson, "homepage", repoInfo.Homepage); - if (repoInfo.HasIssues) - { - // Set bugtracker if repo has issues list - TryAddResourceURL(metadata.Identifier, resourcesJson, "bugtracker", $"{repoInfo.HtmlUrl}/issues"); - } + GithubTransformer.SetRepoResources(repoInfo, resourcesJson); if (repoInfo.Archived) { Log.Warn("Repo is archived, consider freezing"); diff --git a/Spec.md b/Spec.md index 192c017cde..d11d7f9a22 100644 --- a/Spec.md +++ b/Spec.md @@ -640,6 +640,7 @@ are described. Unless specified otherwise, these are URLs: - `homepage` : The preferred landing page for the mod. - `bugtracker` : The mod's bugtracker if it exists. +- `discussions` : The mod's discussions page if it exists. - `license` : The mod's license. - `repository` : The repository where the module source can be found. - `ci` : (**v1.6**) Continuous Integration (e.g. Jenkins) Server where the module is being built. `x_ci` is an alias used in netkan.