<commit_before>import re
import json
import requests
from functools import update_wrapper
from django import forms
from django.conf import settings
from django.views.generic import View
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt

from sentry.utils.http import absolute_uri
from sentry.models import Organization, Team

from .utils import JsonResponse, IS_DEBUG
from .models import Tenant, Context, MentionedEvent
from .plugin import enable_plugin_for_tenant, disable_plugin_for_tenant
from .cards import make_event_notification, make_generic_notification, \
     make_subscription_update_notification, ICON, ICON2X


_link_pattern = re.escape(settings.SENTRY_URL_PREFIX) \
    .replace('https\\:', 'https?\\:') + '/'
_link_re = re.compile(_link_pattern +
    r'(?P<org>[^/]+)/(?P<proj>[^/]+)/group/'
    r'(?P<group>[^/]+)(/events/(?P<event>[^/]+)|/?)')


class DescriptorView(View):

    def get(self, request):
        return JsonResponse({
            'key': 'com.getsentry.hipchat-ac',
            'name': 'Sentry for HipChat',
            'description': 'Sentry integration for HipChat.',
            'links': {
                'self': absolute_uri(reverse('sentry-hipchat-ac-descriptor')),
            },
            'icon': {
                'url': ICON,
            },
            'capabilities': {
                'installable': {
                    'allowRoom': True,
                    'allowGlobal': False,
                    'callbackUrl': absolute_uri(reverse(
                        'sentry-hipchat-ac-installable')),
                },
                'hipchatApiConsumer': {
                    'scopes': ['send_notification', 'view_room'],
                },
                'configurable': {
                    'url': absolute_uri(reverse('sentry-hipchat-ac-config')),
                },
                'webhook': [
                    {
                        'event': 'room_message',
                        'url': absolute_uri(reverse('sentry-hipchat-ac-link-message')),
                        'pattern': _link_pattern,
                        'authentication': 'jwt',
                    },
                ],
                'webPanel': [<commit_msg>Set the key dynamically to avoid conflicts on the atlassian side.<commit_after>import re
import json
import requests
from urlparse import urlparse
from functools import update_wrapper
from django import forms
from django.conf import settings
from django.views.generic import View
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt

from sentry.utils.http import absolute_uri
from sentry.models import Organization, Team

from .utils import JsonResponse, IS_DEBUG
from .models import Tenant, Context, MentionedEvent
from .plugin import enable_plugin_for_tenant, disable_plugin_for_tenant
from .cards import make_event_notification, make_generic_notification, \
     make_subscription_update_notification, ICON, ICON2X


_link_pattern = re.escape(settings.SENTRY_URL_PREFIX) \
    .replace('https\\:', 'https?\\:') + '/'
_link_re = re.compile(_link_pattern +
    r'(?P<org>[^/]+)/(?P<proj>[^/]+)/group/'
    r'(?P<group>[^/]+)(/events/(?P<event>[^/]+)|/?)')


ADDON_HOST_IDENT = urlparse(settings.SENTRY_URL_PREFIX).hostname
if ADDON_HOST_IDENT in ('localhost', '127.0.0.1'):
    ADDON_HOST_IDENT = 'app.dev.getsentry.com'

ADDON_KEY = getattr(settings, 'HIPCHAT_SENTRY_AC_KEY', None)

if ADDON_KEY is None:
    ADDON_KEY = '.'.join(ADDON_HOST_IDENT.split('.')[::-1]) + '.hipchat-ac'


class DescriptorView(View):

    def get(self, request):
        return JsonResponse({
            'key': ADDON_KEY,
            'name': 'Sentry for HipChat',
            'description': 'Sentry integration for HipChat.',
            'links': {
                'self': absolute_uri(reverse('sentry-hipchat-ac-descriptor')),
            },
            'icon': {
                'url': ICON,
            },
            'capabilities': {
                'installable': {
                    'allowRoom': True,
                    'allowGlobal': False,
                    'callbackUrl': absolute_uri(reverse(
                        'sentry-hipchat-ac-installable')),
                },
                'hipchatApiConsumer': {
                    'scopes': ['send_notification', 'view_room'],
                },
                'configurable': {
                    'url': absolute_uri(reverse('sentry-hipchat-ac-config')),
                },
                'webhook': [
                    {
                        'event': 'room_message',
                        'url': absolute_uri(reverse('sentry-hipchat-ac-link-message')),
                        'pattern': _link_pattern,
                        'authentication': 'jwt',
                    },
                ],
                'webPanel': [
{'fraction_non_alphanumeric': 0.1207130401085061, 'fraction_numerical': 0.0017438480914551443, 'mean_word_length': 2.1727105101413646, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2197903', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1408, 'n_words': 302}