Skip to content

Commit

Permalink
fix issue comment
Browse files Browse the repository at this point in the history
  • Loading branch information
freeziyou committed Feb 23, 2024
1 parent 31e0311 commit 3b79d00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
29 changes: 19 additions & 10 deletions server/tasks/lark/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions server/tasks/lark/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b79d00

Please sign in to comment.