Skip to content

Commit

Permalink
Fix color of code coverage based on the rate
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 9, 2024
1 parent 638ca67 commit 7a09f53
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/dotnet-releaser/ReleaserApp.Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ private async Task PublishCoverageToGist(IDevHosting devHosting, BuildInformatio
}

var rate = (int)Math.Round((double)coverage.Rate * 100);

// TODO: We could make many of these things configurable (colors, size of the badge, etc.)
var color = rate switch
{
>= 95 => "#4c1",
>= 90 => "#a3c51c",
>= 75 => "#dfb317",
_ => "#e05d44"
};

var svg = $"""
<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>
<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>
""";

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

0 comments on commit 7a09f53

Please sign in to comment.