From cf591e3acb29d25812899585dcdefa3c5b0df786 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 9 Jun 2020 16:40:37 -0500 Subject: [PATCH] Netkan warning for tags --- Netkan/CKAN-netkan.csproj | 1 + Netkan/Validators/CkanValidator.cs | 1 + Netkan/Validators/TagsValidator.cs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 Netkan/Validators/TagsValidator.cs diff --git a/Netkan/CKAN-netkan.csproj b/Netkan/CKAN-netkan.csproj index 76027aceb6..8bd024c8f3 100644 --- a/Netkan/CKAN-netkan.csproj +++ b/Netkan/CKAN-netkan.csproj @@ -164,6 +164,7 @@ + diff --git a/Netkan/Validators/CkanValidator.cs b/Netkan/Validators/CkanValidator.cs index 8c330319a1..df3d4903da 100644 --- a/Netkan/Validators/CkanValidator.cs +++ b/Netkan/Validators/CkanValidator.cs @@ -15,6 +15,7 @@ public CkanValidator(IHttpService downloader, IModuleService moduleService) _validators = new List { new IsCkanModuleValidator(), + new TagsValidator(), new InstallsFilesValidator(downloader, moduleService), new MatchesKnownGameVersionsValidator(), new ObeysCKANSchemaValidator(), diff --git a/Netkan/Validators/TagsValidator.cs b/Netkan/Validators/TagsValidator.cs new file mode 100644 index 0000000000..bb1786fc23 --- /dev/null +++ b/Netkan/Validators/TagsValidator.cs @@ -0,0 +1,26 @@ +using log4net; +using Newtonsoft.Json.Linq; + +using CKAN.NetKAN.Model; + +namespace CKAN.NetKAN.Validators +{ + internal sealed class TagsValidator : IValidator + { + public TagsValidator() { } + + public void Validate(Metadata metadata) + { + Log.Info("Validating that metadata has tags"); + + JObject json = metadata.Json(); + JArray tags = !json.ContainsKey("tags") ? null : (JArray)json["tags"]; + if (tags == null || tags.Count < 1) + { + Log.Warn("Tags not found, see https://github.com/KSP-CKAN/CKAN/wiki/Suggested-Tags"); + } + } + + private static readonly ILog Log = LogManager.GetLogger(typeof(TagsValidator)); + } +}