github_issues.py
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
GitHub Issues 工具模块
提供创建 GitHub Issues URL 和显示带链接的错误信息的功能
数据模型定义位置:
- 无数据模型
"""
from datetime import datetime
from urllib.parse import quote
# GitHub 仓库信息
GITHUB_REPO = "666ghj/BettaFish"
GITHUB_ISSUES_URL = f"https://github.com/{GITHUB_REPO}/issues/new"
def create_issue_url(title: str, body: str = "") -> str:
"""
创建 GitHub Issues URL,预填充标题和内容
Args:
title: Issue 标题
body: Issue 内容(可选)
Returns:
完整的 GitHub Issues URL
"""
encoded_title = quote(title)
encoded_body = quote(body) if body else ""
if encoded_body:
return f"{GITHUB_ISSUES_URL}?title={encoded_title}&body={encoded_body}"
else:
return f"{GITHUB_ISSUES_URL}?title={encoded_title}"
def error_with_issue_link(
error_message: str,
error_details: str = "",
app_name: str = "Streamlit App"
) -> str:
"""
生成带 GitHub Issues 链接的错误信息字符串
仅在通用异常处理中使用,不用于用户配置错误
Args:
error_message: 错误消息
error_details: 错误详情(可选,用于填充到 Issue body)
app_name: 应用名称,用于标识错误来源
Returns:
包含错误信息和 GitHub Issues 链接的 Markdown 格式字符串
"""
issue_title = f"[{app_name}] {error_message[:50]}"
issue_body = f"## 错误信息\n\n{error_message}\n\n"
if error_details:
issue_body += f"## 错误详情\n\n```\n{error_details}\n```\n\n"
issue_body += f"## 环境信息\n\n- 应用: {app_name}\n- 时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
issue_url = create_issue_url(issue_title, issue_body)
# 使用 markdown 格式添加超链接
error_display = f"{error_message}\n\n[📝 提交错误报告]({issue_url})"
if error_details:
error_display = f"{error_message}\n\n```\n{error_details}\n```\n\n[📝 提交错误报告]({issue_url})"
return error_display
__all__ = [
"create_issue_url",
"error_with_issue_link",
"GITHUB_REPO",
"GITHUB_ISSUES_URL",
]