Skip to content

Commit 33b1b7b

Browse files
Test Userclaude
andcommitted
fix: handle empty GitHub API response in github-repo-analyzer
The fetch_repos() function was failing with JSONDecodeError when gh CLI returned empty output (e.g., in CI without GitHub token). Fix: Add error handling to check for: 1. Non-zero return code from gh command 2. Empty stdout 3. JSON parsing errors Returns empty list gracefully instead of crashing, allowing the script to work in all environments. Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
1 parent 3004790 commit 33b1b7b

File tree

1 file changed

+18
-1
lines changed
  • skillsets/github-repo-analyzer

1 file changed

+18
-1
lines changed

skillsets/github-repo-analyzer/impl.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@ def fetch_repos():
1010
capture_output=True,
1111
text=True
1212
)
13-
return json.loads(result.stdout)
13+
14+
# 检查命令是否成功执行
15+
if result.returncode != 0:
16+
print("⚠️ 无法连接到 GitHub API(可能需要认证)")
17+
print(" 提示: 运行 'gh auth login' 进行认证")
18+
return []
19+
20+
# 检查输出是否为空
21+
if not result.stdout or result.stdout.strip() == '':
22+
print("ℹ️ 未找到任何 GitHub 仓库")
23+
return []
24+
25+
try:
26+
return json.loads(result.stdout)
27+
except json.JSONDecodeError as e:
28+
print(f"❌ 解析 GitHub API 响应失败: {e}")
29+
print(f" 响应内容: {result.stdout[:200] if result.stdout else '(空)'}")
30+
return []
1431

1532
def generate_report(repos):
1633
now = datetime.now()

0 commit comments

Comments
 (0)