From c330309da0c2f932ff70fa9cbb3f79daf0482577 Mon Sep 17 00:00:00 2001 From: Tyler Hanway Date: Wed, 4 Jun 2025 01:03:16 -0500 Subject: [PATCH] fix: support github URLs without protocol --- utils/github.test.ts | 4 ++++ utils/github.ts | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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) {