mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-25 10:42:45 +00:00
23 lines
750 B
TypeScript
23 lines
750 B
TypeScript
import { parseGitHubRemoteUrl } from "@server/shared/git-remote";
|
|
|
|
export function parseGitHubRepoFromRemote(remoteUrl: string | null | undefined): string | null {
|
|
const trimmed = remoteUrl?.trim();
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
return parseGitHubRemoteUrl(trimmed)?.repo ?? null;
|
|
}
|
|
|
|
export function buildGitHubBranchTreeUrl(input: {
|
|
remoteUrl: string | null | undefined;
|
|
branch: string | null | undefined;
|
|
}): string | null {
|
|
const repo = parseGitHubRepoFromRemote(input.remoteUrl);
|
|
const branch = input.branch?.trim();
|
|
if (!repo || !branch || branch === "HEAD") {
|
|
return null;
|
|
}
|
|
const encodedBranch = branch.split("/").map(encodeURIComponent).join("/");
|
|
return `https://github.com/${repo}/tree/${encodedBranch}`;
|
|
}
|