mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-14 14:10:14 +02:00
added health indicators #14
This commit is contained in:
@@ -13,6 +13,9 @@ namespace CodeCoverageSummary
|
||||
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
|
||||
public string Format { get; set; }
|
||||
|
||||
[Option(longName: "indicators", Required = false, HelpText = "Include package health indicators in the output - true or false.", Default = true)]
|
||||
public bool Indicators { get; set; }
|
||||
|
||||
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
|
||||
public string Output { get; set; }
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ namespace CodeCoverageSummary
|
||||
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "txt";
|
||||
output = GenerateTextOutput(summary, badgeUrl);
|
||||
output = GenerateTextOutput(summary, badgeUrl, o.Indicators);
|
||||
}
|
||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileExt = "md";
|
||||
output = GenerateMarkdownOutput(summary, badgeUrl);
|
||||
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -218,78 +218,75 @@ namespace CodeCoverageSummary
|
||||
return $"https://img.shields.io/badge/Code%20Coverage-{summary.LineRate * 100:N0}%25-{colour}?style=flat";
|
||||
}
|
||||
|
||||
private static string GenerateTextOutput(CodeSummary summary, string badgeUrl)
|
||||
private static string GenerateHealthIndicator(double rate)
|
||||
{
|
||||
if (rate < lowerThreshold)
|
||||
{
|
||||
return "❌";
|
||||
}
|
||||
else if (rate < upperThreshold)
|
||||
{
|
||||
return "➖";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "✔";
|
||||
}
|
||||
}
|
||||
|
||||
private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, bool indicators)
|
||||
{
|
||||
StringBuilder textOutput = new();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(badgeUrl))
|
||||
{
|
||||
textOutput.AppendLine(badgeUrl);
|
||||
}
|
||||
|
||||
textOutput.AppendLine($"Line Rate = {summary.LineRate * 100:N0}%, Lines Covered = {summary.LinesCovered} / {summary.LinesValid}")
|
||||
.AppendLine($"Branch Rate = {summary.BranchRate * 100:N0}%, Branches Covered = {summary.BranchesCovered} / {summary.BranchesValid}");
|
||||
|
||||
if (summary.Complexity % 1 == 0)
|
||||
{
|
||||
textOutput.AppendLine($"Complexity = {summary.Complexity}");
|
||||
}
|
||||
else
|
||||
{
|
||||
textOutput.AppendLine($"Complexity = {summary.Complexity:N4}");
|
||||
textOutput.AppendLine(badgeUrl)
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
foreach (CodeCoverage package in summary.Packages)
|
||||
{
|
||||
if (package.Complexity % 1 == 0)
|
||||
{
|
||||
textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity}");
|
||||
}
|
||||
else
|
||||
{
|
||||
textOutput.AppendLine($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%, Branch Rate = {package.BranchRate * 100:N0}%, Complexity = {package.Complexity:N4}");
|
||||
}
|
||||
textOutput.Append($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%")
|
||||
.Append($", Branch Rate = {package.BranchRate * 100:N0}%")
|
||||
.Append((package.Complexity % 1 == 0) ? $", Complexity = {package.Complexity}" : $", Complexity = {package.Complexity:N4}")
|
||||
.AppendLine(indicators ? $", {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
||||
}
|
||||
|
||||
textOutput.Append($"Summary: Line Rate = {summary.LineRate * 100:N0}% ({summary.LinesCovered} / {summary.LinesValid})")
|
||||
.Append($", Branch Rate = {summary.BranchRate * 100:N0}% ({summary.BranchesCovered} / {summary.BranchesValid})")
|
||||
.Append((summary.Complexity % 1 == 0) ? $", Complexity = {summary.Complexity}" : $", Complexity = {summary.Complexity:N4}")
|
||||
.AppendLine(indicators ? $", {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
||||
|
||||
return textOutput.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl)
|
||||
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators)
|
||||
{
|
||||
StringBuilder markdownOutput = new();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(badgeUrl))
|
||||
{
|
||||
markdownOutput.AppendLine($"");
|
||||
markdownOutput.AppendLine("");
|
||||
markdownOutput.AppendLine($"")
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
markdownOutput.AppendLine("Package | Line Rate | Branch Rate | Complexity")
|
||||
.AppendLine("-------- | --------- | ----------- | ----------");
|
||||
markdownOutput.Append("Package | Line Rate | Branch Rate | Complexity")
|
||||
.AppendLine(indicators ? " | Health" : string.Empty)
|
||||
.Append("-------- | --------- | ----------- | ----------")
|
||||
.AppendLine(indicators ? " | ------" : string.Empty);
|
||||
|
||||
foreach (CodeCoverage package in summary.Packages)
|
||||
{
|
||||
if (package.Complexity % 1 == 0)
|
||||
{
|
||||
markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity}");
|
||||
}
|
||||
else
|
||||
{
|
||||
markdownOutput.AppendLine($"{package.Name} | {package.LineRate * 100:N0}% | {package.BranchRate * 100:N0}% | {package.Complexity:N4}");
|
||||
}
|
||||
markdownOutput.Append($"{package.Name} | {package.LineRate * 100:N0}%")
|
||||
.Append($" | {package.BranchRate * 100:N0}%")
|
||||
.Append((package.Complexity % 1 == 0) ? $" | {package.Complexity}" : $" | {package.Complexity:N4}" )
|
||||
.AppendLine(indicators ? $" | {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
||||
}
|
||||
|
||||
markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid}) | ")
|
||||
.Append($"**{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid}) | ");
|
||||
|
||||
if (summary.Complexity % 1 == 0)
|
||||
{
|
||||
markdownOutput.AppendLine(summary.Complexity.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
markdownOutput.AppendLine(summary.Complexity.ToString("N4"));
|
||||
}
|
||||
markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid})")
|
||||
.Append($" | **{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid})")
|
||||
.Append((summary.Complexity % 1 == 0) ? $" | {summary.Complexity}" : $" | {summary.Complexity:N4}")
|
||||
.AppendLine(indicators ? $" | {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
||||
|
||||
return markdownOutput.ToString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user