<commit_before>from flask import render_template
from flask_hookserver import Hooks

from .github import github
from .models import db, User


hooks = Hooks()


@hooks.hook('ping')
def ping(data, guid):
    return 'pong'


@hooks.hook('membership')
def membership(data, guid):
    if data['scope'] != 'team':
        return
    member = User.query.filter_by(id=data['member']['id']).first()
    if member is None:
        return
    if data['action'] == 'added':
        member.is_member = True
        db.session.commit()
    elif data['action'] == 'removed':
        member.is_member = False
        db.session.commit()
    return 'Thanks'


@hooks.hook('member')
def member(data, guid):
    # if no action was given or it was about removing a member
    if data.get('action') != 'added':
        return

    # if there is no repo data
    repo = data.get('repository')
    if repo is None:
        return

    data = {
        'title': render_template('hooks/transfer-title.txt', **data),
        'body': render_template('hooks/transfer-body.txt', **data),
        'labels': ['transfer'],
    }

    response = github.post(
        'repos/jazzband/roadies/issues',
        data,
        access_token=github.admin_access_token,
    )
    return 'Thanks'<commit_msg>Assign to sender<commit_after>from flask import render_template
from flask_hookserver import Hooks

from .github import github
from .models import db, User


hooks = Hooks()


@hooks.hook('ping')
def ping(data, guid):
    return 'pong'


@hooks.hook('membership')
def membership(data, guid):
    if data['scope'] != 'team':
        return
    member = User.query.filter_by(id=data['member']['id']).first()
    if member is None:
        return
    if data['action'] == 'added':
        member.is_member = True
        db.session.commit()
    elif data['action'] == 'removed':
        member.is_member = False
        db.session.commit()
    return 'Thanks'


@hooks.hook('member')
def member(data, guid):
    # if no action was given or it was about removing a member
    if data.get('action') != 'added':
        return

    # if there is no repo data
    repo = data.get('repository')
    if repo is None:
        return

    data = {
        'title': render_template('hooks/transfer-title.txt', **data),
        'body': render_template('hooks/transfer-body.txt', **data),
        'labels': ['transfer'],
        'assignees': [repo['sender']['login']] if 'sender' in repo else [],
    }

    response = github.post(
        'repos/jazzband/roadies/issues',
        data,
        access_token=github.admin_access_token,
    )
    return 'Thanks'
{'fraction_non_alphanumeric': 0.14006888633754305, 'fraction_numerical': 0.0, 'mean_word_length': 2.772005772005772, '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': '7613448', 'n_tokens_mistral': 808, 'n_tokens_neox': 794, 'n_words': 214}