File tree Expand file tree Collapse file tree 3 files changed +14
-25
lines changed
Expand file tree Collapse file tree 3 files changed +14
-25
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,3 @@ class InvalidNotebookError(Exception):
3636
3737 def __init__ (self , message : str ) -> None :
3838 super ().__init__ (message )
39-
40-
41- class InvalidGitHubTokenError (ValueError ):
42- """Exception raised when a GitHub Personal Access Token is malformed."""
43-
44- def __init__ (self ) -> None :
45- msg = (
46- "Invalid GitHub token format. To generate a token, go to "
47- "https://github.com/settings/tokens/new?description=gitingest&scopes=repo."
48- )
49- super ().__init__ (msg )
Original file line number Diff line number Diff line change 66import base64
77import os
88import re
9+ import warnings
910from typing import Final
1011from urllib .parse import urlparse
1112
1920)
2021
2122from gitingest .utils .compat_func import removesuffix
22- from gitingest .utils .exceptions import InvalidGitHubTokenError
2323
2424# GitHub Personal-Access tokens (classic + fine-grained).
2525# - ghp_ / gho_ / ghu_ / ghs_ / ghr_ → 36 alphanumerics
@@ -319,11 +319,11 @@ def validate_github_token(token: str) -> None:
319319 token : str
320320 GitHub personal access token (PAT) for accessing private repositories.
321321
322- Raises
323- ------
324- InvalidGitHubTokenError
325- If the token format is invalid.
326-
327322 """
328323 if not re .fullmatch (_GITHUB_PAT_PATTERN , token ):
329- raise InvalidGitHubTokenError
324+ warnings .warn (
325+ "Invalid GitHub token format. To generate a token, go to "
326+ "https://github.com/settings/tokens/new?description=gitingest&scopes=repo." ,
327+ UserWarning ,
328+ stacklevel = 2 ,
329+ )
Original file line number Diff line number Diff line change 1111
1212import pytest
1313
14- from gitingest .utils .exceptions import InvalidGitHubTokenError
1514from gitingest .utils .git_utils import (
1615 create_git_auth_header ,
1716 create_git_command ,
3736 "gho_" + "E" * 36 ,
3837 ],
3938)
40- def test_validate_github_token_valid (token : str ) -> None :
41- """validate_github_token should accept properly-formatted tokens."""
42- # Should not raise any exception
39+ def test_validate_github_token_valid (token : str , recwarn : pytest .WarningsRecorder ) -> None :
40+ """``validate_github_token`` should silently accept well-formed tokens."""
4341 validate_github_token (token )
42+ assert not recwarn , "validate_github_token should not warn on valid tokens"
4443
4544
4645@pytest .mark .parametrize (
@@ -54,9 +53,10 @@ def test_validate_github_token_valid(token: str) -> None:
5453 "" , # Empty string
5554 ],
5655)
57- def test_validate_github_token_invalid (token : str ) -> None :
58- """Test that ``validate_github_token`` raises ``InvalidGitHubTokenError`` on malformed tokens."""
59- with pytest .raises (InvalidGitHubTokenError ):
56+ def test_validate_github_token_invalid_warns (token : str ) -> None :
57+ """Test that malformed tokens trigger a UserWarning carrying the helper message."""
58+ warn_msg = "Invalid GitHub token format"
59+ with pytest .warns (UserWarning , match = warn_msg ):
6060 validate_github_token (token )
6161
6262
You can’t perform that action at this time.
0 commit comments