mirror of https://github.com/zulip/zulip.git
integrations: Add webhook payloads, webhook code, API endpoint, and tests for heroku
This commit is contained in:
parent
5b22959f1c
commit
7c3aff92d9
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1 @@
|
|||
app=sample-project&app_uuid=f46ffea9-d6be-4293-ae6e-4449fa5ae29a&user=user%40example.com&url=http%3A%2F%2Fsample-project.herokuapp.com&head=3eb5f44&head_long=3eb5f447a2f6bcf254e63fbf2426b8e6738608eb&prev_head=32d184c097b04182483999046e91c32328c07562&git_log=%20%20*%20Example%20User%3A%20Test%20commit%20for%20Deploy%20Hook%202&release=v9
|
|
@ -117,6 +117,7 @@ WEBHOOK_INTEGRATIONS = [
|
|||
),
|
||||
WebhookIntegration('gitlab', display_name='GitLab'),
|
||||
WebhookIntegration('helloworld', display_name='Hello World'),
|
||||
WebhookIntegration('heroku', display_name='Heroku'),
|
||||
WebhookIntegration('ifttt', function='zerver.views.webhooks.ifttt.api_iftt_app_webhook', display_name='IFTTT'),
|
||||
WebhookIntegration('jira', secondary_line_text='(hosted or v5.2+)', display_name='JIRA'),
|
||||
WebhookIntegration('librato'),
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from typing import Text
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
class HerokuHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'heroku'
|
||||
URL_TEMPLATE = u"/api/v1/external/heroku?stream={stream}&api_key={api_key}"
|
||||
|
||||
def test_deployment(self):
|
||||
# type: () -> None
|
||||
expected_subject = "sample-project"
|
||||
expected_message = u"""user@example.com deployed version 3eb5f44 of \
|
||||
[sample-project](http://sample-project.herokuapp.com)
|
||||
> * Example User: Test commit for Deploy Hook 2"""
|
||||
self.send_and_test_stream_message('deploy', expected_subject, expected_message,
|
||||
content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def get_body(self, fixture_name):
|
||||
# type: (Text) -> Text
|
||||
return self.fixture_data("heroku", fixture_name, file_type="txt")
|
|
@ -0,0 +1,22 @@
|
|||
# Webhooks for external integrations.
|
||||
from __future__ import absolute_import
|
||||
from typing import Text
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.lib.actions import check_send_message
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
|
||||
from zerver.models import UserProfile, Client
|
||||
|
||||
|
||||
@api_key_only_webhook_view("Heroku")
|
||||
@has_request_variables
|
||||
def api_heroku_webhook(request, user_profile, client, stream=REQ(default="heroku"),
|
||||
head=REQ(), app=REQ(), user=REQ(), url=REQ(), git_log=REQ()):
|
||||
# type: (HttpRequest, UserProfile, Client, Text, Text, Text, Text, Text, Text) -> HttpResponse
|
||||
template = "{} deployed version {} of [{}]({})\n> {}"
|
||||
content = template.format(user, head, app, url, git_log)
|
||||
|
||||
check_send_message(user_profile, client, "stream", [stream], app, content)
|
||||
return json_success()
|
Loading…
Reference in New Issue