fix: [test] agent_poller get_issue 增强:获取评论 + 修复 Windows GBK 编码崩溃 - Closes #126 #127

Merged
pzhang_qe_agent_01 merged 1 commits from test/issue-126-agent-poller-enhance into main 2026-06-08 21:59:30 +08:00
+18 -1
View File
@@ -21,6 +21,13 @@ import sys
import urllib.request import urllib.request
import urllib.error import urllib.error
# Fix Windows GBK encoding: emoji and Chinese characters from Gitea API
# crash print() under the default Windows code page.
try:
sys.stdout.reconfigure(encoding='utf-8')
except Exception:
pass
def _load_gitea_config(): def _load_gitea_config():
"""Load Gitea URL, repo, and token from ~/.gitea/config.yaml or env vars.""" """Load Gitea URL, repo, and token from ~/.gitea/config.yaml or env vars."""
config_path = os.path.expanduser("~/.gitea/config.yaml") config_path = os.path.expanduser("~/.gitea/config.yaml")
@@ -173,7 +180,7 @@ def blocked_check():
print(f"Checked {len(all_blocked)} blocked issue(s): still blocked.") print(f"Checked {len(all_blocked)} blocked issue(s): still blocked.")
def get_issue(num): def get_issue(num, with_comments=True):
i = _req("GET", f"/issues/{num}") i = _req("GET", f"/issues/{num}")
print(f"## #{i['number']}: {i['title']}") print(f"## #{i['number']}: {i['title']}")
print(f"State: {i['state']}") print(f"State: {i['state']}")
@@ -181,6 +188,16 @@ def get_issue(num):
print(f"Labels: {', '.join(labels) if labels else 'none'}") print(f"Labels: {', '.join(labels) if labels else 'none'}")
print() print()
print(i.get("body", "(no description)")) print(i.get("body", "(no description)"))
if with_comments:
comments = _req_safe("GET", f"/issues/{num}/comments")
if comments:
print(f"\n--- Comments ({len(comments)}) ---")
for c in comments:
user = c.get("user", {}).get("login", "unknown")
created = c.get("created_at", "")[:16]
body = c.get("body", "")
print(f"\n[{user}] {created}")
print(body)
return i return i