From 3b654eb5c8996cbe510ff4a4915ba4142aa5785b Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Mon, 21 Jan 2019 21:00:50 -0600 Subject: [PATCH] Get license from GitHub --- Netkan/Sources/Github/GithubRepo.cs | 9 +++++++++ Netkan/Transformers/GithubTransformer.cs | 5 +++++ Spec.md | 1 + 3 files changed, 15 insertions(+) diff --git a/Netkan/Sources/Github/GithubRepo.cs b/Netkan/Sources/Github/GithubRepo.cs index 0f13baf20c..967a3f07c4 100644 --- a/Netkan/Sources/Github/GithubRepo.cs +++ b/Netkan/Sources/Github/GithubRepo.cs @@ -18,5 +18,14 @@ public sealed class GithubRepo [JsonProperty("homepage")] public string Homepage { get; set; } + + [JsonProperty("license")] + public GithubLicense License { get; set; } + } + + public class GithubLicense + { + [JsonProperty("spdx_id")] + public string Id; } } diff --git a/Netkan/Transformers/GithubTransformer.cs b/Netkan/Transformers/GithubTransformer.cs index 01ca4f87d2..6741a6a8a4 100644 --- a/Netkan/Transformers/GithubTransformer.cs +++ b/Netkan/Transformers/GithubTransformer.cs @@ -66,6 +66,11 @@ public Metadata Transform(Metadata metadata) if (!string.IsNullOrWhiteSpace(ghRepo.Description)) json.SafeAdd("abstract", ghRepo.Description); + // GitHub says NOASSERTION if it can't figure out the repo's license + if (!string.IsNullOrWhiteSpace(ghRepo.License?.Id) + && ghRepo.License.Id != "NOASSERTION") + json.SafeAdd("license", ghRepo.License.Id); + if (!string.IsNullOrWhiteSpace(ghRepo.Homepage)) resourcesJson.SafeAdd("homepage", ghRepo.Homepage); diff --git a/Spec.md b/Spec.md index 011f55797e..b6b6259528 100644 --- a/Spec.md +++ b/Spec.md @@ -648,6 +648,7 @@ For example: `#/ckan/github/pjf/DogeCoinFlag`. When used, the following fields will be auto-filled if not already present: - `name` +- `license` - `abstract` - `author` - `version`