Skip to content

feat: 在PushReviewEntity中添加user_username字段 #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion biz/entity/review_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def commit_messages(self):

class PushReviewEntity:
def __init__(self, project_name: str, author: str, branch: str, updated_at: int, commits: list, score: float,
review_result: str, url_slug: str):
review_result: str, url_slug: str, user_username: str):
self.project_name = project_name
self.author = author
self.branch = branch
Expand All @@ -29,6 +29,7 @@ def __init__(self, project_name: str, author: str, branch: str, updated_at: int,
self.score = score
self.review_result = review_result
self.url_slug = url_slug
self.user_username = user_username

@property
def commit_messages(self):
Expand Down
12 changes: 11 additions & 1 deletion biz/event/event_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from blinker import Signal
from datetime import datetime

from biz.entity.review_entity import MergeRequestReviewEntity, PushReviewEntity
from biz.service.review_service import ReviewService
from biz.utils.im import notifier


def format_timestamp(timestamp_str: str) -> str:
"""将ISO 8601格式的时间字符串转换为更易读的格式"""
try:
dt = datetime.fromisoformat(timestamp_str)
return dt.strftime('%Y-%m-%d %H:%M:%S')
except (ValueError, TypeError):
return timestamp_str

# 定义全局事件管理器(事件信号)
event_manager = {
"merge_request_reviewed": Signal(),
Expand Down Expand Up @@ -47,7 +57,7 @@ def on_push_reviewed(entity: PushReviewEntity):
for commit in entity.commits:
message = commit.get('message', '').strip()
author = commit.get('author', 'Unknown Author')
timestamp = commit.get('timestamp', '')
timestamp = format_timestamp(commit.get('timestamp', ''))
url = commit.get('url', '#')
im_msg += (
f"- **提交信息**: {message}\n"
Expand Down
2 changes: 2 additions & 0 deletions biz/queue/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def handle_push_event(webhook_data: dict, gitlab_token: str, gitlab_url: str, gi
score=score,
review_result=review_result,
url_slug=gitlab_url_slug,
user_username=webhook_data['user_username']
))

except Exception as e:
Expand Down Expand Up @@ -155,6 +156,7 @@ def handle_github_push_event(webhook_data: dict, github_token: str, github_url:
score=score,
review_result=review_result,
url_slug=github_url_slug,
user_username=webhook_data['user_username']
))

except Exception as e:
Expand Down
6 changes: 4 additions & 2 deletions biz/utils/im/wecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def format_markdown_content(self, content, title=None):
# 处理链接格式
content = re.sub(r'\[(.*?)\]\((.*?)\)', r'[链接]\2', content)

# 移除HTML标签
content = re.sub(r'<[^>]+>', '', content)
# 移除HTML标签,但保留企业微信的@消息格式
content = re.sub(r'<(?!@)[^>]+>', '', content)

formatted_content += content
return formatted_content
Expand Down Expand Up @@ -191,6 +191,8 @@ def _build_text_message(self, content, is_at_all):
def _build_markdown_message(self, content, title):
""" 构造 Markdown 消息 """
formatted_content = self.format_markdown_content(content, title)
# 增加日志
logger.info(formatted_content)
return {
"msgtype": "markdown",
"markdown": {
Expand Down