diff --git a/utils/github.test.ts b/utils/github.test.ts index 34fbf52..b3e8036 100644 --- a/utils/github.test.ts +++ b/utils/github.test.ts @@ -75,6 +75,10 @@ describe("parseGitHubURL", () => { expect(parseGitHubURL("http://github.com/owner/repo")).toBe("owner/repo"); }); + it("parses URLs without protocol", () => { + expect(parseGitHubURL("github.com/owner/repo")).toBe("owner/repo"); + }); + it("handles repos with dots in name", () => { expect(parseGitHubURL("owner/repo.name")).toBe("owner/repo.name"); }); diff --git a/utils/github.ts b/utils/github.ts index 429aa2e..2cffdcd 100644 --- a/utils/github.ts +++ b/utils/github.ts @@ -4,8 +4,14 @@ * @returns {string | null} The parsed repository name or null if the URL is invalid. */ export const parseGitHubURL = (input: string): string | null => { + // If the input looks like a github.com URL but is missing a protocol, + // prepend https:// so URL parsing succeeds. + const normalized = /^(?:www\.)?github\.com\//.test(input) + ? `https://${input.replace(/^https?:\/\//, "")}` + : input; + try { - const url = new URL(input); + const url = new URL(normalized); if (url.hostname === "github.com" || url.hostname === "www.github.com") { const pathSegments = url.pathname.split("/").filter(Boolean); if (pathSegments.length >= 2) {