Skip to content

Commit

Permalink
Add Crashlytics integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Kolek authored and timabbott committed Jun 4, 2016
1 parent 093e5a9 commit 8411b2e
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
Binary file added static/images/integrations/crashlytics/001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/integrations/logos/crashlytics.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions templates/zerver/integrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<span class="integration-label">Codeship</span>
</a>
</div>
<div class="integration-lozenge integration-crashlytics">
<a class="integration-link integration-crashlytics" href="#crashlytics">
<img class="integration-logo" src="/static/images/integrations/logos/crashlytics.png" alt="Crashlytics logo" />
<span class="integration-label">Crashlytics</span>
</a>
</div>
<div class="integration-lozenge integration-deskcom">
<a class="integration-link integration-deskcom" href="#deskcom">
<img class="integration-logo" src="/static/images/integrations/logos/deskcom.png" alt="Desk.com logo" />
Expand Down Expand Up @@ -635,6 +641,32 @@

</div>

<div id="crashlytics" class="integration-instructions">

<p>Zulip supports integration with Crashlytics and can notify you
about Crashlytics issues.</p>

<p>First, create the stream you'd like to use for Crashlytics notifications,
and subscribe all interested parties to this stream. We
recommend the name <code>crashlytics</code>.</p>

<p><code>{{ external_api_uri }}/v1/external/crashlytics?api_key=abcdefgh&amp;stream=crashlytics</code></p>

<p>where <code>api_key</code> is the API key of your Zulip bot,
and <code>stream</code> is the stream name you want the
notifications sent to.</p>

<p>Click on the app in
your <a href="https://fabric.io/settings/apps">Crashlytics settings panel</a>.
Next, on the integrations subpage, click “Web Hook,” enter the URL we created above and click
<code>Verify</code>.</p>
<p><b>Congratulations! You're done!</b><br /> When an issue occurs,
you'll get a notification like this:</p>

<img class="screenshot" src="/static/images/integrations/crashlytics/001.png" />

</div>

<div id="deskcom" class="integration-instructions">


Expand Down
13 changes: 13 additions & 0 deletions zerver/fixtures/crashlytics/crashlytics_issue_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"event": "issue_impact_change",
"payload_type": "issue",
"payload": {
"display_id": 123 ,
"title": "Issue Title" ,
"method": "methodName of issue",
"impact_level": 2,
"crashes_count": 54,
"impacted_devices_count": 16,
"url": "http://crashlytics.com/full/url/to/issue"
}
}
4 changes: 4 additions & 0 deletions zerver/fixtures/crashlytics/crashlytics_verification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"event": "verification",
"payload_type": "none"
}
19 changes: 19 additions & 0 deletions zerver/tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,3 +1222,22 @@ def build_webhook_url(self):

def get_body(self, fixture_name):
return {}

class CrashlyticsHookTests(WebhookTestCase):
STREAM_NAME = 'crashlytics'
URL_TEMPLATE = "/api/v1/external/crashlytics?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = 'crashlytics'

def test_crashlytics_verification_message(self):
last_message_before_request = self.get_last_message()
payload = self.get_body('verification')
url = self.build_webhook_url()
result = self.client.post(url, payload, content_type="application/json")
last_message_after_request = self.get_last_message()
self.assert_json_success(result)
self.assertEqual(last_message_after_request.pk, last_message_before_request.pk)

def test_crashlytics_build_in_success_status(self):
expected_subject = u"123: Issue Title"
expected_message = u"[Issue](http://crashlytics.com/full/url/to/issue) impacts at least 16 device(s)."
self.send_and_test_stream_message('issue_message', expected_subject, expected_message)
37 changes: 37 additions & 0 deletions zerver/views/webhooks/crashlytics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Webhooks for external integrations.
from __future__ import absolute_import
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view


CRASHLYTICS_SUBJECT_TEMPLATE = '{display_id}: {title}'
CRASHLYTICS_MESSAGE_TEMPLATE = '[Issue]({url}) impacts at least {impacted_devices_count} device(s).'

VERIFICATION_EVENT = 'verification'


@api_key_only_webhook_view('Crashlytics')
@has_request_variables
def api_crashlytics_webhook(request, user_profile, client, payload=REQ(argument_type='body'),
stream=REQ(default='crashlytics')):
try:
event = payload['event']
if event == VERIFICATION_EVENT:
return json_success()
issue_body = payload['payload']
subject = CRASHLYTICS_SUBJECT_TEMPLATE.format(
display_id=issue_body['display_id'],
title=issue_body['title']
)
body = CRASHLYTICS_MESSAGE_TEMPLATE.format(
impacted_devices_count=issue_body['impacted_devices_count'],
url=issue_body['url']
)
except KeyError as e:
return json_error(_("Missing key {} in JSON".format(e.message)))

check_send_message(user_profile, client, 'stream', [stream],
subject, body)
return json_success()
1 change: 1 addition & 0 deletions zproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
url(r'^api/v1/external/bitbucket$', 'webhooks.bitbucket.api_bitbucket_webhook'),
url(r'^api/v1/external/circleci', 'webhooks.circleci.api_circleci_webhook'),
url(r'^api/v1/external/codeship', 'webhooks.codeship.api_codeship_webhook'),
url(r'^api/v1/external/crashlytics', 'webhooks.crashlytics.api_crashlytics_webhook'),
url(r'^api/v1/external/desk$', 'webhooks.deskdotcom.api_deskdotcom_webhook'),
url(r'^api/v1/external/freshdesk$', 'webhooks.freshdesk.api_freshdesk_webhook'),
url(r'^api/v1/external/github$', 'webhooks.github.api_github_landing'),
Expand Down

0 comments on commit 8411b2e

Please sign in to comment.