Skip to content
2 changes: 1 addition & 1 deletion src/gitingest/parse_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _parse_url(url: str) -> dict[str, Any]:
url = url.split(" ")[0]
url = unquote(url) # Decode URL-encoded characters

if not url.startswith("https://"):
if not url.startswith(("https://", "http://")):
url = "https://" + url

# Extract domain and path
Expand Down
15 changes: 14 additions & 1 deletion src/gitingest/tests/test_parse_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from gitingest.parse_query import _parse_patterns, _parse_url, parse_query


def test_parse_url_valid() -> None:
def test_parse_url_valid_https() -> None:
test_cases = [
"https://github.com/user/repo",
"https://gitlab.com/user/repo",
Expand All @@ -17,6 +17,19 @@ def test_parse_url_valid() -> None:
assert result["url"] == url


def test_parse_url_valid_http() -> None:
test_cases = [
"http://github.com/user/repo",
"http://gitlab.com/user/repo",
"http://bitbucket.org/user/repo",
]
for url in test_cases:
result = _parse_url(url)
assert result["user_name"] == "user"
assert result["repo_name"] == "repo"
assert result["slug"] == "user-repo"


def test_parse_url_invalid() -> None:
url = "https://only-domain.com"
with pytest.raises(ValueError, match="Invalid repository URL"):
Expand Down
Loading