<commit_before>import subprocess
from flask import jsonify
from flask_hookserver import Hooks


def register_hooks(app):
    app.config['VALIDATE_IP'] = False
    app.config['VALIDATE_SIGNATURE'] = False

    hooks = Hooks(app, url='/hooks')

    def ping(data, delivery):
        return 'pong'
    hooks.register_hook('ping', ping)

    def new_code(data, delivery):
        print('New push to %s' % data['ref'])
        if data['ref'] == 'refs/heads/master':
            try:
                cmd_output = subprocess.check_output(
                    ['git', 'pull', 'origin', 'master'],)
                return jsonify({'msg': str(cmd_output)})
            except subprocess.CalledProcessError as error:
                print("Code deployment failed", error.output)
                return jsonify({'msg': str(error.output)})
        return 'Thanks'
    hooks.register_hook('push', new_code)

    return None
<commit_msg>Make git hooks library optional<commit_after>import subprocess
from flask import jsonify
try:
    from flask_hookserver import Hooks
except ImportError:
    Hooks = False


def register_hooks(app):
    app.config['VALIDATE_IP'] = False
    app.config['VALIDATE_SIGNATURE'] = False

    if not Hooks:
        return None

    hooks = Hooks(app, url='/hooks')

    def ping(data, delivery):
        return 'pong'
    hooks.register_hook('ping', ping)

    def new_code(data, delivery):
        print('New push to %s' % data['ref'])
        if data['ref'] == 'refs/heads/master':
            try:
                cmd_output = subprocess.check_output(
                    ['git', 'pull', 'origin', 'master'],)
                return jsonify({'msg': str(cmd_output)})
            except subprocess.CalledProcessError as error:
                print("Code deployment failed", error.output)
                return jsonify({'msg': str(error.output)})
        return 'Thanks'
    hooks.register_hook('push', new_code)

    return None

{'fraction_non_alphanumeric': 0.12217659137577003, 'fraction_numerical': 0.0, 'mean_word_length': 2.511711711711712, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6460172', 'n_tokens_mistral': 578, 'n_tokens_neox': 556, 'n_words': 142}