# Buggy code
def _wrapped_view_func(view_func):
    # type: (Callable[..., HttpResponse]) -> Callable[..., HttpResponse]
    @csrf_exempt
    @has_request_variables
    @wraps(view_func)
    def _wrapped_func_arguments(request, api_key=REQ(), *args, **kwargs):
        # type: (HttpRequest, Text, *Any, **Any) -> HttpResponse
        try:
            user_profile = UserProfile.objects.get(api_key=api_key)
        except UserProfile.DoesNotExist:
            raise JsonableError(_("Invalid API key"))
        if not user_profile.is_active:
            raise JsonableError(_("Account not active"))
        if user_profile.realm.deactivated:
            raise JsonableError(_("Realm for account has been deactivated"))
        if not check_subdomain(get_subdomain(request), user_profile.realm.subdomain):
            logging.warning(
                "User %s attempted to access webhook API on wrong subdomain %s"
                % (user_profile.email, get_subdomain(request))
            )
            raise JsonableError(_("Account is not associated with this subdomain"))

        request.user = user_profile
        request._email = user_profile.email
        webhook_client_name = "Zulip{}Webhook".format(client_name)
        process_client(request, user_profile, client_name=webhook_client_name)
        if settings.RATE_LIMITING:
            rate_limit_user(request, user_profile, domain="all")
        return view_func(request, user_profile, *args, **kwargs)

    return _wrapped_func_arguments


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "./zerver/webhooks/github_dispatcher.py", line 15, in api_github_webhook_dispatch
return api_github_landing(request)
File "/home/zulip/deployments/2017-05-10-06-16-16/zulip-venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "./zerver/decorator.py", line 104, in wrapper
return func(request, *args, **kwargs)
File "./zerver/lib/request.py", line 166, in _wrapped_view_func
return view_func(request, *args, **kwargs)
File "./zerver/decorator.py", line 384, in _wrapped_func_arguments
return limited_func(request, user_profile, *args, **kwargs)
File "./zerver/decorator.py", line 664, in wrapped_func
return func(request, *args, **kwargs)
File "./zerver/lib/request.py", line 166, in _wrapped_view_func
return view_func(request, *args, **kwargs)
File "./zerver/webhooks/github/view.py", line 270, in api_github_landing
**kwargs)
File "./zerver/webhooks/github/view.py", line 175, in api_github_v2
created=payload['created'])
File "./zerver/webhooks/github/view.py", line 294, in build_message_from_gitlog
content = get_push_commits_event_message(pusher, url, short_ref, commits)
File "./zerver/lib/webhooks/git.py", line 64, in get_push_commits_event_message
committers_details = "{} ({})".format(*committers_items[0])
IndexError: list index out of range

# Fixed code
def _wrapped_view_func(view_func):
    # type: (Callable[..., HttpResponse]) -> Callable[..., HttpResponse]
    @csrf_exempt
    @has_request_variables
    @wraps(view_func)
    def _wrapped_func_arguments(request, api_key=REQ(), *args, **kwargs):
        # type: (HttpRequest, Text, *Any, **Any) -> HttpResponse
        try:
            user_profile = UserProfile.objects.get(api_key=api_key)
        except UserProfile.DoesNotExist:
            raise JsonableError(_("Invalid API key"))
        if not user_profile.is_active:
            raise JsonableError(_("Account not active"))
        if user_profile.realm.deactivated:
            raise JsonableError(_("Realm for account has been deactivated"))
        if not check_subdomain(get_subdomain(request), user_profile.realm.subdomain):
            logging.warning(
                "User %s attempted to access webhook API on wrong subdomain %s"
                % (user_profile.email, get_subdomain(request))
            )
            raise JsonableError(_("Account is not associated with this subdomain"))

        request.user = user_profile
        request._email = user_profile.email
        webhook_client_name = "Zulip{}Webhook".format(client_name)
        process_client(request, user_profile, client_name=webhook_client_name)
        if settings.RATE_LIMITING:
            rate_limit_user(request, user_profile, domain="all")
        try:
            return view_func(request, user_profile, *args, **kwargs)
        except Exception:
            if request.content_type == "application/json":
                request_body = ujson.dumps(ujson.loads(request.body), indent=4)
            else:
                request_body = request.body
            message = """
user: {email} ({realm})
client: {client_name}
URL: {path_info}
body:

{body}
                """.format(
                email=user_profile.email,
                realm=user_profile.realm.string_id,
                client_name=webhook_client_name,
                body=request_body,
                path_info=request.META.get("PATH_INFO", None),
            )
            webhook_logger.exception(message)
            raise

    return _wrapped_func_arguments