Skip to content

Commit 950fd9f

Browse files
authored
Merge pull request #11 from AptS-1547/feat-polling
feat: 增强 webhook 匹配逻辑,支持非 push 事件的分支名检查,添加调试日志
2 parents fdb30d2 + 4308fc1 commit 950fd9f

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

app/core/github/webhook.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,40 @@ def find_matching_webhook(
9292
9393
Args:
9494
repo_name: 仓库名
95-
branch: 分支名
95+
branch: 分支名 (可能为空,对于非push事件)
9696
event_type: 事件类型
9797
webhooks: webhook 配置列表
9898
9999
Returns:
100100
匹配的 webhook 配置或 None
101101
"""
102+
logger.debug("尝试匹配 webhook: 仓库=%s, 分支=%s, 事件类型=%s", repo_name, branch, event_type)
103+
102104
for webhook in webhooks:
103-
# 检查仓库名是否匹配配置中的任一模式
104105
repo_matches = any(match_pattern(repo_name, repo_pattern)
105-
for repo_pattern in webhook.REPO)
106-
107-
# 检查分支名是否匹配配置中的任一模式
108-
branch_matches = any(match_pattern(branch, branch_pattern)
109-
for branch_pattern in webhook.BRANCH)
110-
111-
# 检查事件类型是否匹配
112-
if (repo_matches and branch_matches and event_type in webhook.EVENTS):
113-
return webhook
114-
106+
for repo_pattern in webhook.REPO)
107+
if not repo_matches:
108+
continue
109+
110+
if event_type not in webhook.EVENTS:
111+
continue
112+
113+
if event_type in ["push", "pull_request"]:
114+
branch_matches = any(match_pattern(branch, branch_pattern)
115+
for branch_pattern in webhook.BRANCH)
116+
if not branch_matches:
117+
continue
118+
else:
119+
if getattr(webhook, "BRANCH_CHECK_ALL", False) and branch:
120+
branch_matches = any(match_pattern(branch, branch_pattern)
121+
for branch_pattern in webhook.BRANCH)
122+
if not branch_matches:
123+
continue
124+
125+
logger.debug("找到匹配的webhook配置: %s", webhook)
126+
return webhook
127+
128+
logger.debug("未找到匹配的webhook配置")
115129
return None
116130

117131
@staticmethod

0 commit comments

Comments
 (0)