forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make webhooks as separate modules with view and tests.
Create python packege for every webhook with view.py and tests.py
- Loading branch information
Showing
132 changed files
with
99 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
from six import text_type | ||
from typing import Union | ||
from zerver.lib.test_classes import WebhookTestCase | ||
|
||
class BitbucketHookTests(WebhookTestCase): | ||
STREAM_NAME = 'bitbucket' | ||
URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}" | ||
FIXTURE_DIR_NAME = 'bitbucket' | ||
EXPECTED_SUBJECT = u"Repository name" | ||
EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master" | ||
|
||
def test_bitbucket_on_push_event(self): | ||
# type: () -> None | ||
fixture_name = 'push' | ||
self.url = self.build_url(fixture_name) | ||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c' | ||
expected_message = u"kolaszek pushed to branch master\n\n{}".format(commit_info) | ||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) | ||
|
||
def test_bitbucket_on_push_commits_above_limit_event(self): | ||
# type: () -> None | ||
fixture_name = 'push_commits_above_limit' | ||
self.url = self.build_url(fixture_name) | ||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c\n' | ||
expected_message = u"kolaszek pushed to branch master\n\n{}[and 40 more commit(s)]".format(commit_info * 10) | ||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) | ||
|
||
def test_bitbucket_on_force_push_event(self): | ||
# type: () -> None | ||
fixture_name = 'force_push' | ||
self.url = self.build_url(fixture_name) | ||
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)" | ||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) | ||
|
||
def get_body(self, fixture_name): | ||
# type: (text_type) -> Union[text_type, Dict[str, text_type]] | ||
return {} | ||
|
||
def get_payload(self, fixture_name): | ||
# type: (text_type) -> Union[text_type, Dict[str, text_type]] | ||
return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name) | ||
|
||
def build_webhook_url(self): | ||
# type: () -> text_type | ||
return '' | ||
|
||
def build_url(self, fixture_name): | ||
# type: (text_type) -> text_type | ||
return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME) |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
zerver/views/webhooks/github_dispatcher.py → zerver/webhooks/github_dispatcher.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Webhooks for external integrations. | ||
from __future__ import absolute_import | ||
import ujson | ||
from typing import Mapping, Any, Tuple, Text | ||
from django.utils.translation import ugettext as _ | ||
from django.http import HttpRequest, HttpResponse | ||
from zerver.lib.actions import check_send_message | ||
from zerver.decorator import return_success_on_head_request | ||
from zerver.lib.response import json_success, json_error | ||
from zerver.models import UserProfile, Client | ||
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view | ||
|
||
from .view.card_actions import SUPPORTED_CARD_ACTIONS, process_card_action | ||
from .view.board_actions import SUPPORTED_BOARD_ACTIONS, process_board_action | ||
from .view.exceptions import UnsupportedAction | ||
|
||
@api_key_only_webhook_view('Trello') | ||
@return_success_on_head_request | ||
@has_request_variables | ||
def api_trello_webhook(request, user_profile, client, payload=REQ(argument_type='body'), stream=REQ(default='trello')): | ||
# type: (HttpRequest, UserProfile, Client, Mapping[str, Any], Text) -> HttpResponse | ||
payload = ujson.loads(request.body) | ||
action_type = payload.get('action').get('type') | ||
try: | ||
subject, body = get_subject_and_body(payload, action_type) | ||
except UnsupportedAction: | ||
return json_error(_('Unsupported action_type: {action_type}'.format(action_type=action_type))) | ||
|
||
check_send_message(user_profile, client, 'stream', [stream], subject, body) | ||
return json_success() | ||
|
||
def get_subject_and_body(payload, action_type): | ||
# type: (Mapping[str, Any], Text) -> Tuple[Text, Text] | ||
if action_type in SUPPORTED_CARD_ACTIONS: | ||
return process_card_action(payload, action_type) | ||
if action_type in SUPPORTED_BOARD_ACTIONS: | ||
return process_board_action(payload, action_type) | ||
raise UnsupportedAction('{} if not supported'.format(action_type)) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters