Skip to content

Commit 0fcdf5f

Browse files
authored
Merge pull request #13 from tylercb/codex/fix-bug-in-codebase
Fix parseGitHubURL for URLs without protocol
2 parents 8dc1036 + 2b87523 commit 0fcdf5f

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

utils/github.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ describe("parseGitHubURL", () => {
7575
expect(parseGitHubURL("http://github.com/owner/repo")).toBe("owner/repo");
7676
});
7777

78+
it("parses URLs without protocol", () => {
79+
expect(parseGitHubURL("github.com/owner/repo")).toBe("owner/repo");
80+
});
81+
7882
it("handles repos with dots in name", () => {
7983
expect(parseGitHubURL("owner/repo.name")).toBe("owner/repo.name");
8084
});

utils/github.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
* @returns {string | null} The parsed repository name or null if the URL is invalid.
55
*/
66
export const parseGitHubURL = (input: string): string | null => {
7+
// If the input looks like a github.com URL but is missing a protocol,
8+
// prepend https:// so URL parsing succeeds.
9+
const normalized = /^(?:www\.)?github\.com\//.test(input)
10+
? `https://${input.replace(/^https?:\/\//, "")}`
11+
: input;
12+
713
try {
8-
const url = new URL(input);
14+
const url = new URL(normalized);
915
if (url.hostname === "github.com" || url.hostname === "www.github.com") {
1016
const pathSegments = url.pathname.split("/").filter(Boolean);
1117
if (pathSegments.length >= 2) {

0 commit comments

Comments
 (0)