<commit_before>import asyncio, json, logging

from sinks.base_bot_request_handler import AsyncRequestHandler
import dateutil.parser


logger = logging.getLogger(__name__)


class webhookReceiver(AsyncRequestHandler):
    _bot = None

    @asyncio.coroutine
    def process_request(self, path, query_string, content):
        path = path.split("/")
        conv_or_user_id = path[1]
        if conv_or_user_id is None:
            logger.error("conversation or user id must be provided as part of path")
            return

        try:
            payload = json.loads(content)
        except Exception as e:
            logger.exception("invalid payload")

        try:
            object_kind = payload["object_kind"]
        except KeyError:
            object_kind = 'push'

        if object_kind == 'push':
            logger.debug('GITLAB push: {}'.format(json.dumps(payload)))
            html = '<b>{}</b> has pushed {} commit(s) to <a href="{}">{}</a><br/>'.format(
                    payload["user_name"], payload["total_commits_count"],
                    payload["repository"]["url"], payload["repository"]["name"])

            for commit in payload["commits"]:<commit_msg>Warn nicely if python_dateutil is missing<commit_after>import asyncio, json, logging

from sinks.base_bot_request_handler import AsyncRequestHandler

logger = logging.getLogger(__name__)

try:
    import dateutil.parser
except ImportError:
    logger.error("missing module python_dateutil: pip3 install python_dateutil")
    raise



class webhookReceiver(AsyncRequestHandler):
    _bot = None

    @asyncio.coroutine
    def process_request(self, path, query_string, content):
        path = path.split("/")
        conv_or_user_id = path[1]
        if conv_or_user_id is None:
            logger.error("conversation or user id must be provided as part of path")
            return

        try:
            payload = json.loads(content)
        except Exception as e:
            logger.exception("invalid payload")

        try:
            object_kind = payload["object_kind"]
        except KeyError:
            object_kind = 'push'

        if object_kind == 'push':
            logger.debug('GITLAB push: {}'.format(json.dumps(payload)))
            html = '<b>{}</b> has pushed {} commit(s) to <a href="{}">{}</a><br/>'.format(
                    payload["user_name"], payload["total_commits_count"],
                    payload["repository"]["url"], payload["repository"]["name"])

            for commit in payload["commits"]:
{'fraction_non_alphanumeric': 0.11634349030470914, 'fraction_numerical': 0.001187178472497032, 'mean_word_length': 2.5706214689265536, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2961554', 'n_tokens_mistral': 697, 'n_tokens_neox': 689, 'n_words': 174}