From acfd9158d6b235d684c34e1f0614934eb0f377d0 Mon Sep 17 00:00:00 2001 From: joydeep049 Date: Wed, 1 Jan 2025 19:17:40 +0530 Subject: [PATCH 1/8] fix: http error --- src/gitingest/parse_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index 18a78e9a..f21011be 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -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://") and not url.startswith("http://"): url = "https://" + url # Extract domain and path From eba490d384fcabbbb6598963506b2473303cce41 Mon Sep 17 00:00:00 2001 From: Joydeep Tripathy <113792434+joydeep049@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:34:50 +0530 Subject: [PATCH 2/8] Update src/gitingest/parse_query.py Co-authored-by: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> --- src/gitingest/parse_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index f21011be..859cafb2 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -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://") and not url.startswith("http://"): + if not url.startswith(("https://", "http://")): url = "https://" + url # Extract domain and path From 747d1f8521b1088b27b8cec84f8cb336decd394b Mon Sep 17 00:00:00 2001 From: joydeep049 Date: Thu, 2 Jan 2025 01:03:23 +0530 Subject: [PATCH 3/8] feat: added test --- src/gitingest/parse_query.py | 3 ++- src/gitingest/tests/test_parse_query.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index f21011be..9bde9c60 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -116,6 +116,7 @@ def _parse_url(url: str) -> dict[str, Any]: _id = str(uuid.uuid4()) slug = f"{user_name}-{repo_name}" + final_url = f"https://{domain}/{user_name}/{repo_name}" if url.startswith("https://") else f"http://{domain}/{user_name}/{repo_name}" parsed = { "user_name": user_name, "repo_name": repo_name, @@ -124,7 +125,7 @@ def _parse_url(url: str) -> dict[str, Any]: "commit": None, "subpath": "/", "local_path": f"{TMP_BASE_PATH}/{_id}/{slug}", - "url": f"https://{domain}/{user_name}/{repo_name}", + "url": final_url, "slug": slug, "id": _id, } diff --git a/src/gitingest/tests/test_parse_query.py b/src/gitingest/tests/test_parse_query.py index 8ce3ff00..df908ac1 100644 --- a/src/gitingest/tests/test_parse_query.py +++ b/src/gitingest/tests/test_parse_query.py @@ -9,6 +9,7 @@ def test_parse_url_valid() -> None: "https://github.com/user/repo", "https://gitlab.com/user/repo", "https://bitbucket.org/user/repo", + "http://github.com/user/repo", ] for url in test_cases: result = _parse_url(url) From 861c01f9a358874c628823a4e0f2e41b1d2d366e Mon Sep 17 00:00:00 2001 From: joydeep049 Date: Thu, 2 Jan 2025 01:10:08 +0530 Subject: [PATCH 4/8] fix: black error --- src/gitingest/parse_query.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index 3b22b700..5f871700 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -116,7 +116,11 @@ def _parse_url(url: str) -> dict[str, Any]: _id = str(uuid.uuid4()) slug = f"{user_name}-{repo_name}" - final_url = f"https://{domain}/{user_name}/{repo_name}" if url.startswith("https://") else f"http://{domain}/{user_name}/{repo_name}" + final_url = ( + f"https://{domain}/{user_name}/{repo_name}" + if url.startswith("https://") + else f"http://{domain}/{user_name}/{repo_name}" + ) parsed = { "user_name": user_name, "repo_name": repo_name, From fad65fe188f56fb5ff18260cbc01db1a37a42794 Mon Sep 17 00:00:00 2001 From: Romain Courtois Date: Thu, 2 Jan 2025 00:43:09 +0100 Subject: [PATCH 5/8] Update src/gitingest/parse_query.py Co-authored-by: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> --- src/gitingest/parse_query.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index 5f871700..ccab062a 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -116,11 +116,6 @@ def _parse_url(url: str) -> dict[str, Any]: _id = str(uuid.uuid4()) slug = f"{user_name}-{repo_name}" - final_url = ( - f"https://{domain}/{user_name}/{repo_name}" - if url.startswith("https://") - else f"http://{domain}/{user_name}/{repo_name}" - ) parsed = { "user_name": user_name, "repo_name": repo_name, From bb52882a803dbada68fa651cca566a7b1e04f6f5 Mon Sep 17 00:00:00 2001 From: Romain Courtois Date: Thu, 2 Jan 2025 00:43:19 +0100 Subject: [PATCH 6/8] Update src/gitingest/parse_query.py Co-authored-by: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> --- src/gitingest/parse_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitingest/parse_query.py b/src/gitingest/parse_query.py index ccab062a..859cafb2 100644 --- a/src/gitingest/parse_query.py +++ b/src/gitingest/parse_query.py @@ -124,7 +124,7 @@ def _parse_url(url: str) -> dict[str, Any]: "commit": None, "subpath": "/", "local_path": f"{TMP_BASE_PATH}/{_id}/{slug}", - "url": final_url, + "url": f"https://{domain}/{user_name}/{repo_name}", "slug": slug, "id": _id, } From f5b75284ddfad9c10c5931d29f6805e75c72b379 Mon Sep 17 00:00:00 2001 From: joydeep049 Date: Thu, 2 Jan 2025 09:36:36 +0530 Subject: [PATCH 7/8] test: added separate test for http --- src/gitingest/tests/test_parse_query.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gitingest/tests/test_parse_query.py b/src/gitingest/tests/test_parse_query.py index df908ac1..6176a913 100644 --- a/src/gitingest/tests/test_parse_query.py +++ b/src/gitingest/tests/test_parse_query.py @@ -4,12 +4,11 @@ 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", "https://bitbucket.org/user/repo", - "http://github.com/user/repo", ] for url in test_cases: result = _parse_url(url) @@ -17,6 +16,17 @@ def test_parse_url_valid() -> None: assert result["repo_name"] == "repo" 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" From a419f150b13dc3a66be41a0c48b48ec9d4d8baf4 Mon Sep 17 00:00:00 2001 From: joydeep049 Date: Thu, 2 Jan 2025 09:56:36 +0530 Subject: [PATCH 8/8] fix: linter error --- src/gitingest/tests/test_parse_query.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitingest/tests/test_parse_query.py b/src/gitingest/tests/test_parse_query.py index 6176a913..b6b20389 100644 --- a/src/gitingest/tests/test_parse_query.py +++ b/src/gitingest/tests/test_parse_query.py @@ -16,6 +16,7 @@ def test_parse_url_valid_https() -> None: assert result["repo_name"] == "repo" assert result["url"] == url + def test_parse_url_valid_http() -> None: test_cases = [ "http://github.com/user/repo", @@ -28,6 +29,7 @@ def test_parse_url_valid_http() -> None: 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"):