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):
36
36
37
37
def __init__ (self , message : str ) -> None :
38
38
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 6
6
import base64
7
7
import os
8
8
import re
9
+ import warnings
9
10
from typing import Final
10
11
from urllib .parse import urlparse
11
12
19
20
)
20
21
21
22
from gitingest .utils .compat_func import removesuffix
22
- from gitingest .utils .exceptions import InvalidGitHubTokenError
23
23
24
24
# GitHub Personal-Access tokens (classic + fine-grained).
25
25
# - ghp_ / gho_ / ghu_ / ghs_ / ghr_ → 36 alphanumerics
@@ -319,11 +319,11 @@ def validate_github_token(token: str) -> None:
319
319
token : str
320
320
GitHub personal access token (PAT) for accessing private repositories.
321
321
322
- Raises
323
- ------
324
- InvalidGitHubTokenError
325
- If the token format is invalid.
326
-
327
322
"""
328
323
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 11
11
12
12
import pytest
13
13
14
- from gitingest .utils .exceptions import InvalidGitHubTokenError
15
14
from gitingest .utils .git_utils import (
16
15
create_git_auth_header ,
17
16
create_git_command ,
37
36
"gho_" + "E" * 36 ,
38
37
],
39
38
)
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."""
43
41
validate_github_token (token )
42
+ assert not recwarn , "validate_github_token should not warn on valid tokens"
44
43
45
44
46
45
@pytest .mark .parametrize (
@@ -54,9 +53,10 @@ def test_validate_github_token_valid(token: str) -> None:
54
53
"" , # Empty string
55
54
],
56
55
)
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 ):
60
60
validate_github_token (token )
61
61
62
62
You can’t perform that action at this time.
0 commit comments