fix(ui): resolve skill source links through default branch

This commit is contained in:
Devin AI 2026-07-12 15:08:00 +00:00
parent 3e9e52042a
commit 7acaf3b2f6
3 changed files with 24 additions and 5 deletions

View file

@ -128,9 +128,15 @@ describe("getSourceLink", () => {
expect(getSourceLink({ source: "url", url: "https://example.com" })).toBe("https://example.com");
});
it("returns the repo url for a github git-subdir source", () => {
it("uses the default branch for a github git-subdir source", () => {
expect(getSourceLink({ source: "git-subdir", url: "https://github.com/org/repo", path: "plugins/x" })).toBe(
"https://github.com/org/repo",
"https://github.com/org/repo/tree/HEAD/plugins/x",
);
});
it("strips the clone suffix from a github git-subdir link", () => {
expect(getSourceLink({ source: "git-subdir", url: "https://github.com/org/repo.git", path: "plugins/x" })).toBe(
"https://github.com/org/repo/tree/HEAD/plugins/x",
);
});

View file

@ -239,6 +239,15 @@ export const getSourceDisplayText = (source: PluginSource): string => {
return "Unknown source";
};
const getGitHubSubdirLink = (repoUrl: string, path: string): string | null => {
const url = parseRepoUrl(repoUrl);
if (!url || url.hostname.replace(/^www\./, "") !== GITHUB_HOST) {
return null;
}
const repoPath = url.pathname.replace(/\.git\/?$/, "").replace(/\/+$/, "");
return `${url.origin}${repoPath}/tree/HEAD/${path}`;
};
/**
* Get clickable link for plugin source
*/
@ -246,7 +255,10 @@ export const getSourceLink = (source: PluginSource): string | null => {
if (source.source === "github" && source.repo) {
return `https://github.com/${source.repo}`;
}
if ((source.source === "url" || source.source === "git-subdir") && source.url) {
if (source.source === "git-subdir" && source.url) {
return source.path ? getGitHubSubdirLink(source.url, source.path) ?? source.url : source.url;
}
if (source.source === "url" && source.url) {
return source.url;
}
return null;

View file

@ -3,6 +3,7 @@ import { Badge, Text } from "@tremor/react";
import { Tooltip } from "antd";
import { CopyOutlined, LinkOutlined } from "@ant-design/icons";
import { Plugin } from "./claude_code_plugins/types";
import { getSourceLink } from "./claude_code_plugins/helpers";
import { StatusBadge } from "@/components/shared/table_cells";
export const skillHubColumns = (
@ -79,8 +80,8 @@ export const skillHubColumns = (
url = `https://github.com/${src.repo}`;
label = src.repo;
} else if (src?.source === "git-subdir" && src.url) {
url = src.path ? `${src.url}/tree/main/${src.path}` : src.url;
label = url.replace("https://github.com/", "");
url = getSourceLink(src);
label = (url ?? src.url).replace("https://github.com/", "");
} else if (src?.source === "url" && src.url) {
url = src.url;
label = src.url.replace(/^https?:\/\//, "");