@api.route('/webhooks')
async def webhooks(req, resp):
    '\n    Handle incoming GitHub webhooks\n    '
    data = (await req.media())
    eventid = req.headers.get('X-GitHub-Delivery')
    event = req.headers.get('X-GitHub-Event')
    if (not Subscriptions.is_listening_for(event)):
        resp.text = f'Accepted, but not listening for {event} events.'
        return
    if env.webhook_secret:
        signature = req.headers.get('X-Hub-Signature')
        assert signature, 'X-Hub-Signature not found in the header.'
        (sha_name, signature) = signature.split('=')
        assert (sha_name == 'sha1')
        mac = hmac.new(env.webhook_secret, msg=data, digestmod='sha1')
        assert (str(mac.hexdigest()) == str(signature))
    Subscriptions.publish(eventid, event, {'event': event, 'payload': data})
    resp.text = 'Accepted'
Handle incoming GitHub webhooks
@api.route('/webhooks')
async def webhooks(req, resp):
    '\n    \n    '
    data = (await req.media())
    eventid = req.headers.get('X-GitHub-Delivery')
    event = req.headers.get('X-GitHub-Event')
    if (not Subscriptions.is_listening_for(event)):
        resp.text = f'Accepted, but not listening for {event} events.'
        return
    if env.webhook_secret:
        signature = req.headers.get('X-Hub-Signature')
        assert signature, 'X-Hub-Signature not found in the header.'
        (sha_name, signature) = signature.split('=')
        assert (sha_name == 'sha1')
        mac = hmac.new(env.webhook_secret, msg=data, digestmod='sha1')
        assert (str(mac.hexdigest()) == str(signature))
    Subscriptions.publish(eventid, event, {'event': event, 'payload': data})
    resp.text = 'Accepted'