mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Add github dispatcher to have one elegant url for both github integrations.
Dispatcher avoids to create new URL for github_webhook.
This commit is contained in:
@@ -929,7 +929,7 @@
|
||||
|
||||
<p>In the <b>"Payload URL"</b> field, enter a URL constructed like this:</p>
|
||||
|
||||
<p><code>{{ external_api_uri_subdomain }}/v1/external/webhook_github?api_key=abcdefgh&stream=github</code></p>
|
||||
<p><code>{{ external_api_uri_subdomain }}/v1/external/github?api_key=abcdefgh&stream=github</code></p>
|
||||
|
||||
<p>where <code>api_key</code> is the API key of your Zulip
|
||||
bot. Select the actions that you want to result in a
|
||||
|
||||
@@ -90,6 +90,15 @@ class HubotLozenge(Integration):
|
||||
self.git_url = git_url
|
||||
super(HubotLozenge, self).__init__(name, name, logo, display_name=display_name)
|
||||
|
||||
class GithubIntegration(WebhookIntegration):
|
||||
"""
|
||||
We need this class to don't creating url object for git integrations.
|
||||
We want to have one generic url with dispatch function for github service and github webhook.
|
||||
"""
|
||||
@property
|
||||
def url_object(self):
|
||||
# type: () -> None
|
||||
return
|
||||
|
||||
WEBHOOK_INTEGRATIONS = [
|
||||
WebhookIntegration('airbrake'),
|
||||
@@ -102,16 +111,15 @@ WEBHOOK_INTEGRATIONS = [
|
||||
WebhookIntegration('crashlytics'),
|
||||
WebhookIntegration('deskdotcom', logo='static/images/integrations/logos/deskcom.png', display_name='Desk.com'),
|
||||
WebhookIntegration('freshdesk'),
|
||||
WebhookIntegration(
|
||||
GithubIntegration(
|
||||
'github',
|
||||
function='zerver.views.webhooks.github.api_github_landing',
|
||||
display_name='GitHub',
|
||||
secondary_line_text='(deprecated)'
|
||||
),
|
||||
WebhookIntegration(
|
||||
GithubIntegration(
|
||||
'github_webhook',
|
||||
display_name='GitHub',
|
||||
url='api/v1/external/webhook_github',
|
||||
logo='static/images/integrations/logos/github.png',
|
||||
secondary_line_text='(webhook)',
|
||||
function='zerver.views.webhooks.github_webhook.api_github_webhook'
|
||||
|
||||
@@ -7,7 +7,7 @@ from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
class GithubWebhookTest(WebhookTestCase):
|
||||
STREAM_NAME = 'github'
|
||||
URL_TEMPLATE = "/api/v1/external/webhook_github?stream={stream}&api_key={api_key}"
|
||||
URL_TEMPLATE = "/api/v1/external/github?stream={stream}&api_key={api_key}"
|
||||
FIXTURE_DIR_NAME = 'github_webhook'
|
||||
EXPECTED_SUBJECT_REPO_EVENTS = u"public-repo"
|
||||
EXPECTED_SUBJECT_ISSUE_EVENTS = u"public-repo / Issue #2 Spelling error in the README file"
|
||||
|
||||
12
zerver/views/webhooks/github_dispatcher.py
Normal file
12
zerver/views/webhooks/github_dispatcher.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from .github_webhook import api_github_webhook
|
||||
from .github import api_github_landing
|
||||
|
||||
|
||||
def api_github_webhook_dispatch(request):
|
||||
# type: (HttpRequest) -> HttpResponse
|
||||
if request.META.get('HTTP_X_GITHUB_EVENT'):
|
||||
return api_github_webhook(request)
|
||||
else:
|
||||
return api_github_landing(request)
|
||||
@@ -9,6 +9,8 @@ from zproject import dev_urls
|
||||
from zproject.legacy_urls import legacy_urls
|
||||
from zerver.views.integrations import IntegrationView, APIView, HelpView
|
||||
from zerver.lib.integrations import WEBHOOK_INTEGRATIONS
|
||||
from zerver.views.webhooks import github_dispatcher
|
||||
|
||||
|
||||
from django.contrib.auth.views import (login, password_reset,
|
||||
password_reset_done, password_reset_confirm, password_reset_complete)
|
||||
@@ -303,9 +305,14 @@ urls += url(r'^user_uploads/(?P<realm_id_str>(\d*|unk))/(?P<filename>.*)',
|
||||
{'override_api_url_scheme'})}),
|
||||
|
||||
# Incoming webhook URLs
|
||||
# We don't create urls for particular git integrations here
|
||||
# because of generic one below
|
||||
for incoming_webhook in WEBHOOK_INTEGRATIONS:
|
||||
if incoming_webhook.url_object:
|
||||
urls.append(incoming_webhook.url_object)
|
||||
|
||||
urls.append(url(r'^api/v1/external/github', github_dispatcher.api_github_webhook_dispatch))
|
||||
|
||||
# Mobile-specific authentication URLs
|
||||
urls += [
|
||||
# This json format view used by the mobile apps lists which authentication
|
||||
|
||||
Reference in New Issue
Block a user