Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ Output Type - `console` (default), `file` or `both`.
Lower and upper threshold percentages for badge and health indicators, lower threshold can also be used to fail the action. Separate the values with a space and enclose them in quotes; default `'50 75'`.


### `collapsible`

Wrap the markdown table in collapsible `<details></details>` tags - `true` or `false` (default).


## Outputs

### Text Example
Expand All @@ -118,6 +123,23 @@ Minimum allowed line rate is 50%
>
> _Minimum allowed line rate is `50%`_

### Collapsible Markdown Example

> ![Code Coverage](https://img.shields.io/badge/Code%20Coverage-83%25-success?style=flat)
>
> <details>
> <summary>Code Coverage Summary</summary>
>
> Package | Line Rate | Branch Rate | Complexity | Health
> -------- | --------- | ----------- | ---------- | ------
> Company.Example | 83% | 69% | 671 | ✔
> Company.Example.Library | 27% | 100% | 11 | ❌
> **Summary** | **83%** (1212 / 1460) | **69%** (262 / 378) | 682 | ✔
>
> </details>
>
> _Minimum allowed line rate is `50%`_


## Usage

Expand Down Expand Up @@ -174,6 +196,7 @@ jobs:
indicators: true
output: both
thresholds: '60 80'
collapsible: true

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ inputs:
description: 'Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.'
required: false
default: '50 75'
collapsible:
description: 'Wrap the markdown table in collapsible details tags - true / false (default).'
required: false
default: 'false'
runs:
using: 'docker'
image: 'docker://ghcr.io/irongut/codecoveragesummary:v1.3.0'
Expand All @@ -62,3 +66,5 @@ runs:
- ${{ inputs.output }}
- '--thresholds'
- ${{ inputs.thresholds }}
- '--collapsible'
- ${{ inputs.collapsible }}
5 changes: 5 additions & 0 deletions src/CodeCoverageSummary/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ public class CommandLineOptions

[Option(longName: "thresholds", Required = false, HelpText = "Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.", Default = "50 75")]
public string Thresholds { get; set; }

[Option(longName: "collapsible", Required = false, HelpText = "Wrap the markdown table in collapsible details tags - true or false.", Default = "false")]
public string CollapsibleString { get; set; }

public bool Collapsible => CollapsibleString.Equals("true", StringComparison.OrdinalIgnoreCase);
}
}
17 changes: 15 additions & 2 deletions src/CodeCoverageSummary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static int Main(string[] args)
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
{
fileExt = "md";
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity);
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators, hideBranchRate, o.HideComplexity, o.Collapsible);
if (o.FailBelowThreshold)
output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}";
}
Expand Down Expand Up @@ -329,7 +329,7 @@ private static string GenerateTextOutput(CodeSummary summary, string badgeUrl, b
return textOutput.ToString();
}

private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity)
private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUrl, bool indicators, bool hideBranchRate, bool hideComplexity, bool collapsible)
{
StringBuilder markdownOutput = new();

Expand All @@ -339,6 +339,13 @@ private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUr
.AppendLine();
}

if (collapsible)
{
markdownOutput.AppendLine("<details>")
.AppendLine("<summary>Expand for details</summary>")
.AppendLine();
}

markdownOutput.Append("Package | Line Rate")
.Append(hideBranchRate ? string.Empty : " | Branch Rate")
.Append(hideComplexity ? string.Empty : " | Complexity")
Expand All @@ -361,6 +368,12 @@ private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUr
.Append(hideComplexity ? string.Empty : (summary.Complexity % 1 == 0) ? $" | **{summary.Complexity}**" : $" | **{summary.Complexity:N4}**")
.AppendLine(indicators ? $" | {GenerateHealthIndicator(summary.LineRate)}" : string.Empty);

if (collapsible)
{
markdownOutput.AppendLine()
.AppendLine("</details>");
}

return markdownOutput.ToString();
}
}
Expand Down
Loading