Skip to content

Commit bcf88a7

Browse files
Add gh CLI availability check in query_job_status.py
1 parent 82c8a43 commit bcf88a7

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

scripts/ci/query_job_status.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,53 @@
2626
exit(1)
2727

2828

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+
2963
def run_gh_command(args: list[str]) -> dict:
3064
"""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+
3676
if result.returncode != 0:
3777
raise Exception(f"gh api failed: {result.stderr}")
3878
return json.loads(result.stdout)
@@ -748,6 +788,10 @@ def format_markdown(
748788

749789

750790
def main():
791+
# Check gh CLI availability before proceeding
792+
if not check_gh_cli_available():
793+
sys.exit(1)
794+
751795
# Capture the time when the command is run (both datetime and formatted string)
752796
report_time = datetime.now(timezone.utc)
753797
report_generated_time = report_time.strftime("%Y-%m-%d %H:%M:%S")

0 commit comments

Comments
 (0)