<commit_before>from bottle import request, post, run, abort, Bottle
import json
from os.path import normpath, dirname, abspath, join
from ghi_assist.utils import byteify
from ghi_assist.webhook import Webhook
from ghi_assist.hooks import AssignRelatedHook, ClaimHook, CommentLabelHook, NewIssueLabelHook, \
    NewPrLabelHook, PingHook

app = Bottle()
path = normpath(abspath(dirname(__file__)))
with open(join(path, 'config.json')) as config_file:
    app.config.load_dict(byteify(json.load(config_file)))

webhook = Webhook(secret=app.config["github.secret"], api_token=app.config["github.api_token"])
webhook.register("ping", PingHook())
webhook.register("issue_comment", CommentLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"]
))
webhook.register("issue_comment", ClaimHook())
webhook.register("issues", NewIssueLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"]
))
webhook.register("pull_request", NewPrLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"]
))
webhook.register("pull_request", AssignRelatedHook())

@post('/')
def github_webhook():
    """
    Main app entrypoint.
    """
    signature_header = request.headers.get('X-Hub-Signature')
    if signature_header is None:
        abort(403, "No X-Hub-Signature header.")

    digest_mode, signature = signature_header.split('=')
    if digest_mode != "sha1":
        abort(501, "'%s' not supported." % digest_mode)
    if not webhook.signature_valid(data=request.body.read(), signed_data=signature):
        abort(403, "Signature does not match expected value.")

    event = request.headers.get('X-GitHub-Event')
    responses = webhook.respond_to(event, request.json)
    return "Responded to %s.\n%s" % (event, "\n".join(responses))

run(host='localhost', port=8080)<commit_msg>Get first element of the array for labels.aliases<commit_after>from bottle import request, post, run, abort, Bottle
import json
from os.path import normpath, dirname, abspath, join
from ghi_assist.utils import byteify
from ghi_assist.webhook import Webhook
from ghi_assist.hooks import AssignRelatedHook, ClaimHook, CommentLabelHook, NewIssueLabelHook, \
    NewPrLabelHook, PingHook

app = Bottle()
path = normpath(abspath(dirname(__file__)))
with open(join(path, 'config.json')) as config_file:
    app.config.load_dict(byteify(json.load(config_file)))

webhook = Webhook(secret=app.config["github.secret"], api_token=app.config["github.api_token"])
webhook.register("ping", PingHook())
webhook.register("issue_comment", CommentLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0] # hidden in an array to prevent the nesting from being used
                                            # as namespace by load_dict
))
webhook.register("issue_comment", ClaimHook())
webhook.register("issues", NewIssueLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0]
))
webhook.register("pull_request", NewPrLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0]
))
webhook.register("pull_request", AssignRelatedHook())

@post('/')
def github_webhook():
    """
    Main app entrypoint.
    """
    signature_header = request.headers.get('X-Hub-Signature')
    if signature_header is None:
        abort(403, "No X-Hub-Signature header.")

    digest_mode, signature = signature_header.split('=')
    if digest_mode != "sha1":
        abort(501, "'%s' not supported." % digest_mode)
    if not webhook.signature_valid(data=request.body.read(), signed_data=signature):
        abort(403, "Signature does not match expected value.")

    event = request.headers.get('X-GitHub-Event')
    responses = webhook.respond_to(event, request.json)
    return "Responded to %s.\n%s" % (event, "\n".join(responses))

run(host='localhost', port=8080)
{'fraction_non_alphanumeric': 0.13938780672906653, 'fraction_numerical': 0.007842145206172527, 'mean_word_length': 5.027439024390244, 'pattern_counts': {'":': 2, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4499380', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1246, 'n_words': 253}