refactor: rename URL validators to looksLikeRepoUrl

This commit is contained in:
statxc
2026-04-01 23:21:22 +00:00
parent 6a7830b07e
commit 9d89d74d70
5 changed files with 16 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import {
isGithubShorthand,
isGithubUrl,
looksLikeRepoUrl,
isHttpUrl,
normalizeGithubImportSource,
} from "../commands/client/company.js";
@@ -21,17 +21,17 @@ describe("isHttpUrl", () => {
});
});
describe("isGithubUrl", () => {
describe("looksLikeRepoUrl", () => {
it("matches GitHub URLs", () => {
expect(isGithubUrl("https://github.com/org/repo")).toBe(true);
expect(looksLikeRepoUrl("https://github.com/org/repo")).toBe(true);
});
it("rejects non-GitHub HTTP URLs", () => {
expect(isGithubUrl("https://example.com/foo")).toBe(false);
it("rejects URLs without owner/repo path", () => {
expect(looksLikeRepoUrl("https://example.com/foo")).toBe(false);
});
it("rejects local paths", () => {
expect(isGithubUrl("/tmp/my-company")).toBe(false);
expect(looksLikeRepoUrl("/tmp/my-company")).toBe(false);
});
});

View File

@@ -765,7 +765,7 @@ export function isHttpUrl(input: string): boolean {
return /^https?:\/\//i.test(input.trim());
}
export function isGithubUrl(input: string): boolean {
export function looksLikeRepoUrl(input: string): boolean {
try {
const url = new URL(input.trim());
if (url.protocol !== "https:") return false;
@@ -843,7 +843,7 @@ export function normalizeGithubImportSource(input: string, refOverride?: string)
});
}
if (!isGithubUrl(trimmed)) {
if (!looksLikeRepoUrl(trimmed)) {
throw new Error("GitHub source must be a GitHub or GitHub Enterprise URL, or owner/repo[/path] shorthand.");
}
if (!ref) {
@@ -1218,10 +1218,10 @@ export function registerCompanyCommands(program: Command): void {
| { type: "github"; url: string };
const treatAsLocalPath = !isHttpUrl(from) && await pathExists(from);
const isGithubSource = isGithubUrl(from) || (isGithubShorthand(from) && !treatAsLocalPath);
const isGithubSource = looksLikeRepoUrl(from) || (isGithubShorthand(from) && !treatAsLocalPath);
if (isHttpUrl(from) || isGithubSource) {
if (!isGithubUrl(from) && !isGithubShorthand(from)) {
if (!looksLikeRepoUrl(from) && !isGithubShorthand(from)) {
throw new Error(
"Only GitHub URLs and local paths are supported for import. " +
"Generic HTTP URLs are not supported. Use a GitHub or GitHub Enterprise URL (https://github.com/... or https://ghe.example.com/...) or a local directory path.",