mirror of
https://github.com/wled/WLED.git
synced 2025-11-09 02:59:03 +00:00
Improve error handling for missing git CLI
Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
This commit is contained in:
BIN
pio-scripts/__pycache__/set_repo.cpython-312.pyc
Normal file
BIN
pio-scripts/__pycache__/set_repo.cpython-312.pyc
Normal file
Binary file not shown.
@@ -3,7 +3,12 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
def get_github_repo():
|
def get_github_repo():
|
||||||
"""Extract GitHub repository name from git remote URL."""
|
"""Extract GitHub repository name from git remote URL.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Repository name in 'owner/repo' format for GitHub repos,
|
||||||
|
'unknown' for non-GitHub repos, missing git CLI, or any errors.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# Get the remote URL for origin
|
# Get the remote URL for origin
|
||||||
result = subprocess.run(['git', 'remote', 'get-url', 'origin'],
|
result = subprocess.run(['git', 'remote', 'get-url', 'origin'],
|
||||||
@@ -35,8 +40,14 @@ def get_github_repo():
|
|||||||
|
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError, Exception):
|
except FileNotFoundError:
|
||||||
# Git command failed or git is not available
|
# Git CLI is not installed or not in PATH
|
||||||
|
return 'unknown'
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# Git command failed (e.g., not a git repo, no remote, etc.)
|
||||||
|
return 'unknown'
|
||||||
|
except Exception:
|
||||||
|
# Any other unexpected error
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
repo = get_github_repo()
|
repo = get_github_repo()
|
||||||
|
|||||||
Reference in New Issue
Block a user