@@ -52,15 +52,39 @@ def format_coverage_precision(coverage: float | None, precision: int):
5252 return ("%%.%sf" % precision ) % coverage
5353
5454
55- def get_bundle_badge (bundle_size_bytes : int , precision : int ):
55+ def get_bundle_badge (bundle_size_bytes : int | None , precision : int ):
56+ if bundle_size_bytes is None :
57+ # Returns text 'unknown' instead of bundle size
58+ return """<svg xmlns="http://www.w3.org/2000/svg" width="106" height="20">
59+ <linearGradient id="CodecovBadgeGradient" x2="0" y2="100%">
60+ <stop offset="0" stop-color="#bbb" stop-opacity=".1" />
61+ <stop offset="1" stop-opacity=".1" />
62+ </linearGradient>
63+ <mask id="CodecovBadgeMask106px">
64+ <rect width="106" height="20" rx="3" fill="#fff" />
65+ </mask>
66+ <g mask="url(#CodecovBadgeMask106px)">
67+ <path fill="#555" d="M0 0h47v20H0z" />
68+ <path fill="#2C2433" d="M47 0h59v20H47z" />
69+ <path fill="url(#CodecovBadgeGradient)" d="M0 0h106v20H0z" />
70+ </g>
71+ <g fill="#fff" text-anchor="left" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
72+ <text x="5" y="15" fill="#010101" fill-opacity=".3">bundle</text>
73+ <text x="5" y="14">bundle</text>
74+ <text x="52" y="15" fill="#010101" fill-opacity=".3">unknown</text>
75+ <text x="52" y="14">unknown</text>
76+ </g>
77+ </svg>
78+ """
79+
5680 bundle_size_string = format_bundle_bytes (bundle_size_bytes , precision )
5781 char_width = 7 # approximate, looks good on all reasonable inputs
5882 width_in_pixels = len (bundle_size_string ) * char_width
5983 static_width = 57 # width of static elements in the svg (text + margins)
6084
6185 width = static_width + width_in_pixels
6286
63- return f""" <svg xmlns="http://www.w3.org/2000/svg" width="{ width } " height="20">
87+ return f"""<svg xmlns="http://www.w3.org/2000/svg" width="{ width } " height="20">
6488 <linearGradient id="CodecovBadgeGradient" x2="0" y2="100%">
6589 <stop offset="0" stop-color="#bbb" stop-opacity=".1" />
6690 <stop offset="1" stop-opacity=".1" />
@@ -70,7 +94,7 @@ def get_bundle_badge(bundle_size_bytes: int, precision: int):
7094 </mask>
7195 <g mask="url(#CodecovBadgeMask{ width } px)">
7296 <path fill="#555" d="M0 0h47v20H0z" />
73- <path fill="#2C2433" d="M47 0h{ width - static_width + 10 } v20H47z" />
97+ <path fill="#2C2433" d="M47 0h{ width_in_pixels + 10 } v20H47z" />
7498 <path fill="url(#CodecovBadgeGradient)" d="M0 0h{ width } v20H0z" />
7599 </g>
76100 <g fill="#fff" text-anchor="left" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
0 commit comments