Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

712 B
Raw Blame
export const GITHUB_OWNER_PATTERN = /^[a-zA-Z0-9-]+$/;
export const GITEA_OWNER_PATTERN = /^[a-zA-Z0-9_.-]+$/;
const NAME_PATTERN = /^[a-zA-Z0-9._-]+$/;

export type RepositoryPath = {
  owner: string;
  name: string;
};

export function parseRepositoryPath(
  value: string,
  ownerPattern: RegExp,
): RepositoryPath | null {
  const parts = value
    .trim()
    .replace(/^\/+|\/+$/g, "")
    .split("/");
  if (parts.length !== 2) return null;
  const [owner = "", name = ""] = parts;
  if (!ownerPattern.test(owner) || !NAME_PATTERN.test(name)) return null;
  return { owner, name };
}

export function formatRepositoryPath(owner: string, name: string) {
  return owner && name ? `${owner}/${name}` : "";
}