fix(mention): address PR #45 review feedback (M1-M3, S1-S3)
M1: Remove '帮忙' from help_keywords to fix keyword priority bug M3: Add unit tests for mention_utils (§25.7) S1: Merge two 'if action == opened' blocks in _handle_issues S2: Extract _send_review_mentions helper to deduplicate @mention code S3: Remove redundant 'import re' inside conditional block
This commit is contained in:
@@ -110,8 +110,8 @@ def infer_intent(body: str) -> str:
|
||||
if any(kw in body for kw in assign_keywords):
|
||||
return "assign"
|
||||
|
||||
# 求助关键词
|
||||
help_keywords = ["怎么", "如何", "?", "?", "什么", "哪个", "能否", "帮忙"]
|
||||
# 求助关键词(注意:"帮忙"已由 assign_keywords 的"帮忙做"覆盖,"请帮忙"由 collab_keywords 覆盖)
|
||||
help_keywords = ["怎么", "如何", "?", "?", "什么", "哪个", "能否"]
|
||||
if any(kw in body for kw in help_keywords):
|
||||
return "help"
|
||||
|
||||
|
||||
+41
-46
@@ -400,6 +400,32 @@ async def _handle_pr_opened(payload: Dict[str, Any]) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def _send_review_mentions(
|
||||
review_body: str,
|
||||
reviewer: str,
|
||||
pr_author: str,
|
||||
pr: dict,
|
||||
repo: str,
|
||||
pr_number: int,
|
||||
) -> None:
|
||||
"""提取并发送 Review body 中的 @mention 通知(COMMENTED / 非 COMMENTED 通用)。"""
|
||||
mentions = extract_mentions(review_body, reviewer)
|
||||
if mentions:
|
||||
auto_targets = [pr_author]
|
||||
await _send_mention_mails(
|
||||
mentions=mentions,
|
||||
auto_targets=auto_targets,
|
||||
source_type="Review",
|
||||
mention_type="Review @mention",
|
||||
source_url=pr.get("html_url", ""),
|
||||
commenter=reviewer,
|
||||
content=review_body,
|
||||
repo=repo,
|
||||
issue_number=pr_number,
|
||||
is_pr=True,
|
||||
)
|
||||
|
||||
|
||||
async def _handle_pull_request_review(payload: Dict[str, Any]) -> None:
|
||||
"""处理 pull_request_review 事件:非 COMMENTED → 通知 PR 作者。
|
||||
|
||||
@@ -463,22 +489,7 @@ async def _handle_pull_request_review(payload: Dict[str, Any]) -> None:
|
||||
_send_mail(pr_author, title, text)
|
||||
|
||||
# S5: Review body @mention 通知(COMMENTED 路径)
|
||||
mentions = extract_mentions(review_body, reviewer)
|
||||
if mentions:
|
||||
# 自动流转已通知 PR 作者(review_comment)
|
||||
auto_targets = [pr_author]
|
||||
await _send_mention_mails(
|
||||
mentions=mentions,
|
||||
auto_targets=auto_targets,
|
||||
source_type="Review",
|
||||
mention_type="Review @mention",
|
||||
source_url=pr.get("html_url", ""),
|
||||
commenter=reviewer,
|
||||
content=review_body,
|
||||
repo=repo,
|
||||
issue_number=pr_number,
|
||||
is_pr=True,
|
||||
)
|
||||
await _send_review_mentions(review_body, reviewer, pr_author, pr, repo, pr_number)
|
||||
|
||||
return
|
||||
|
||||
@@ -500,22 +511,7 @@ async def _handle_pull_request_review(payload: Dict[str, Any]) -> None:
|
||||
_send_mail(pr_author, title, text)
|
||||
|
||||
# S5: Review body @mention 通知(非 COMMENTED 路径)
|
||||
mentions = extract_mentions(review_body, reviewer)
|
||||
if mentions:
|
||||
# 自动流转已通知 PR 作者(review_result)
|
||||
auto_targets = [pr_author]
|
||||
await _send_mention_mails(
|
||||
mentions=mentions,
|
||||
auto_targets=auto_targets,
|
||||
source_type="Review",
|
||||
mention_type="Review @mention",
|
||||
source_url=pr.get("html_url", ""),
|
||||
commenter=reviewer,
|
||||
content=review_body,
|
||||
repo=repo,
|
||||
issue_number=pr_number,
|
||||
is_pr=True,
|
||||
)
|
||||
await _send_review_mentions(review_body, reviewer, pr_author, pr, repo, pr_number)
|
||||
|
||||
|
||||
async def _fetch_latest_reviewer(repo: str, pr_number: int) -> str:
|
||||
@@ -700,7 +696,6 @@ async def _handle_pr_closed(payload: Dict[str, Any]) -> None:
|
||||
self_restart = False
|
||||
if pm2_name and os.environ.get("PM2_HOME") and "pm2 restart" in cmd:
|
||||
# 检查命令是否包含当前进程名
|
||||
import re
|
||||
if re.search(rf'pm2\s+restart\s+{re.escape(pm2_name)}', cmd):
|
||||
self_restart = True
|
||||
|
||||
@@ -792,22 +787,22 @@ async def _handle_issues(payload: Dict[str, Any]) -> None:
|
||||
title = f"Issue 指派: {issue_title} ({repo}#{issue_number})"
|
||||
_send_mail(assignee, title, text)
|
||||
|
||||
elif action == "opened" and "部署失败" in issue_title:
|
||||
# 从 Issue body 提取 commit hash(Gitea deploy workflow 格式)
|
||||
sha_match = re.search(r'[0-9a-f]{40}', issue.get("body", ""))
|
||||
commit_sha = sha_match.group(0) if sha_match else "(未知)"
|
||||
elif action == "opened":
|
||||
if "部署失败" in issue_title:
|
||||
# 从 Issue body 提取 commit hash(Gitea deploy workflow 格式)
|
||||
sha_match = re.search(r'[0-9a-f]{40}', issue.get("body", ""))
|
||||
commit_sha = sha_match.group(0) if sha_match else "(未知)"
|
||||
|
||||
text = render_template("deploy_failure", {
|
||||
"repo": repo,
|
||||
"commit_sha": commit_sha or "(未知)",
|
||||
})
|
||||
text = render_template("deploy_failure", {
|
||||
"repo": repo,
|
||||
"commit_sha": commit_sha or "(未知)",
|
||||
})
|
||||
|
||||
title = f"部署失败: {repo}"
|
||||
for agent_id in ("jiangwei-infra", "pangtong-fujunshi"):
|
||||
_send_mail(agent_id, title, text)
|
||||
title = f"部署失败: {repo}"
|
||||
for agent_id in ("jiangwei-infra", "pangtong-fujunshi"):
|
||||
_send_mail(agent_id, title, text)
|
||||
|
||||
# S1: Issue body @mention(opened 时检查)
|
||||
if action == "opened":
|
||||
# Issue body @mention(opened 时检查)
|
||||
issue_body = issue.get("body", "") or ""
|
||||
sender = payload.get("sender", {}).get("login", "")
|
||||
mentions = extract_mentions(issue_body, sender)
|
||||
|
||||
Reference in New Issue
Block a user