|
26 | 26 | exit(1) |
27 | 27 |
|
28 | 28 |
|
| 29 | +def check_gh_cli_available() -> bool: |
| 30 | + """Check if gh CLI is installed and authenticated.""" |
| 31 | + try: |
| 32 | + result = subprocess.run( |
| 33 | + ["gh", "--version"], |
| 34 | + capture_output=True, |
| 35 | + text=True, |
| 36 | + ) |
| 37 | + if result.returncode != 0: |
| 38 | + return False |
| 39 | + |
| 40 | + # Check if authenticated |
| 41 | + auth_result = subprocess.run( |
| 42 | + ["gh", "auth", "status"], |
| 43 | + capture_output=True, |
| 44 | + text=True, |
| 45 | + ) |
| 46 | + if auth_result.returncode != 0: |
| 47 | + print( |
| 48 | + "Error: gh CLI is not authenticated. Please run 'gh auth login' first.", |
| 49 | + file=sys.stderr, |
| 50 | + ) |
| 51 | + print(f"Details: {auth_result.stderr}", file=sys.stderr) |
| 52 | + return False |
| 53 | + |
| 54 | + return True |
| 55 | + except FileNotFoundError: |
| 56 | + print( |
| 57 | + "Error: gh CLI is not installed. Please install it from https://cli.github.com/", |
| 58 | + file=sys.stderr, |
| 59 | + ) |
| 60 | + return False |
| 61 | + |
| 62 | + |
29 | 63 | def run_gh_command(args: list[str]) -> dict: |
30 | 64 | """Run gh CLI command and return JSON result.""" |
31 | | - result = subprocess.run( |
32 | | - ["gh", "api"] + args, |
33 | | - capture_output=True, |
34 | | - text=True, |
35 | | - ) |
| 65 | + try: |
| 66 | + result = subprocess.run( |
| 67 | + ["gh", "api"] + args, |
| 68 | + capture_output=True, |
| 69 | + text=True, |
| 70 | + ) |
| 71 | + except FileNotFoundError: |
| 72 | + raise Exception( |
| 73 | + "gh CLI not found. Please install from https://cli.github.com/" |
| 74 | + ) |
| 75 | + |
36 | 76 | if result.returncode != 0: |
37 | 77 | raise Exception(f"gh api failed: {result.stderr}") |
38 | 78 | return json.loads(result.stdout) |
@@ -748,6 +788,10 @@ def format_markdown( |
748 | 788 |
|
749 | 789 |
|
750 | 790 | def main(): |
| 791 | + # Check gh CLI availability before proceeding |
| 792 | + if not check_gh_cli_available(): |
| 793 | + sys.exit(1) |
| 794 | + |
751 | 795 | # Capture the time when the command is run (both datetime and formatted string) |
752 | 796 | report_time = datetime.now(timezone.utc) |
753 | 797 | report_generated_time = report_time.strftime("%Y-%m-%d %H:%M:%S") |
|
0 commit comments