mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-19 00:10:14 +02:00
merge PR #25 Allow hiding Branch Rate + Complexity values in output
PR: Allow hiding Branch Rate + Complexity values in output
This commit is contained in:
+12
@@ -20,6 +20,14 @@ inputs:
|
|||||||
description: 'Output Format - markdown or text (default).'
|
description: 'Output Format - markdown or text (default).'
|
||||||
required: false
|
required: false
|
||||||
default: 'text'
|
default: 'text'
|
||||||
|
hide_branch_rate:
|
||||||
|
description: 'Hide Branch Rate values in the output - true / false (default).'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
hide_complexity:
|
||||||
|
description: 'Hide Complexity values in the output - true / false (default).'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
indicators:
|
indicators:
|
||||||
description: 'Include health indicators in the output - true (default) / false.'
|
description: 'Include health indicators in the output - true (default) / false.'
|
||||||
required: false
|
required: false
|
||||||
@@ -43,6 +51,10 @@ runs:
|
|||||||
- ${{ inputs.fail_below_min }}
|
- ${{ inputs.fail_below_min }}
|
||||||
- '--format'
|
- '--format'
|
||||||
- ${{ inputs.format }}
|
- ${{ inputs.format }}
|
||||||
|
- '--hidebranch'
|
||||||
|
- ${{ inputs.hide_branch_rate }}
|
||||||
|
- '--hidecomplexity'
|
||||||
|
- ${{ inputs.hide_complexity }}
|
||||||
- '--indicators'
|
- '--indicators'
|
||||||
- ${{ inputs.indicators }}
|
- ${{ inputs.indicators }}
|
||||||
- '--output'
|
- '--output'
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ namespace CodeCoverageSummary
|
|||||||
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
|
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
|
||||||
public string Format { get; set; }
|
public string Format { get; set; }
|
||||||
|
|
||||||
|
[Option(longName: "hidebranch", Required = false, HelpText = "Hide Branch Rate values in the output - true or false.", Default = "false")]
|
||||||
|
public string HideBranchString { get; set; }
|
||||||
|
|
||||||
|
public bool HideBranchRate => HideBranchString.Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
[Option(longName: "hidecomplexity", Required = false, HelpText = "Hide Complexity values in the output - true or false.", Default = "false")]
|
||||||
|
public string HideComplexityString { get; set; }
|
||||||
|
|
||||||
|
public bool HideComplexity => HideComplexityString.Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
[Option(longName: "indicators", Required = false, HelpText = "Include health indicators in the output - true or false.", Default = "true")]
|
[Option(longName: "indicators", Required = false, HelpText = "Include health indicators in the output - true or false.", Default = "true")]
|
||||||
public string IndicatorsString { get; set; }
|
public string IndicatorsString { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ namespace CodeCoverageSummary
|
|||||||
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fileExt = "txt";
|
fileExt = "txt";
|
||||||
output = GenerateTextOutput(summary, badgeUrl, o.Indicators);
|
output = GenerateTextOutput(summary, badgeUrl, o.Indicators, o.HideBranchRate, o.HideComplexity);
|
||||||
if (o.FailBelowThreshold)
|
if (o.FailBelowThreshold)
|
||||||
output += $"Minimum allowed line rate is {lowerThreshold * 100:N0}%{Environment.NewLine}";
|
output += $"Minimum allowed line rate is {lowerThreshold * 100:N0}%{Environment.NewLine}";
|
||||||
}
|
}
|
||||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fileExt = "md";
|
fileExt = "md";
|
||||||
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators);
|
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, o.HideBranchRate, o.HideComplexity);
|
||||||
if (o.FailBelowThreshold)
|
if (o.FailBelowThreshold)
|
||||||
output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}";
|
output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}";
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ namespace CodeCoverageSummary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, bool indicators)
|
private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity)
|
||||||
{
|
{
|
||||||
StringBuilder textOutput = new();
|
StringBuilder textOutput = new();
|
||||||
|
|
||||||
@@ -257,20 +257,20 @@ namespace CodeCoverageSummary
|
|||||||
foreach (CodeCoverage package in summary.Packages)
|
foreach (CodeCoverage package in summary.Packages)
|
||||||
{
|
{
|
||||||
textOutput.Append($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%")
|
textOutput.Append($"{package.Name}: Line Rate = {package.LineRate * 100:N0}%")
|
||||||
.Append($", Branch Rate = {package.BranchRate * 100:N0}%")
|
.Append(hideBranchRate ? string.Empty : $", Branch Rate = {package.BranchRate * 100:N0}%")
|
||||||
.Append((package.Complexity % 1 == 0) ? $", Complexity = {package.Complexity}" : $", Complexity = {package.Complexity:N4}")
|
.Append(hideComplexity ? string.Empty : (package.Complexity % 1 == 0) ? $", Complexity = {package.Complexity}" : $", Complexity = {package.Complexity:N4}")
|
||||||
.AppendLine(indicators ? $", {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
.AppendLine(indicators ? $", {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
textOutput.Append($"Summary: Line Rate = {summary.LineRate * 100:N0}% ({summary.LinesCovered} / {summary.LinesValid})")
|
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(hideBranchRate ? string.Empty : $", Branch Rate = {summary.BranchRate * 100:N0}% ({summary.BranchesCovered} / {summary.BranchesValid})")
|
||||||
.Append((summary.Complexity % 1 == 0) ? $", Complexity = {summary.Complexity}" : $", Complexity = {summary.Complexity:N4}")
|
.Append(hideComplexity ? string.Empty : (summary.Complexity % 1 == 0) ? $", Complexity = {summary.Complexity}" : $", Complexity = {summary.Complexity:N4}")
|
||||||
.AppendLine(indicators ? $", {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
.AppendLine(indicators ? $", {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
||||||
|
|
||||||
return textOutput.ToString();
|
return textOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators)
|
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity)
|
||||||
{
|
{
|
||||||
StringBuilder markdownOutput = new();
|
StringBuilder markdownOutput = new();
|
||||||
|
|
||||||
@@ -280,22 +280,26 @@ namespace CodeCoverageSummary
|
|||||||
.AppendLine();
|
.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
markdownOutput.Append("Package | Line Rate | Branch Rate | Complexity")
|
markdownOutput.Append("Package | Line Rate")
|
||||||
|
.Append(hideBranchRate ? string.Empty : " | Branch Rate")
|
||||||
|
.Append(hideComplexity ? string.Empty : " | Complexity")
|
||||||
.AppendLine(indicators ? " | Health" : string.Empty)
|
.AppendLine(indicators ? " | Health" : string.Empty)
|
||||||
.Append("-------- | --------- | ----------- | ----------")
|
.Append("-------- | ---------")
|
||||||
|
.Append(hideBranchRate ? string.Empty : " | -----------")
|
||||||
|
.Append(hideComplexity ? string.Empty : " | ----------")
|
||||||
.AppendLine(indicators ? " | ------" : string.Empty);
|
.AppendLine(indicators ? " | ------" : string.Empty);
|
||||||
|
|
||||||
foreach (CodeCoverage package in summary.Packages)
|
foreach (CodeCoverage package in summary.Packages)
|
||||||
{
|
{
|
||||||
markdownOutput.Append($"{package.Name} | {package.LineRate * 100:N0}%")
|
markdownOutput.Append($"{package.Name} | {package.LineRate * 100:N0}%")
|
||||||
.Append($" | {package.BranchRate * 100:N0}%")
|
.Append(hideBranchRate ? string.Empty : $" | {package.BranchRate * 100:N0}%")
|
||||||
.Append((package.Complexity % 1 == 0) ? $" | {package.Complexity}" : $" | {package.Complexity:N4}" )
|
.Append(hideComplexity ? string.Empty : (package.Complexity % 1 == 0) ? $" | {package.Complexity}" : $" | {package.Complexity:N4}" )
|
||||||
.AppendLine(indicators ? $" | {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
.AppendLine(indicators ? $" | {GenerateHealthIndicator(package.LineRate)}" : string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid})")
|
markdownOutput.Append($"**Summary** | **{summary.LineRate * 100:N0}%** ({summary.LinesCovered} / {summary.LinesValid})")
|
||||||
.Append($" | **{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid})")
|
.Append(hideBranchRate ? string.Empty : $" | **{summary.BranchRate * 100:N0}%** ({summary.BranchesCovered} / {summary.BranchesValid})")
|
||||||
.Append((summary.Complexity % 1 == 0) ? $" | {summary.Complexity}" : $" | {summary.Complexity:N4}")
|
.Append(hideComplexity ? string.Empty : (summary.Complexity % 1 == 0) ? $" | **{summary.Complexity}**" : $" | **{summary.Complexity:N4}**")
|
||||||
.AppendLine(indicators ? $" | {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
.AppendLine(indicators ? $" | {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);
|
||||||
|
|
||||||
return markdownOutput.ToString();
|
return markdownOutput.ToString();
|
||||||
|
|||||||
Reference in New Issue
Block a user