mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
integrations: Improve the branch filtering in Git-related integrations.
- Made the branch-filtering checks uniform across all the integrations, by adding a helper function to git.py, and re-using it. - Instead of checking if the name of the branch that generated the event is a substring of the "branches" parameter, we now check if there's an exact match. For example, if there are two branches named "main" and "release/v1.0-main", and the user wants to track pushes to only the "release/v1.0-main" branch, they wouldn't have been able to previously, it will always track pushes to both branches. There was no way to filter out the smaller named branch when there were overlaps.
This commit is contained in:
@@ -9,7 +9,11 @@ from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
||||
from zerver.lib.validator import WildValue, check_string
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, get_push_commits_event_message
|
||||
from zerver.lib.webhooks.git import (
|
||||
TOPIC_WITH_BRANCH_TEMPLATE,
|
||||
get_push_commits_event_message,
|
||||
is_branch_name_notifiable,
|
||||
)
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
||||
@@ -49,7 +53,7 @@ def get_event_name(payload: WildValue, branches: str | None) -> str | None:
|
||||
event_name = payload["event"]["name"].tame(check_string)
|
||||
if event_name == "repo-push" and branches is not None:
|
||||
branch = get_push_branch_name(payload)
|
||||
if branches.find(branch) == -1:
|
||||
if not is_branch_name_notifiable(branch, branches):
|
||||
return None
|
||||
if event_name in EVENT_FUNCTION_MAPPER:
|
||||
return event_name
|
||||
|
||||
Reference in New Issue
Block a user