(undefined);
@@ -254,6 +282,7 @@ const PanelGroup = ({
) : (
@@ -302,6 +332,7 @@ const PanelGroup = ({
onClose={() => setSelectedFile(undefined)}
selectedMatchIndex={selectedMatchIndex}
onSelectedMatchIndexChange={setSelectedMatchIndex}
+ repoUrlTemplates={repoUrlTemplates}
/>
diff --git a/packages/web/src/lib/schemas.ts b/packages/web/src/lib/schemas.ts
index f401b765..9fcb2b0d 100644
--- a/packages/web/src/lib/schemas.ts
+++ b/packages/web/src/lib/schemas.ts
@@ -68,6 +68,7 @@ export const zoektSearchResponseSchema = z.object({
// Set if `whole` is true.
Content: z.string().optional(),
})).nullable(),
+ RepoURLs: z.record(z.string(), z.string()),
}),
});
diff --git a/packages/web/src/lib/utils.ts b/packages/web/src/lib/utils.ts
index c2a46df3..3e6211bb 100644
--- a/packages/web/src/lib/utils.ts
+++ b/packages/web/src/lib/utils.ts
@@ -4,6 +4,7 @@ import githubLogo from "../../public/github.svg";
import gitlabLogo from "../../public/gitlab.svg";
import giteaLogo from "../../public/gitea.svg";
import { ServiceError } from "./serviceError";
+import { Repository } from "./types";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
@@ -31,64 +32,53 @@ export const createPathWithQueryParams = (path: string, ...queryParams: [string,
type CodeHostInfo = {
type: "github" | "gitlab" | "gitea";
- repoName: string;
+ displayName: string;
costHostName: string;
repoLink: string;
icon: string;
iconClassName?: string;
}
-export const getRepoCodeHostInfo = (repoName: string): CodeHostInfo | undefined => {
- if (repoName.startsWith("github.com")) {
- return {
- type: "github",
- repoName: repoName.substring("github.com/".length),
- costHostName: "GitHub",
- repoLink: `https://${repoName}`,
- icon: githubLogo,
- iconClassName: "dark:invert",
- }
- }
-
- if (repoName.startsWith("gitlab.com")) {
- return {
- type: "gitlab",
- repoName: repoName.substring("gitlab.com/".length),
- costHostName: "GitLab",
- repoLink: `https://${repoName}`,
- icon: gitlabLogo,
- }
+export const getRepoCodeHostInfo = (repo?: Repository): CodeHostInfo | undefined => {
+ if (!repo) {
+ return undefined;
}
- if (repoName.startsWith("gitea.com")) {
- return {
- type: "gitea",
- repoName: repoName.substring("gitea.com/".length),
- costHostName: "Gitea",
- repoLink: `https://${repoName}`,
- icon: giteaLogo,
- }
+ const hostType = repo.RawConfig ? repo.RawConfig['web-url-type'] : undefined;
+ if (!hostType) {
+ return undefined;
}
- return undefined;
-}
+ const url = new URL(repo.URL);
+ const displayName = url.pathname.slice(1);
-export const getCodeHostFilePreviewLink = (repoName: string, filePath: string, branch: string = "HEAD"): string | undefined => {
- const info = getRepoCodeHostInfo(repoName);
-
- if (info?.type === "github") {
- return `${info.repoLink}/blob/${branch}/${filePath}`;
+ switch (hostType) {
+ case 'github':
+ return {
+ type: "github",
+ displayName: displayName,
+ costHostName: "GitHub",
+ repoLink: repo.URL,
+ icon: githubLogo,
+ iconClassName: "dark:invert",
+ }
+ case 'gitlab':
+ return {
+ type: "gitlab",
+ displayName: displayName,
+ costHostName: "GitLab",
+ repoLink: repo.URL,
+ icon: gitlabLogo,
+ }
+ case 'gitea':
+ return {
+ type: "gitea",
+ displayName: displayName,
+ costHostName: "Gitea",
+ repoLink: repo.URL,
+ icon: giteaLogo,
+ }
}
-
- if (info?.type === "gitlab") {
- return `${info.repoLink}/-/blob/${branch}/${filePath}`;
- }
-
- if (info?.type === "gitea") {
- return `${info.repoLink}/src/branch/${branch}/${filePath}`;
- }
-
- return undefined;
}
export const isServiceError = (data: unknown): data is ServiceError => {