Skip to content

Commit 7a09f53

Browse files
committed
Fix color of code coverage based on the rate
1 parent 638ca67 commit 7a09f53

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/dotnet-releaser/ReleaserApp.Coverage.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ private async Task PublishCoverageToGist(IDevHosting devHosting, BuildInformatio
2525
}
2626

2727
var rate = (int)Math.Round((double)coverage.Rate * 100);
28+
29+
// TODO: We could make many of these things configurable (colors, size of the badge, etc.)
30+
var color = rate switch
31+
{
32+
>= 95 => "#4c1",
33+
>= 90 => "#a3c51c",
34+
>= 75 => "#dfb317",
35+
_ => "#e05d44"
36+
};
37+
2838
var svg = $"""
29-
<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="99" height="20" fill="#555"/><rect rx="3" x="63" width="36" height="20" fill="#97CA00"/><path fill="#97CA00" d="M63 0h4v20h-4z"/><rect rx="3" width="99" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="32.5" y="15" fill="#010101" fill-opacity=".3">coverage</text><text x="32.5" y="14">coverage</text><text x="80" y="15" fill="#010101" fill-opacity=".3">{rate:##}%</text><text x="80" y="14">{rate:##}%</text></g></svg>
39+
<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="99" height="20" fill="#555"/><rect rx="3" x="63" width="36" height="20" fill="{color}"/><path fill="{color}" d="M63 0h4v20h-4z"/><rect rx="3" width="99" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="32.5" y="15" fill="#010101" fill-opacity=".3">coverage</text><text x="32.5" y="14">coverage</text><text x="80" y="15" fill="#010101" fill-opacity=".3">{rate:##}%</text><text x="80" y="14">{rate:##}%</text></g></svg>
3040
""";
3141

3242
var fileName = $"dotnet-releaser-coverage-badge-{_config.GitHub.User}-{_config.GitHub.Repo}.svg";

0 commit comments

Comments
 (0)