Skip to content

Commit

Permalink
2248: Fix search path for application-services hosted libs
Browse files Browse the repository at this point in the history
  • Loading branch information
edugfilho committed Nov 12, 2024
1 parent f75b25f commit d7198d8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/MetadataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export let item = {};
function format(ref, formatter) {
return formatter ? formatter(ref, appName) : ref;
return formatter ? formatter(ref, appName, item) : ref;
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/data/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const METRIC_DEFINITION_SCHEMA = [
type: "link",
helpText:
"Finds uses of this metric using simple matching. Metrics used dynamically may not appear in the results, only metrics defined in the application will be found.",
linkFormatter: (metricId, appName) => getCodeSearchLink(appName, metricId),
linkFormatter: getCodeSearchLink,
},
];
export const METRIC_METADATA_SCHEMA = [
Expand Down
8 changes: 6 additions & 2 deletions src/formatters/codesearch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { camelCase, upperFirst, snakeCase } from "lodash";
import { getGithubRepoName } from "./links";

const searchfoxMap = {
fenix: "fenix",
Expand Down Expand Up @@ -48,7 +49,7 @@ const sourcegraphMap = {
mozilla_vpn: "mozilla-vpn-client",
};

export const getCodeSearchLink = (app, metric) => {
export const getCodeSearchLink = (metric, app, item) => {
const [category, name] = metric.split(/\.(?=[^.]+$)/);

// Generate all possible casings for a search query:
Expand Down Expand Up @@ -79,9 +80,12 @@ export const getCodeSearchLink = (app, metric) => {
/* eslint no-else-return: "error" */

if (searchfoxMap[app]) {
const repoName = getGithubRepoName(item.source_url);
const searchFoxPath =
repoName === "application-services" ? repoName : searchfoxMap[app];
return app === "firefox_desktop"
? `https://searchfox.org/mozilla-central/search?q=${allLanguagePatterns}&regexp=true`
: `https://searchfox.org/mozilla-mobile/search?q=${allLanguagePatterns}&path=${searchfoxMap[app]}&regexp=true`;
: `https://searchfox.org/mozilla-mobile/search?q=${allLanguagePatterns}&path=${searchFoxPath}&regexp=true`;
} else if (sourcegraphMap[app]) {
return (
`https://sourcegraph.com/search?q=repo:%5Egithub%5C.com%5C/%5BMm%5Dozilla%28.*%29%5C/` +
Expand Down
13 changes: 13 additions & 0 deletions src/formatters/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ export function getSourceUrlTitle(url) {
}
return url;
}

export function getGithubRepoName(url) {
const urlObj = new URL(url);
if (!urlObj.hostname.endsWith("github.com")) {
return null;
}
// Segments without falsy values that can be introduced by things like '//'
const pathSegments = urlObj.pathname.split("/").filter(Boolean);
if (pathSegments.length < 2) {
return null;
}
return pathSegments[1];
}

0 comments on commit d7198d8

Please sign in to comment.