Skip to content

Commit 8cde625

Browse files
rebase
1 parent 110e6aa commit 8cde625

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/gitingest/clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
from gitingest.config import DEFAULT_TIMEOUT
99
from gitingest.utils.git_utils import (
10-
is_github_host,
1110
check_repo_exists,
1211
create_git_auth_header,
1312
create_git_command,
1413
ensure_git_installed,
14+
is_github_host,
1515
run_command,
1616
validate_github_token,
1717
)

src/gitingest/utils/git_utils.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import asyncio
66
import base64
77
import re
8-
import warnings
98
from urllib.parse import urlparse
109

1110
from gitingest.utils.exceptions import InvalidGitHubTokenError
@@ -14,8 +13,7 @@
1413

1514

1615
def is_github_host(url: str) -> bool:
17-
"""
18-
Check if a URL is from a GitHub host (github.com or GitHub Enterprise).
16+
"""Check if a URL is from a GitHub host (github.com or GitHub Enterprise).
1917
2018
Parameters
2119
----------
@@ -26,6 +24,7 @@ def is_github_host(url: str) -> bool:
2624
-------
2725
bool
2826
True if the URL is from a GitHub host, False otherwise
27+
2928
"""
3029
hostname = urlparse(url).hostname or ""
3130
return hostname == "github.com" or hostname.startswith("github.")
@@ -150,8 +149,6 @@ async def _check_github_repo_exists(url: str, token: str | None = None) -> bool:
150149
151150
Raises
152151
------
153-
ValueError
154-
If the URL is not a valid GitHub repository URL.
155152
RuntimeError
156153
If the repository is not found, if the provided URL is invalid, or if the token format is invalid.
157154
@@ -214,17 +211,22 @@ def _parse_github_url(url: str) -> tuple[str, str, str]:
214211
------
215212
ValueError
216213
If the URL is not a valid GitHub repository URL.
214+
217215
"""
216+
expected_path_length = 2
218217
parsed = urlparse(url)
219218
if parsed.scheme not in {"http", "https"}:
220-
raise ValueError("URL must start with http:// or https://")
219+
msg = f"URL must start with http:// or https://: {url!r}"
220+
raise ValueError(msg)
221221

222222
if not parsed.hostname or not parsed.hostname.startswith("github."):
223-
raise ValueError(f"Un-recognised GitHub hostname: {parsed.hostname!r}")
223+
msg = f"Un-recognised GitHub hostname: {parsed.hostname!r}"
224+
raise ValueError(msg)
224225

225226
parts = parsed.path.strip("/").removesuffix(".git").split("/")
226-
if len(parts) != 2:
227-
raise ValueError("Path must look like /<owner>/<repo>")
227+
if len(parts) != expected_path_length:
228+
msg = f"Path must look like /<owner>/<repo>: {parsed.path!r}"
229+
raise ValueError(msg)
228230

229231
owner, repo = parts
230232
return parsed.hostname, owner, repo
@@ -293,14 +295,14 @@ def create_git_command(base_cmd: list[str], local_path: str, url: str, token: st
293295
return cmd
294296

295297

296-
def create_git_auth_header(token: str, url: str | None = None) -> str:
298+
def create_git_auth_header(token: str, url: str = "https://github.com") -> str:
297299
"""Create a Basic authentication header for GitHub git operations.
298300
299301
Parameters
300302
----------
301303
token : str
302304
GitHub personal access token
303-
url : str | None
305+
url : str
304306
The GitHub URL to create the authentication header for.
305307
Defaults to "https://github.com" if not provided.
306308
@@ -310,19 +312,7 @@ def create_git_auth_header(token: str, url: str | None = None) -> str:
310312
The git config command for setting the authentication header
311313
312314
"""
313-
if url is None:
314-
# TODO: Deprecate implicit github.com URL and require passing the url
315-
warnings.warn(
316-
"Implicitly assuming 'github.com' as the host is deprecated and will be "
317-
"removed in a future release. Explicitly pass the repository `url` to "
318-
"create_git_auth_header() instead.",
319-
DeprecationWarning,
320-
stacklevel=2,
321-
)
322-
hostname = "github.com"
323-
else:
324-
hostname = urlparse(url).hostname
325-
315+
hostname = urlparse(url).hostname
326316
basic = base64.b64encode(f"x-oauth-basic:{token}".encode()).decode()
327317
return f"http.https://{hostname}/.extraheader=Authorization: Basic {basic}"
328318

tests/test_git_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_create_git_command_helper_calls(
154154

155155
if should_call:
156156
validate_mock.assert_called_once_with(token)
157-
header_mock.assert_called_once_with(token)
157+
header_mock.assert_called_once_with(token, url=url)
158158
assert "HEADER" in cmd
159159
else:
160160
validate_mock.assert_not_called()
@@ -163,7 +163,7 @@ def test_create_git_command_helper_calls(
163163

164164

165165
@pytest.mark.parametrize(
166-
"url, expected",
166+
("url", "expected"),
167167
[
168168
# GitHub.com URLs
169169
("https://github.com/owner/repo.git", True),
@@ -187,13 +187,13 @@ def test_create_git_command_helper_calls(
187187
("ftp://github.com/owner/repo.git", True), # Different protocol but still github.com
188188
],
189189
)
190-
def test_is_github_host(url: str, expected: bool) -> None:
190+
def test_is_github_host(url: str, *, expected: bool) -> None:
191191
"""Test that ``is_github_host`` correctly identifies GitHub and GitHub Enterprise URLs."""
192192
assert is_github_host(url) == expected
193193

194194

195195
@pytest.mark.parametrize(
196-
"token, url, expected_hostname",
196+
("token", "url", "expected_hostname"),
197197
[
198198
# GitHub.com URLs (default)
199199
("ghp_" + "a" * 36, "https://github.com", "github.com"),
@@ -206,7 +206,7 @@ def test_is_github_host(url: str, expected: bool) -> None:
206206
)
207207
def test_create_git_auth_header_with_ghe_url(token: str, url: str, expected_hostname: str) -> None:
208208
"""Test that ``create_git_auth_header`` handles GitHub Enterprise URLs correctly."""
209-
header = create_git_auth_header(token, url)
209+
header = create_git_auth_header(token, url=url)
210210
expected_basic = base64.b64encode(f"x-oauth-basic:{token}".encode()).decode()
211211
expected = f"http.https://{expected_hostname}/.extraheader=Authorization: Basic {expected_basic}"
212212
assert header == expected
@@ -258,7 +258,7 @@ def test_create_git_command_with_ghe_urls(
258258
cmd = create_git_command(base_cmd, local_path, url, token)
259259

260260
# Should have base command and -C option
261-
expected_prefix = base_cmd + ["-C", local_path]
261+
expected_prefix = [*base_cmd, "-C", local_path]
262262
assert cmd[: len(expected_prefix)] == expected_prefix
263263

264264
# Should have -c and auth header
@@ -290,5 +290,5 @@ def test_create_git_command_ignores_non_github_urls(
290290
cmd = create_git_command(base_cmd, local_path, url, token)
291291

292292
# Should only have base command and -C option, no auth headers
293-
expected = base_cmd + ["-C", local_path]
293+
expected = [*base_cmd, "-C", local_path]
294294
assert cmd == expected

0 commit comments

Comments
 (0)