|
34 | 34 | from dataclasses import dataclass |
35 | 35 | from urllib.parse import urlparse |
36 | 36 |
|
37 | | -from github import Github, GithubException |
| 37 | +try: |
| 38 | + from github import Github, GithubException |
| 39 | + HAS_PYGITHUB = True |
| 40 | +except ImportError: |
| 41 | + HAS_PYGITHUB = False |
| 42 | + Github = None |
| 43 | + GithubException = None |
38 | 44 |
|
39 | 45 |
|
40 | 46 | @dataclass |
@@ -66,6 +72,8 @@ def owner_repo(self) -> str: |
66 | 72 |
|
67 | 73 | def fetch_latest_commit(owner_repo: str, branch: str, token: str | None) -> str: |
68 | 74 | """Fetch latest commit sha for given owner_repo & branch using PyGithub.""" |
| 75 | + if not HAS_PYGITHUB: |
| 76 | + raise RuntimeError("PyGithub not installed. Install it with: pip install PyGithub") |
69 | 77 | try: |
70 | 78 | gh = Github(token) if token else Github() |
71 | 79 | repo = gh.get_repo(owner_repo) |
@@ -167,6 +175,13 @@ def main(argv: list[str]) -> int: |
167 | 175 | updated: list[Module] = [] |
168 | 176 | # Default: use gh if available unless --no-gh specified |
169 | 177 | use_gh = (not args.no_gh) and shutil.which("gh") is not None |
| 178 | + |
| 179 | + # If PyGithub is not available and gh CLI is not available, error out |
| 180 | + if not use_gh and not HAS_PYGITHUB: |
| 181 | + print("ERROR: Neither 'gh' CLI nor PyGithub library found.", file=sys.stderr) |
| 182 | + print("Please install PyGithub (pip install PyGithub) or install GitHub CLI.", file=sys.stderr) |
| 183 | + return 3 |
| 184 | + |
170 | 185 | if not args.no_gh and not use_gh: |
171 | 186 | print("INFO: 'gh' CLI not found; using direct GitHub API", file=sys.stderr) |
172 | 187 | if args.no_gh and shutil.which("gh") is not None: |
|
0 commit comments