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:
Niloth P
2025-03-02 11:07:09 +05:30
committed by Tim Abbott
parent b7e79715cc
commit c32e6f4940
10 changed files with 42 additions and 12 deletions

View File

@@ -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