From 745b8f413acbafe354691b34eb4cc3d791772d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20T=C3=B6rcsv=C3=A1ri?= Date: Thu, 20 Aug 2026 11:49:56 +0200 Subject: [PATCH] version badge: display commit hashes GitHub-style (7 chars) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Staging tags are "staging-" — shorten any embedded full hash for display only; the corresponding-source link keeps the full sha, release tags pass through untouched. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_011gJ3M1RpeZLeNUUj8jKC4h --- .../src/components/VersionBadge.test.ts | 22 +++++++++++++++++++ .../src/components/VersionBadge.tsx | 9 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 web/standalone/src/components/VersionBadge.test.ts diff --git a/web/standalone/src/components/VersionBadge.test.ts b/web/standalone/src/components/VersionBadge.test.ts new file mode 100644 index 0000000..803263d --- /dev/null +++ b/web/standalone/src/components/VersionBadge.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from "vitest"; +import { shortBuildTag } from "./VersionBadge"; + +describe("shortBuildTag (version badge display)", () => { + it("shortens a staging tag's full sha to 7 chars", () => { + expect(shortBuildTag("staging-75bb0d7e4f2a9c1b8d3e6f0a2b4c6d8e0f1a2b3c")).toBe( + "staging-75bb0d7", + ); + }); + + it("shortens a bare full sha", () => { + expect(shortBuildTag("75bb0d7e4f2a9c1b8d3e6f0a2b4c6d8e0f1a2b3c")).toBe("75bb0d7"); + }); + + it("leaves release tags and dev untouched", () => { + expect(shortBuildTag("2.7.7")).toBe("2.7.7"); + expect(shortBuildTag("dev")).toBe("dev"); + // Short hex-ish fragments (< 12 chars) are not treated as hashes. + expect(shortBuildTag("demo-local")).toBe("demo-local"); + expect(shortBuildTag("beta-abc123")).toBe("beta-abc123"); + }); +}); diff --git a/web/standalone/src/components/VersionBadge.tsx b/web/standalone/src/components/VersionBadge.tsx index d3d0ead..d2fb04c 100644 --- a/web/standalone/src/components/VersionBadge.tsx +++ b/web/standalone/src/components/VersionBadge.tsx @@ -10,8 +10,15 @@ import { APP_GIT_SHA, APP_TAG, LANDING_URL, REPO_URL } from "@/lib/config"; * loaded editor. `fixed` keeps it viewport-anchored on every route; z-20 sits * under the editor's boot overlay (z-30) so it's hidden until the tool is up. */ +/** Display form of a build tag: any embedded full commit hash shortens to the + * GitHub-style 7 chars ("staging-<40 hex>" → "staging-abc1234"); release tags + * ("2.7.7") pass through untouched. Display only — links keep the full sha. */ +export function shortBuildTag(tag: string): string { + return tag.replace(/\b[0-9a-f]{12,40}\b/i, (h) => h.slice(0, 7)); +} + export function VersionBadge() { - const tag = APP_TAG ?? "dev"; + const tag = shortBuildTag(APP_TAG ?? "dev"); const versionUrl = APP_GIT_SHA ? `${REPO_URL}/commit/${APP_GIT_SHA}` : APP_TAG