From 7e2435352ee4274a3e1a79ce599f888b97687d11 Mon Sep 17 00:00:00 2001 From: Charlie Humphreys Date: Wed, 22 Jul 2026 11:16:46 -0400 Subject: [PATCH] Bug #2279: add metric source URL remapping for github/mozilla-firefox/firefox URLs to searchfox URLs --- src/data/schemas.js | 2 ++ src/formatters/links.js | 20 ++++++++++++++++++-- tests/formatters.links.test.js | 26 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/data/schemas.js b/src/data/schemas.js index 04cc03e9d..7005f47ad 100644 --- a/src/data/schemas.js +++ b/src/data/schemas.js @@ -5,6 +5,7 @@ import { getBugURL, getBugLinkTitle, getSourceUrlTitle, + getSourceUrl, } from "../formatters/links"; import { getCodeSearchLink } from "../formatters/codesearch"; import { getPingReasons } from "../formatters/text"; @@ -76,6 +77,7 @@ export const METRIC_DEFINITION_SCHEMA = [ type: "link", helpText: "Where the source definition of the metric may be found (referencing the first commit in which it was introduced).", + linkFormatter: getSourceUrl, valueFormatter: getSourceUrlTitle, }, { diff --git a/src/formatters/links.js b/src/formatters/links.js index 0e4b4670a..b0020c266 100644 --- a/src/formatters/links.js +++ b/src/formatters/links.js @@ -27,12 +27,28 @@ export function getBugLinkTitle(ref) { return url.replace(/^http(s?):\/\//, ""); } +export function getSourceUrl(ref) { + if (ref.includes("github.com/mozilla-firefox/firefox")) { + return ref + .replace( + "github.com/mozilla-firefox/firefox/blob/", + "searchfox.org/firefox-main/rev/" + ) + .replace("#L", "#"); + } + return ref; +} + export function getSourceUrlTitle(url) { if (url.includes("github.com")) { return url.replace( /[^\d]+\/([^\d]+)\/([^\d]+)\/([^\d]+)\/([^/]+)\/(.*)/, - (_, orgName, repoName, _blob, _hash, path) => - `${orgName}/${repoName}/${path}` + (_, orgName, repoName, _blob, _hash, path) => { + if (orgName === "mozilla-firefox" && repoName === "firefox") { + return path.replace("#L", "#"); + } + return `${orgName}/${repoName}/${path}`; + } ); } return url; diff --git a/tests/formatters.links.test.js b/tests/formatters.links.test.js index 50555d70b..66dc6a316 100644 --- a/tests/formatters.links.test.js +++ b/tests/formatters.links.test.js @@ -1,4 +1,8 @@ -import { getBugLinkTitle, getSourceUrlTitle } from "../src/formatters/links"; +import { + getBugLinkTitle, + getSourceUrl, + getSourceUrlTitle, +} from "../src/formatters/links"; describe("Titles for bugzilla URLs", () => { it("works as expected", () => { @@ -34,6 +38,18 @@ describe("Titles for other issue tracker URLs", () => { }); }); +describe("Links for source URL", () => { + it("converts github.com/mozilla-firefox/firefox links to searchfox.org links", () => { + expect( + getSourceUrl( + "https://github.com/mozilla-firefox/firefox/blob/b52296d542b89092ffd707ca478a85ebf0f89ff5/accessible/metrics.yaml#L14" + ) + ).toBe( + "https://searchfox.org/firefox-main/rev/b52296d542b89092ffd707ca478a85ebf0f89ff5/accessible/metrics.yaml#14" + ); + }); +}); + describe("Titles for source definition", () => { it("works as expected", () => { expect( @@ -42,4 +58,12 @@ describe("Titles for source definition", () => { ) ).toBe("mozilla-mobile/fenix/app/metrics.yaml#L1234"); }); + + it("only shows path and changes line hash for mozilla-firefox/firefox", () => { + expect( + getSourceUrlTitle( + "https://github.com/mozilla-firefox/firefox/blob/b52296d542b89092ffd707ca478a85ebf0f89ff5/accessible/metrics.yaml#L14" + ) + ).toBe("accessible/metrics.yaml#14"); + }); });