Skip to content

Commit

Permalink
Merge #4111 Store GitHub Discussions links and display in UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jun 26, 2024
2 parents 2323dc7 + d23cb20 commit 24fbd16
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file.
- [Build] Linux: Improve desktop entries (#4092 by: mmvanheusden; reviewed: HebaruSan)
- [ConsoleUI] Install from .ckan file option for ConsoleUI (#4103 by: HebaruSan)
- [Build] Support icons from libraries for deb and rpm (#4104 by: HebaruSan)
- [Multiple] Store GitHub Discussions links and display in UIs (#4111 by: HebaruSan)

### Bugfixes

Expand Down
5 changes: 5 additions & 0 deletions CKAN.schema
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
"type" : "string",
"format" : "uri"
},
"discussions" : {
"description" : "Mod discussions",
"type" : "string",
"format" : "uri"
},
"license" : {
"description" : "Mod license",
"type" : "string",
Expand Down
5 changes: 5 additions & 0 deletions Cmdline/Action/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Cmdline/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ Try `ckan list` for a list of installed mods.</value></data>
<data name="ShowSpaceDock" xml:space="preserve"><value> SpaceDock: {0}</value></data>
<data name="ShowRepository" xml:space="preserve"><value> Repository: {0}</value></data>
<data name="ShowBugTracker" xml:space="preserve"><value> Bug tracker: {0}</value></data>
<data name="ShowDiscussions" xml:space="preserve"><value> Discussions: {0}</value></data>
<data name="ShowCurse" xml:space="preserve"><value> Curse: {0}</value></data>
<data name="ShowStore" xml:space="preserve"><value> Store: {0}</value></data>
<data name="ShowSteamStore" xml:space="preserve"><value> Steam store: {0}</value></data>
Expand Down
7 changes: 7 additions & 0 deletions ConsoleUI/ModInfoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions ConsoleUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ If you uninstall it, CKAN will not be able to re-install it.</value></data>
<data name="ModInfoRepositoryTip" xml:space="preserve"><value>Open the repository URL in a browser</value></data>
<data name="ModInfoBugtracker" xml:space="preserve"><value>Bugtracker</value></data>
<data name="ModInfoBugtrackerTip" xml:space="preserve"><value>Open the bug tracker URL in a browser</value></data>
<data name="ModInfoDiscussions" xml:space="preserve"><value>Discussions</value></data>
<data name="ModInfoDiscussionsTip" xml:space="preserve"><value>Open the discussions URL in a browser</value></data>
<data name="ModInfoSpaceDock" xml:space="preserve"><value>SpaceDock</value></data>
<data name="ModInfoSpaceDockTip" xml:space="preserve"><value>Open the SpaceDock URL in a browser</value></data>
<data name="ModInfoCurse" xml:space="preserve"><value>Curse</value></data>
Expand Down
7 changes: 7 additions & 0 deletions Core/Exporters/DelimeterSeparatedValueExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void Export(IRegistryQuerier registry, Stream stream)
"repository",
"homepage",
"bugtracker",
"discussions",
"spacedock",
"curse");

Expand All @@ -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));
}
Expand All @@ -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())
Expand Down
20 changes: 12 additions & 8 deletions Core/Types/ResourcesDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/ModInfoTabs/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions GUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ If you suspect a bug in the client: https://github.com/KSP-CKAN/CKAN/issues/new/
<data name="ModInfoCurseLabel" xml:space="preserve"><value>Curse:</value></data>
<data name="ModInfoRepositoryLabel" xml:space="preserve"><value>Repository:</value></data>
<data name="ModInfoBugTrackerLabel" xml:space="preserve"><value>Bug tracker:</value></data>
<data name="ModInfoDiscussionsLabel" xml:space="preserve"><value>Discussions:</value></data>
<data name="ModInfoContinuousIntegrationLabel" xml:space="preserve"><value>Continuous integration:</value></data>
<data name="ModInfoLicenseLabel" xml:space="preserve"><value>Licence:</value></data>
<data name="ModInfoManualLabel" xml:space="preserve"><value>Manual:</value></data>
Expand Down
3 changes: 3 additions & 0 deletions Netkan/Sources/Github/GithubRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
30 changes: 19 additions & 11 deletions Netkan/Transformers/GithubTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions Netkan/Transformers/SpacedockTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 24fbd16

Please sign in to comment.