Skip to content

Instantly share code, notes, and snippets.

@veigr
Last active October 31, 2018 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veigr/4ae598905c62720d7279c9c7eec222fd to your computer and use it in GitHub Desktop.
Save veigr/4ae598905c62720d7279c9c7eec222fd to your computer and use it in GitHub Desktop.
jaredsburrows/gradle-license-plugin JSON Report to Markdown
using System.IO;
using Newtonsoft.Json;
using System.Linq;
namespace GradleLicensePluginReportJsonToMd
{
public static class Parser
{
public static string ParseToMd(string path)
{
if (!File.Exists(path)) return "";
var json = File.ReadAllText(path);
var report = JsonConvert.DeserializeObject<Library[]>(json);
return report.ToMd();
}
}
public static class Extensions
{
public static string ToMd(this Library[] libs)
{
return string.Join("\r\n\r\n", libs.Select(x => x.ToMd()));
}
private static string ToMd(this Library lib)
{
if (string.IsNullOrWhiteSpace(lib.url))
return $"* {lib.project} \r\n"
+ $"_License: {lib.licenses.ToMd()}_";
else
return $"* [{lib.project}]({lib.url}) \r\n"
+ $"_License: {lib.licenses.ToMd()}_";
}
private static string ToMd(this License[] licenses)
{
return string.Join(", ", licenses.Select(x => x.ToMd()));
}
private static string ToMd(this License license)
{
if (string.IsNullOrWhiteSpace(license.license_url))
return license.license;
else
return $"[{license.license}]({license.license_url})";
}
}
public class Library
{
public string project { get; set; }
public string description { get; set; }
public string version { get; set; }
public string[] developers { get; set; }
public string url { get; set; }
public string year { get; set; }
public License[] licenses { get; set; }
}
public class License
{
public string license { get; set; }
public string license_url { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment