Example #1
0
def webhook_circle_ci():
    data = request.json['payload']

    embed = MessageEmbed()

    if data['outcome'] == 'success':
        embed.color = 0x42c88a
    else:
        embed.color = 0xed5c5c

    embed.title = 'Build #{} - {} ({})'.format(
        data['build_num'],
        data['subject'],
        data['author_name'],
    )

    embed.url = data['build_url']

    steps = []
    for step in data['steps']:
        emoji = ':x:' if any(
            True for act in step['actions']
            if act.get('failed', False)) else ':white_check_mark:'
        steps.append('{} - {}'.format(emoji, step['name']))

    embed.description = '\n'.join(steps)
    embed.description += '\n [View Diff]({})'.format(data['compare'])

    Webhook.execute_url(current_app.config.get('WEBHOOK_URL'), embeds=[embed])

    if data['outcome'] != 'success':
        return

    subprocess.Popen(['git', 'pull', 'origin', 'master']).wait()
    rdb.publish('actions', json.dumps({
        'type': 'RESTART',
    }))
    return '', 200
Example #2
0
def send_webhook(embed, url):
    return Webhook.execute_url(url, embeds=[embed])