diff --git a/server/tasks/lark/chat.py b/server/tasks/lark/chat.py index 0d28e9e4..c5bb7fb7 100644 --- a/server/tasks/lark/chat.py +++ b/server/tasks/lark/chat.py @@ -316,16 +316,7 @@ def create_issue( assignees = [code_users[openid][1] for openid in users if openid in code_users] # 处理 body - # 1. 判断 body 中是否有 at - if "mentions" in data["event"]["message"]: - # 替换 body 中的 im_name 为 code_name - body = replace_im_name_to_github_name( - app_id, message_id, {"text": body}, data, team, *args, **kwargs - ) - body = body.replace("\n", "\r\n") - - # 2. 处理 body 中的图片 - body = replace_images_keys_with_url(body, team.id, message_id) + body = process_desc(app_id, message_id, body, data, team, *args, **kwargs) response = github_app.create_issue( team.name, repo.name, title, body, assignees, labels @@ -337,6 +328,24 @@ def create_issue( return response +def process_desc(app_id, message_id, desc, data, team, *args, **kwargs): + """ + 处理发给 github 的 desc, 转换@、处理图片、换行 + """ + # 1. 判断 body 中是否有 at + if "mentions" in data["event"]["message"]: + # 替换 body 中的 im_name 为 code_name + desc = replace_im_name_to_github_name( + app_id, message_id, {"text": desc}, data, team, *args, **kwargs + ) + + # 2. 处理 body 中的图片 + desc = replace_images_keys_with_url(desc, team.id, message_id) + + # github 只支持 \r\n + return desc.replace("\n", "\r\n") + + def replace_images_keys_with_url(text, team_id, message_id): """ replace image_key with image URL. diff --git a/server/tasks/lark/issue.py b/server/tasks/lark/issue.py index abdee5c0..8dfc7602 100644 --- a/server/tasks/lark/issue.py +++ b/server/tasks/lark/issue.py @@ -601,12 +601,12 @@ def create_issue_comment(app_id, message_id, content, data, *args, **kwargs): ) comment_text = content["text"] - # 判断 content 中是否有 at - if "mentions" in data["event"]["message"]: - # 替换 content 中的 im_name 为 code_name - comment_text = replace_im_name_to_github_name( - app_id, message_id, content, data, team, *args, **kwargs - ) + from tasks.lark.chat import process_desc + + # 处理 desc + comment_text = process_desc( + app_id, message_id, comment_text, data, team, *args, **kwargs + ) response = github_app.create_issue_comment( team.name, repo.name, issue.issue_number, comment_text