Skip to content

Commit 75623a1

Browse files
1stvampTrigger.dev RepoOps
authored andcommitted
feat(observability-map): show the score as a circular gauge
The observability map report now shows its score as a circular gauge, a donut with the arc filled to the score and the number centred, in place of the plain `19/100` line. The gauge is a small pre-generated image referenced by the report comment; the `over N measured of M entry points` detail and the base-comparison line stay beneath it, and the number is still in the image's alt text. Mono-RevId: 321358a4d0c0900670bbf280148178385b8872b2
1 parent 82c1292 commit 75623a1

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎internal-packages/observability-map/src/report/prComment.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ describe("renderPrComment", () => {
3131
expect(renderPrComment(head, head).split("\n")[0]).toBe("<!-- observability-map-report -->");
3232
});
3333

34+
it("shows the score gauge image for a measured head", () => {
35+
const head = buildReport([scanFile("api.v1.a.ts", brokenSource)!], []);
36+
const out = renderPrComment(head, null);
37+
expect(out).toContain(`static-scorecard-assets/gauge-${head.global}.png`);
38+
expect(out).toContain('width="120" height="120"');
39+
expect(out).toContain(`score ${head.global} out of 100`);
40+
// The gauge replaces the bold headline; it must not also print alongside it.
41+
expect(out).not.toContain(`**${head.global}/100**`);
42+
// The measured-count detail stays.
43+
expect(out).toContain(`over ${head.measured} measured of`);
44+
});
45+
3446
it("says the comparison is unavailable when base is null", () => {
3547
const head = buildReport([scanFile("api.v1.a.ts", brokenSource)!], []);
3648
const out = renderPrComment(head, null);

‎internal-packages/observability-map/src/report/prComment.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ import {
1212
/** First line of every comment this job posts, so the upsert step can find its own comment again. */
1313
const MARKER = "<!-- observability-map-report -->";
1414

15+
/**
16+
* Pre-generated score gauges (`gauge-0.png` .. `gauge-100.png`), a donut for each whole-number score,
17+
* served from the static-scorecard-assets repo over GitHub Pages. Pages so the images are publicly
18+
* fetchable while that repo stays private, and PNG because Pages serves it `image/png`, which GitHub
19+
* renders through camo; an inline `<svg>` is stripped from a comment and would not render.
20+
*/
21+
const GAUGE_BASE = "https://triggerdotdev.github.io/static-scorecard-assets";
22+
23+
/**
24+
* The gauge image line, empty when the head has no numeric score. Shown at 120px from a 2x source,
25+
* and `<img>` rather than `![]()` so it can be sized. The score is still in the alt text and in the
26+
* scoreLine beneath it.
27+
*/
28+
function gaugeLine(head: MapReport): string[] {
29+
if (head.global === null) return [];
30+
return [
31+
`<img src="${GAUGE_BASE}/gauge-${head.global}.png" width="120" height="120" ` +
32+
`alt="Observability map score ${head.global} out of 100">`,
33+
"",
34+
];
35+
}
36+
1537
/**
1638
* The commit a comment was rendered for. Data rather than something the renderers read for themselves,
1739
* so they stay pure and a run with no commit context renders the same comment without the line.
@@ -62,10 +84,12 @@ const MAX_DELEGATED_ROUTES = 15;
6284
const failingIds = (e: ScoredEntry) => scoredFailures(e).map((c) => c.id);
6385

6486
function scoreLine(head: MapReport, base: MapReport | null): string {
87+
// No `N/100` here when measured: the gauge above the line already shows it, and printing it twice
88+
// is what this line used to do. The measured-count and base comparison stay.
6589
const headline =
6690
head.global === null
6791
? `not measured over ${head.measured} measured of ${head.entries.length} entry points`
68-
: `**${head.global}/100** over ${head.measured} measured of ${head.entries.length} entry points`;
92+
: `over ${head.measured} measured of ${head.entries.length} entry points`;
6993

7094
if (!base) return headline;
7195
// Head first: when this side has no score the headline already says so, and naming the base as the
@@ -302,6 +326,7 @@ export function renderPrComment(
302326
"## Observability map",
303327
"",
304328
...commitLines(commit),
329+
...gaugeLine(head),
305330
scoreLine(head, base),
306331
"",
307332
];

0 commit comments

Comments
 (0)