"""
sentry_freight.plugin
~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2015 by Sentry Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
"""

import json

import sentry_freight

from sentry.plugins import ReleaseHook, ReleaseTrackingPlugin


class FreightReleaseHook(ReleaseHook):
    def handle(self, request):
        data = json.loads(request.body)
        if data['event'] == 'started':
            self.start_release(
                version=data['sha'],
            )
        elif data['event'] == 'finished':
            self.finish_release(
                version=data['sha'],
            )
        else:
            raise ValueError(data['event'])


class FreightPlugin(ReleaseTrackingPlugin):
    author = 'Sentry Team'
    author_url = 'https://github.com/getsentry'
    resource_links = (
        ('Bug Tracker', 'https://github.com/getsentry/sentry-freight/issues'),
        ('Source', 'https://github.com/getsentry/sentry-freight'),
    )

    title = 'Freight'
    slug = 'freight'
    description = 'Integrate Freight release tracking.'
    version = sentry_freight.VERSION

    def get_release_doc_html(self, hook_url):
        return """
        <p>Configure a Freight notification with the given webhook url.</p>
        <pre class="clippy">{{
            "type": "sentry",
            "config": {{"webhook_url": "{hook_url}"}}
        }}</pre>
        """.format(hook_url=hook_url)

    def get_release_hook(self):
        return FreightReleaseHook

@@ -265,16 +265,204 @@
 Plugin%0A%0A
+DOC_HTML = %22%22%22%0A%3Cp%3EConfigure a Freight notification with the given webhook url.%3C/p%3E%0A%3Cpre class=%22clippy%22%3E%7B%7B%0A    %22type%22: %22sentry%22,%0A    %22config%22: %7B%7B%22webhook_url%22: %22%7Bhook_url%7D%22%7D%7D%0A%7D%7D%3C/pre%3E%0A%22%22%22%0A%0A
 %0Aclass F
@@ -1369,231 +1369,16 @@
 urn 
-%22%22%22%0A        %3Cp%3EConfigure a Freight notification with the given webhook url.%3C/p%3E%0A        %3Cpre class=%22clippy%22%3E%7B%7B%0A            %22type%22: %22sentry%22,%0A            %22config%22: %7B%7B%22webhook_url%22: %22%7Bhook_url%7D%22%7D%7D%0A        %7D%7D%3C/pre%3E%0A        %22%22%22
+DOC_HTML
 .for

Fix example