From 92050cf6702d8486074f4fa6dfacd2844fddcb91 Mon Sep 17 00:00:00 2001 From: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> Date: Mon, 30 Jun 2025 20:57:41 +0200 Subject: [PATCH] fix GitHub PAT regex --- README.md | 2 +- src/gitingest/utils/git_utils.py | 2 +- tests/test_git_utils.py | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 81b177f3..8af7ceaf 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ You can also replace `hub` with `ingest` in any GitHub URL to access the corresp ## 📚 Requirements - Python 3.8+ -- 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) +- For private repositories: A GitHub Personal Access Token (PAT). [Generate your token **here**!](https://github.com/settings/tokens/new?description=gitingest&scopes=repo) ### 📦 Installation diff --git a/src/gitingest/utils/git_utils.py b/src/gitingest/utils/git_utils.py index 857e1417..52fd319e 100644 --- a/src/gitingest/utils/git_utils.py +++ b/src/gitingest/utils/git_utils.py @@ -9,7 +9,7 @@ from gitingest.utils.exceptions import InvalidGitHubTokenError -GITHUB_PAT_PATTERN = r"^(?:github_pat_|ghp_)[A-Za-z0-9_]{36,}$" +GITHUB_PAT_PATTERN = r"^(?:gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59})$" def is_github_host(url: str) -> bool: diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index 1410d355..20e9818b 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -29,9 +29,12 @@ "token", [ # Valid tokens: correct prefixes and at least 36 allowed characters afterwards - "github_pat_" + "a" * 36, + "github_pat_" + "a" * 22 + "_" + "b" * 59, "ghp_" + "A" * 36, - "github_pat_1234567890abcdef1234567890abcdef1234", + "ghu_" + "B" * 36, + "ghs_" + "C" * 36, + "ghr_" + "D" * 36, + "gho_" + "E" * 36, ], ) def test_validate_github_token_valid(token: str) -> None: @@ -47,6 +50,7 @@ def test_validate_github_token_valid(token: str) -> None: "ghp_" + "b" * 35, # one character short "invalidprefix_" + "c" * 36, # Wrong prefix "github_pat_" + "!" * 36, # Disallowed characters + "github_pat_" + "a" * 36, # Too short after 'github_pat_' prefix "", # Empty string ], )