mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-20 17:00:14 +02:00
added Thresholds parameter to CLI #15
This commit is contained in:
@@ -15,5 +15,8 @@ namespace CodeCoverageSummary
|
|||||||
|
|
||||||
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
|
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
|
||||||
public string Output { get; set; }
|
public string Output { get; set; }
|
||||||
|
|
||||||
|
[Option(longName: "thresholds", Required = false, HelpText = "Badge colour thresholds.", Default = "50 75")]
|
||||||
|
public string Thresholds { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,4 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
[assembly: SuppressMessage("Performance", "RCS1197:Optimize StringBuilder.Append/AppendLine call.", Scope = "type", Target = "~T:CodeCoverageSummary.Program")]
|
[assembly: SuppressMessage("Performance", "RCS1197:Optimize StringBuilder.Append/AppendLine call.", Scope = "type", Target = "~T:CodeCoverageSummary.Program")]
|
||||||
|
[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Scope = "member", Target = "~M:CodeCoverageSummary.Program.SetThresholds(System.String)")]
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ namespace CodeCoverageSummary
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private static double lowerThreshold = 0.5;
|
||||||
|
private static double upperThreshold = 0.75;
|
||||||
|
|
||||||
private static int Main(string[] args)
|
private static int Main(string[] args)
|
||||||
{
|
{
|
||||||
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
||||||
@@ -32,6 +35,10 @@ namespace CodeCoverageSummary
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// set health badge thresholds
|
||||||
|
if (!string.IsNullOrWhiteSpace(o.Thresholds))
|
||||||
|
SetThresholds(o.Thresholds);
|
||||||
|
|
||||||
// generate badge
|
// generate badge
|
||||||
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
string badgeUrl = o.Badge ? GenerateBadge(summary) : null;
|
||||||
|
|
||||||
@@ -158,14 +165,49 @@ namespace CodeCoverageSummary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetThresholds(string thresholds)
|
||||||
|
{
|
||||||
|
int lowerPercentage;
|
||||||
|
int upperPercentage = (int)(upperThreshold * 100);
|
||||||
|
int s = thresholds.IndexOf(" ");
|
||||||
|
if (s == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Threshold parameter set incorrectly.");
|
||||||
|
}
|
||||||
|
else if (s < 0)
|
||||||
|
{
|
||||||
|
if (!int.TryParse(thresholds, out lowerPercentage))
|
||||||
|
throw new ArgumentException("Threshold parameter set incorrectly.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!int.TryParse(thresholds.Substring(0, s), out lowerPercentage))
|
||||||
|
throw new ArgumentException("Threshold parameter set incorrectly.");
|
||||||
|
|
||||||
|
if (!int.TryParse(thresholds.Substring(s + 1), out upperPercentage))
|
||||||
|
throw new ArgumentException("Threshold parameter set incorrectly.");
|
||||||
|
}
|
||||||
|
lowerThreshold = lowerPercentage / 100.0;
|
||||||
|
upperThreshold = upperPercentage / 100.0;
|
||||||
|
|
||||||
|
if (lowerThreshold > 1.0)
|
||||||
|
lowerThreshold = 1.0;
|
||||||
|
|
||||||
|
if (lowerThreshold > upperThreshold)
|
||||||
|
upperThreshold = lowerThreshold + 0.1;
|
||||||
|
|
||||||
|
if (upperThreshold > 1.0)
|
||||||
|
upperThreshold = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
private static string GenerateBadge(CodeSummary summary)
|
private static string GenerateBadge(CodeSummary summary)
|
||||||
{
|
{
|
||||||
string colour;
|
string colour;
|
||||||
if (summary.LineRate < 0.5)
|
if (summary.LineRate < lowerThreshold)
|
||||||
{
|
{
|
||||||
colour = "critical";
|
colour = "critical";
|
||||||
}
|
}
|
||||||
else if (summary.LineRate < 0.75)
|
else if (summary.LineRate < upperThreshold)
|
||||||
{
|
{
|
||||||
colour = "yellow";
|
colour = "yellow";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"CodeCoverageSummary": {
|
"CodeCoverageSummary": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "../../../../coverage.gcovr.xml --format=md --badge=true"
|
"commandLineArgs": "../../../../coverage.cobertura.xml --format=md --badge=true --thresholds=\"80 90\""
|
||||||
},
|
},
|
||||||
"Docker": {
|
"Docker": {
|
||||||
"commandName": "Docker",
|
"commandName": "Docker",
|
||||||
|
|||||||
Reference in New Issue
Block a user