mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
webhooks/bitbucket3: Add the diagnostics:ping event.
Note: Unlike with the other events supported by this webhook so far, to determine this event's event type, we need to use the X-Event-Key HTTP Header.
This commit is contained in:
committed by
Tim Abbott
parent
09e57389ca
commit
b8268c66d5
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"test": true
|
||||
}
|
||||
@@ -8,6 +8,22 @@ class Bitbucket3HookTests(WebhookTestCase):
|
||||
EXPECTED_TOPIC = "sandbox"
|
||||
EXPECTED_TOPIC_BRANCH_EVENTS = "sandbox / {branch}"
|
||||
|
||||
# Diagnostics Events:
|
||||
def test_ping(self) -> None:
|
||||
expected_message = "Congratulations! The Bitbucket Server webhook was configured successfully!"
|
||||
self.send_and_test_stream_message("diagnostics_ping",
|
||||
"Bitbucket Server Ping",
|
||||
expected_message,
|
||||
HTTP_X_EVENT_KEY="diagnostics:ping")
|
||||
|
||||
def test_ping_with_user_defined_topic(self) -> None:
|
||||
self.url = self.build_webhook_url(topic="my topic")
|
||||
expected_message = "Congratulations! The Bitbucket Server webhook was configured successfully!"
|
||||
self.send_and_test_stream_message("diagnostics_ping",
|
||||
"my topic",
|
||||
expected_message,
|
||||
HTTP_X_EVENT_KEY="diagnostics:ping")
|
||||
|
||||
# Core Repo Events:
|
||||
def test_commit_comment_added(self) -> None:
|
||||
expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) commented on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907):\n~~~ quote\nJust an arbitrary comment on a commit.\n~~~"""
|
||||
|
||||
@@ -46,6 +46,15 @@ def get_user_name(payload: Dict[str, Any]) -> str:
|
||||
url=payload["actor"]["links"]["self"][0]["href"])
|
||||
return user_name
|
||||
|
||||
def ping_handler(payload: Dict[str, Any], include_title: Optional[str]=None
|
||||
) -> List[Dict[str, str]]:
|
||||
if include_title:
|
||||
subject = include_title
|
||||
else:
|
||||
subject = "Bitbucket Server Ping"
|
||||
body = "Congratulations! The Bitbucket Server webhook was configured successfully!"
|
||||
return [{"subject": subject, "body": body}]
|
||||
|
||||
def repo_comment_handler(payload: Dict[str, Any], action: str) -> List[Dict[str, str]]:
|
||||
repo_name = payload["repository"]["name"]
|
||||
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
|
||||
@@ -304,6 +313,7 @@ def pr_comment_handler(payload: Dict[str, Any], action: str,
|
||||
return [{"subject": subject, "body": body}]
|
||||
|
||||
EVENT_HANDLER_MAP = {
|
||||
"diagnostics:ping": ping_handler,
|
||||
"repo:comment:added": partial(repo_comment_handler, action="commented"),
|
||||
"repo:comment:edited": partial(repo_comment_handler, action="edited their comment"),
|
||||
"repo:comment:deleted": partial(repo_comment_handler, action="deleted their comment"),
|
||||
@@ -338,7 +348,10 @@ def api_bitbucket3_webhook(request: HttpRequest, user_profile: UserProfile,
|
||||
branches: Optional[str]=REQ(default=None),
|
||||
user_specified_topic: Optional[str]=REQ("topic", default=None)
|
||||
) -> HttpResponse:
|
||||
eventkey = payload["eventKey"]
|
||||
try:
|
||||
eventkey = payload["eventKey"]
|
||||
except KeyError:
|
||||
eventkey = request.META["HTTP_X_EVENT_KEY"]
|
||||
handler = get_event_handler(eventkey)
|
||||
|
||||
if "branches" in signature(handler).parameters:
|
||||
|
||||
Reference in New Issue
Block a user