Skip to content

Commit 9a19c92

Browse files
refactor: rename _parse_url and standardize docstrings
- Renamed `_parse_url` to `_parse_repo_source` in query_parser.py - Adjusted docstrings to adhere to PEP 257 by using imperative tense
1 parent 95b5e27 commit 9a19c92

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/gitingest/query_parser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def parse_query(
5353

5454
# Determine the parsing method based on the source type
5555
if from_web or source.startswith("https://") or "github.com" in source:
56-
query = _parse_url(source)
56+
query = _parse_repo_source(source)
5757
else:
5858
query = _parse_path(source)
5959

@@ -80,7 +80,7 @@ async def parse_query(
8080
return query
8181

8282

83-
def _parse_url(url: str) -> dict[str, Any]:
83+
def _parse_repo_source(url: str) -> dict[str, Any]:
8484
"""
8585
Parse a GitHub repository URL into a structured query dictionary.
8686
@@ -165,7 +165,7 @@ def _parse_url(url: str) -> dict[str, Any]:
165165

166166
def _is_valid_git_commit_hash(commit: str) -> bool:
167167
"""
168-
Validates if the provided string is a valid Git commit hash.
168+
Validate if the provided string is a valid Git commit hash.
169169
170170
This function checks if the commit hash is a 40-character string consisting only
171171
of hexadecimal digits, which is the standard format for Git commit hashes.
@@ -185,7 +185,7 @@ def _is_valid_git_commit_hash(commit: str) -> bool:
185185

186186
def _normalize_pattern(pattern: str) -> str:
187187
"""
188-
Normalizes the given pattern by removing leading separators and appending a wildcard.
188+
Normalize the given pattern by removing leading separators and appending a wildcard.
189189
190190
This function processes the pattern string by stripping leading directory separators
191191
and appending a wildcard (`*`) if the pattern ends with a separator.
@@ -249,7 +249,7 @@ def _parse_patterns(pattern: list[str] | str) -> list[str]:
249249

250250
def _override_ignore_patterns(ignore_patterns: list[str], include_patterns: list[str]) -> list[str]:
251251
"""
252-
Removes patterns from ignore_patterns that are present in include_patterns using set difference.
252+
Remove patterns from ignore_patterns that are present in include_patterns using set difference.
253253
254254
Parameters
255255
----------
@@ -268,7 +268,7 @@ def _override_ignore_patterns(ignore_patterns: list[str], include_patterns: list
268268

269269
def _parse_path(path_str: str) -> dict[str, Any]:
270270
"""
271-
Parses a file path into a structured query dictionary.
271+
Parse a file path into a structured query dictionary.
272272
273273
This function takes a file path and constructs a query dictionary that includes
274274
relevant details such as the absolute path and the slug (a combination of the
@@ -297,7 +297,7 @@ def _parse_path(path_str: str) -> dict[str, Any]:
297297

298298
def _is_valid_pattern(pattern: str) -> bool:
299299
"""
300-
Validates if the given pattern contains only valid characters.
300+
Validate if the given pattern contains only valid characters.
301301
302302
This function checks if the pattern contains only alphanumeric characters or one
303303
of the following allowed characters: dash (`-`), underscore (`_`), dot (`.`),

tests/test_query_parser.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import pytest
66

77
from gitingest.ignore_patterns import DEFAULT_IGNORE_PATTERNS
8-
from gitingest.query_parser import _parse_patterns, _parse_url, parse_query
8+
from gitingest.query_parser import _parse_patterns, _parse_repo_source, parse_query
99

1010

1111
async def test_parse_url_valid_https() -> None:
1212
"""
13-
Test `_parse_url` with valid HTTPS URLs from supported platforms (GitHub, GitLab, Bitbucket, Gitea).
13+
Test `_parse_repo_source` with valid HTTPS URLs from supported platforms (GitHub, GitLab, Bitbucket, Gitea).
1414
Verifies that user and repository names are correctly extracted.
1515
"""
1616
test_cases = [
@@ -19,15 +19,15 @@ async def test_parse_url_valid_https() -> None:
1919
"https://bitbucket.org/user/repo",
2020
]
2121
for url in test_cases:
22-
result = await _parse_url(url)
22+
result = await _parse_repo_source(url)
2323
assert result["user_name"] == "user"
2424
assert result["repo_name"] == "repo"
2525
assert result["url"] == url
2626

2727

2828
async def test_parse_url_valid_http() -> None:
2929
"""
30-
Test `_parse_url` with valid HTTP URLs from supported platforms.
30+
Test `_parse_repo_source` with valid HTTP URLs from supported platforms.
3131
Verifies that user and repository names, as well as the slug, are correctly extracted.
3232
"""
3333
test_cases = [
@@ -36,20 +36,20 @@ async def test_parse_url_valid_http() -> None:
3636
"http://bitbucket.org/user/repo",
3737
]
3838
for url in test_cases:
39-
result = await _parse_url(url)
39+
result = await _parse_repo_source(url)
4040
assert result["user_name"] == "user"
4141
assert result["repo_name"] == "repo"
4242
assert result["slug"] == "user-repo"
4343

4444

4545
async def test_parse_url_invalid() -> None:
4646
"""
47-
Test `_parse_url` with an invalid URL that does not include a repository structure.
47+
Test `_parse_repo_source` with an invalid URL that does not include a repository structure.
4848
Verifies that a ValueError is raised with an appropriate error message.
4949
"""
5050
url = "https://github.com"
5151
with pytest.raises(ValueError, match="Invalid repository URL"):
52-
await _parse_url(url)
52+
await _parse_repo_source(url)
5353

5454

5555
async def test_parse_query_basic() -> None:
@@ -99,11 +99,11 @@ async def test_parse_query_invalid_pattern() -> None:
9999

100100
async def test_parse_url_with_subpaths() -> None:
101101
"""
102-
Test `_parse_url` with a URL containing a branch and subpath.
102+
Test `_parse_repo_source` with a URL containing a branch and subpath.
103103
Verifies that user name, repository name, branch, and subpath are correctly extracted.
104104
"""
105105
url = "https://github.com/user/repo/tree/main/subdir/file"
106-
result = await _parse_url(url)
106+
result = await _parse_repo_source(url)
107107
assert result["user_name"] == "user"
108108
assert result["repo_name"] == "repo"
109109
assert result["branch"] == "main"
@@ -112,12 +112,12 @@ async def test_parse_url_with_subpaths() -> None:
112112

113113
async def test_parse_url_invalid_repo_structure() -> None:
114114
"""
115-
Test `_parse_url` with an invalid repository structure in the URL.
115+
Test `_parse_repo_source` with an invalid repository structure in the URL.
116116
Verifies that a ValueError is raised with an appropriate error message.
117117
"""
118118
url = "https://github.com/user"
119119
with pytest.raises(ValueError, match="Invalid repository URL"):
120-
await _parse_url(url)
120+
await _parse_repo_source(url)
121121

122122

123123
def test_parse_patterns_valid() -> None:
@@ -216,14 +216,14 @@ async def test_parse_query_empty_source() -> None:
216216

217217
async def test_parse_url_branch_and_commit_distinction() -> None:
218218
"""
219-
Test `_parse_url` with URLs containing either a branch name or a commit hash.
219+
Test `_parse_repo_source` with URLs containing either a branch name or a commit hash.
220220
Verifies that the branch and commit are correctly distinguished.
221221
"""
222222
url_branch = "https://github.com/user/repo/tree/main"
223223
url_commit = "https://github.com/user/repo/tree/abcd1234abcd1234abcd1234abcd1234abcd1234"
224224

225-
result_branch = await _parse_url(url_branch)
226-
result_commit = await _parse_url(url_commit)
225+
result_branch = await _parse_repo_source(url_branch)
226+
result_commit = await _parse_repo_source(url_commit)
227227

228228
assert result_branch["branch"] == "main"
229229
assert result_branch["commit"] is None
@@ -244,11 +244,11 @@ async def test_parse_query_uuid_uniqueness() -> None:
244244

245245
async def test_parse_url_with_query_and_fragment() -> None:
246246
"""
247-
Test `_parse_url` with a URL containing query parameters and a fragment.
247+
Test `_parse_repo_source` with a URL containing query parameters and a fragment.
248248
Verifies that the URL is cleaned and other fields are correctly extracted.
249249
"""
250250
url = "https://github.com/user/repo?arg=value#fragment"
251-
result = await _parse_url(url)
251+
result = await _parse_repo_source(url)
252252
assert result["user_name"] == "user"
253253
assert result["repo_name"] == "repo"
254254
assert result["url"] == "https://github.com/user/repo" # URL should be cleaned

0 commit comments

Comments
 (0)