Skip to content

Commit d099de5

Browse files
fix GitHub PAT regex (#341)
1 parent ba1b6ad commit d099de5

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can also replace `hub` with `ingest` in any GitHub URL to access the corresp
5454
## 📚 Requirements
5555

5656
- Python 3.8+
57-
- For private repositories: A GitHub Personal Access Token (PAT). You can generate one at [https://github.com/settings/personal-access-tokens](https://github.com/settings/personal-access-tokens) (Profile → Settings → Developer Settings → Personal Access Tokens → Fine-grained Tokens)
57+
- For private repositories: A GitHub Personal Access Token (PAT). [Generate your token **here**!](https://github.com/settings/tokens/new?description=gitingest&scopes=repo)
5858

5959
### 📦 Installation
6060

src/gitingest/utils/git_utils.py

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

1010
from gitingest.utils.exceptions import InvalidGitHubTokenError
1111

12-
GITHUB_PAT_PATTERN = r"^(?:github_pat_|ghp_)[A-Za-z0-9_]{36,}$"
12+
GITHUB_PAT_PATTERN = r"^(?:gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59})$"
1313

1414

1515
def is_github_host(url: str) -> bool:

tests/test_git_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
"token",
3030
[
3131
# Valid tokens: correct prefixes and at least 36 allowed characters afterwards
32-
"github_pat_" + "a" * 36,
32+
"github_pat_" + "a" * 22 + "_" + "b" * 59,
3333
"ghp_" + "A" * 36,
34-
"github_pat_1234567890abcdef1234567890abcdef1234",
34+
"ghu_" + "B" * 36,
35+
"ghs_" + "C" * 36,
36+
"ghr_" + "D" * 36,
37+
"gho_" + "E" * 36,
3538
],
3639
)
3740
def test_validate_github_token_valid(token: str) -> None:
@@ -47,6 +50,7 @@ def test_validate_github_token_valid(token: str) -> None:
4750
"ghp_" + "b" * 35, # one character short
4851
"invalidprefix_" + "c" * 36, # Wrong prefix
4952
"github_pat_" + "!" * 36, # Disallowed characters
53+
"github_pat_" + "a" * 36, # Too short after 'github_pat_' prefix
5054
"", # Empty string
5155
],
5256
)

0 commit comments

Comments
 (0)