mirror of https://github.com/zulip/zulip.git
github_webhook: Send test message sent by GitHub webhook integration.
Fixes #3994.
This commit is contained in:
parent
282d27a934
commit
edfb9c21bc
|
@ -27,8 +27,8 @@
|
|||
},
|
||||
"repository": {
|
||||
"id": 53679793,
|
||||
"name": "zulip",
|
||||
"full_name": "TomaszKolek/zulip",
|
||||
"name": "public-repo",
|
||||
"full_name": "TomaszKolek/public-repo",
|
||||
"owner": {
|
||||
"login": "TomaszKolek",
|
||||
"id": 5993758,
|
||||
|
|
|
@ -20,9 +20,8 @@ class GithubWebhookTest(WebhookTestCase):
|
|||
|
||||
def test_ping_event(self):
|
||||
# type: () -> None
|
||||
payload = self.get_body('ping')
|
||||
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='ping', content_type="application/json")
|
||||
self.assert_json_success(result)
|
||||
expected_message = u"GitHub webhook has been successfully configured by TomaszKolek"
|
||||
self.send_and_test_stream_message('ping', self.EXPECTED_SUBJECT_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='ping')
|
||||
|
||||
def test_push_1_commit(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -13,7 +13,8 @@ from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variabl
|
|||
from zerver.lib.webhooks.git import get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE,\
|
||||
get_pull_request_event_message, SUBJECT_WITH_BRANCH_TEMPLATE,\
|
||||
get_push_commits_event_message, CONTENT_MESSAGE_TEMPLATE,\
|
||||
get_commits_comment_action_message, get_push_tag_event_message
|
||||
get_commits_comment_action_message, get_push_tag_event_message, \
|
||||
get_setup_webhook_message
|
||||
|
||||
class UnknownEventType(Exception):
|
||||
pass
|
||||
|
@ -296,6 +297,10 @@ def get_pull_request_review_comment_body(payload):
|
|||
type='PR Review Comment'
|
||||
)
|
||||
|
||||
def get_ping_body(payload):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
return get_setup_webhook_message('GitHub', get_sender_name(payload))
|
||||
|
||||
def get_repository_name(payload):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
return payload['repository']['name']
|
||||
|
@ -368,6 +373,7 @@ EVENT_FUNCTION_MAPPER = {
|
|||
'opened_or_update_pull_request': get_opened_or_update_pull_request_body,
|
||||
'assigned_or_unassigned_pull_request': get_assigned_or_unassigned_pull_request_body,
|
||||
'page_build': get_page_build_body,
|
||||
'ping': get_ping_body,
|
||||
'public': get_public_body,
|
||||
'pull_request_review': get_pull_request_review_body,
|
||||
'pull_request_review_comment': get_pull_request_review_comment_body,
|
||||
|
@ -386,7 +392,7 @@ def api_github_webhook(
|
|||
payload=REQ(argument_type='body'), stream=REQ(default='github')):
|
||||
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
|
||||
event = get_event(request, payload)
|
||||
if event != 'ping' and event is not None:
|
||||
if event is not None:
|
||||
subject = get_subject_based_on_type(payload, event)
|
||||
body = get_body_function_based_on_type(event)(payload)
|
||||
check_send_message(user_profile, client, 'stream', [stream], subject, body)
|
||||
|
|
Loading…
Reference in New Issue