add web
This commit is contained in:
@@ -84,7 +84,7 @@ class FeishuNotifier:
|
||||
|
||||
def _upload_file(self, file_path: str, file_name: str) -> Optional[str]:
|
||||
"""
|
||||
上传文件到飞书(用于消息中发送)
|
||||
上传文件到飞书
|
||||
|
||||
Args:
|
||||
file_path: 文件本地路径
|
||||
@@ -99,8 +99,7 @@ class FeishuNotifier:
|
||||
return None
|
||||
|
||||
try:
|
||||
# 使用 im API 上传文件
|
||||
url = "https://open.feishu.cn/open-apis/im/v1/files"
|
||||
url = "https://open.feishu.cn/open-apis/drive/v1/files/upload_all"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}"
|
||||
}
|
||||
@@ -108,29 +107,25 @@ class FeishuNotifier:
|
||||
# 读取文件
|
||||
with open(file_path, 'rb') as f:
|
||||
file_content = f.read()
|
||||
|
||||
# 获取文件类型
|
||||
file_ext = os.path.splitext(file_name)[1].lower()
|
||||
file_type = 'stream' # 默认
|
||||
|
||||
|
||||
# 构建 multipart 请求
|
||||
files = {
|
||||
'file': (file_name, file_content, 'application/octet-stream')
|
||||
}
|
||||
data = {
|
||||
'file_name': file_name,
|
||||
'file_type': file_type
|
||||
'parent_node': 'root' # 根目录
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, files=files, data=data, timeout=60)
|
||||
result = response.json()
|
||||
|
||||
if result.get("code") == 0:
|
||||
file_key = result.get("data", {}).get("file_key")
|
||||
logger.info(f"文件上传成功: {file_name}, file_key: {file_key}")
|
||||
file_key = result.get("data", {}).get("file", {}).get("token")
|
||||
logger.info(f"文件上传成功: {file_name}")
|
||||
return file_key
|
||||
else:
|
||||
logger.error(f"文件上传失败: {result.get('msg')}, code: {result.get('code')}")
|
||||
logger.error(f"文件上传失败: {result.get('msg')}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
@@ -489,6 +484,61 @@ class FeishuNotifier:
|
||||
}
|
||||
})
|
||||
|
||||
# 添加 PR 操作按钮(仅 PR 扫描且扫描通过时显示)
|
||||
if pr_url and target_branch and status == 'pass':
|
||||
card["elements"].append({
|
||||
"tag": "div",
|
||||
"text": {
|
||||
"tag": "lark_md",
|
||||
"content": "**请选择操作:**"
|
||||
}
|
||||
})
|
||||
|
||||
# 解析仓库信息用于按钮回调
|
||||
repo_full_name = report.get('repo_name', '')
|
||||
if '/' in repo_full_name:
|
||||
owner, repo = repo_full_name.split('/', 1)
|
||||
else:
|
||||
owner, repo = '', repo_full_name
|
||||
|
||||
pr_number = report.get('pr_number', 0)
|
||||
|
||||
card["elements"].append({
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "✅ 同意合并"
|
||||
},
|
||||
"type": "primary",
|
||||
"value": {
|
||||
"action": "merge",
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"pr_number": pr_number,
|
||||
"pr_url": pr_url
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "❌ 取消合并"
|
||||
},
|
||||
"type": "danger",
|
||||
"value": {
|
||||
"action": "close",
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"pr_number": pr_number,
|
||||
"pr_url": pr_url
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
# 添加报告文件附件
|
||||
if file_key:
|
||||
card["elements"].append({
|
||||
|
||||
Reference in New Issue
Block a user