webhooks: Migrate to check_send_stream_message.

This commit migrates all webhooks to use check_send_stream_message
instead of check_send_message. The only two webhooks that still
use check_send_message are our yo and teamcity webhooks. They
both use check_send_message for private messages.
This commit is contained in:
Eeshan Garg
2017-09-29 23:48:16 -02:30
committed by showell
parent 24aff0d0a2
commit 86c2c7ad34
53 changed files with 188 additions and 192 deletions

View File

@@ -379,22 +379,22 @@ class GitlabHookTests(WebhookTestCase):
HTTP_X_GITLAB_EVENT="Pipeline Hook"
)
@patch('zerver.webhooks.gitlab.view.check_send_message')
@patch('zerver.webhooks.gitlab.view.check_send_stream_message')
def test_push_event_message_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push')
result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.gitlab.view.check_send_message')
@patch('zerver.webhooks.gitlab.view.check_send_stream_message')
def test_push_commits_more_than_limit_message_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_commits_more_than_limit')
result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)

View File

@@ -1,5 +1,5 @@
from functools import partial
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
from zerver.lib.webhooks.git import get_push_commits_event_message, EMPTY_SHA,\
@@ -288,7 +288,7 @@ def api_gitlab_webhook(request, user_profile,
if event is not None:
body = get_body_based_on_event(event)(payload)
subject = get_subject_based_on_event(event, payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()
def get_body_based_on_event(event):