-
Notifications
You must be signed in to change notification settings - Fork 81
feat(review): 增加 Merge 触发分支白名单配置 #38
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
base: main
Are you sure you want to change the base?
Conversation
- 在 config.py 中添加 MERGE_TRIGGER_ON_BRANCHES 配置项,用于指定需要进行审核的分支 - 修改 args_check.py,增加 branch_need_check 函数用于检查分支是否需要审核 - 修改 webhook_listener.py,增加分支白名单检查逻辑
WalkthroughThis change introduces a new configuration variable and corresponding branch checking functionality. A new list variable in the configuration file specifies branch names or wildcard patterns for triggering certain actions. Additionally, a new helper function is added to check branch patterns, and the merge request handler now utilizes this function to determine if processing should continue. The overall changes enhance the configurability and specificity of branch-related merge triggers. Changes
Sequence Diagram(s)sequenceDiagram
participant GR as GitLab Payload
participant WL as WebhookListener
participant BC as branch_need_check()
participant CFG as Config
GR->>WL: Send Merge Request Payload
WL->>WL: Check if merge request is opened
WL->>WL: Extract target branch from payload
WL->>BC: Call branch_need_check(target_branch)
BC->>CFG: Compare target branch with MERGE_TRIGGER_ON_BRANCHES patterns
CFG-->>BC: Return matching result (True/False)
BC-->>WL: Return decision
WL->>WL: Proceed with merge handling if conditions met
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
config/config.py
(1 hunks)gitlab_integration/webhook_listener.py
(2 hunks)utils/args_check.py
(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
gitlab_integration/webhook_listener.py (2)
utils/args_check.py (1)
branch_need_check
(194-201)gitlab_integration/gitlab_fetcher.py (1)
is_merge_request_opened
(208-218)
🔇 Additional comments (5)
config/config.py (1)
93-95
: LGTM: Clear and well-documented configuration addition.The new configuration variable
MERGE_TRIGGER_ON_BRANCHES
with helpful comments and examples is a clean implementation. Setting it as an empty list by default means all branches will be processed when not configured, which is a sensible default behavior.utils/args_check.py (3)
1-1
: Clean import addition for the new functionality.The addition of
fnmatch
to the import statement is appropriate for the pattern matching functionality needed in the new branch checking feature.
4-4
: Import of the new configuration variable is properly implemented.Adding
MERGE_TRIGGER_ON_BRANCHES
to the import list from config is necessary for the new function.
194-202
: Well-implemented branch checking function with clear documentation.The
branch_need_check
function is well documented and handles both the case when the whitelist is empty (checking all branches) and when specific patterns are provided. The use offnmatch
for wildcard pattern matching is appropriate.The return statement is concise yet readable:
return not MERGE_TRIGGER_ON_BRANCHES or any(fnmatch.fnmatch(branch_name, pattern) for pattern in MERGE_TRIGGER_ON_BRANCHES)If the whitelist is empty, it returns
True
(indicating all branches need checking). Otherwise, it checks if the branch name matches any of the configured patterns.gitlab_integration/webhook_listener.py (1)
9-9
: Appropriate import of the new branch checking function.The addition of the import for
branch_need_check
from utils.args_check is correct.
- 使用 get 方法替代直接访问字典,避免 KeyError 异常 - 添加默认值以处理潜在的 NoneType 错误
Summary by CodeRabbit