Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions utils/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
8 changes: 7 additions & 1 deletion utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down