コード例 #1
0
ファイル: hooks.py プロジェクト: somosazucar/Jappy
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
コード例 #2
0
""" Flask app for github hook server. """
import os

from flask import Flask
from flask_hookserver import Hooks

APP = Flask(__name__)
APP.config['GITHUB_WEBHOOKS_KEY'] = os.environ.get('GITHUB_WEBHOOKS_KEY')
APP.config['VALIDATE_IP'] = (os.environ.get('GIT_HOOK_VALIDATE_IP',
                                            'True').lower()
                             not in ['false', '0'])
APP.config['VALIDATE_SIGNATURE'] = (os.environ.get(
    'GIT_HOOK_VALIDATE_SIGNATURE', 'True').lower() not in ['false', '0'])

HOOKS = Hooks(APP, url='/hooks')

# See http://flask.pocoo.org/docs/0.12/patterns/packages/ for information
import app.views  # noqa F401 pylint: disable=wrong-import-position
コード例 #3
0
ファイル: hooks.py プロジェクト: hashim361/website-2
import json
import uuid

from flask_hookserver import Hooks

from .db import redis
from .members.models import User
from .projects.tasks import update_project_by_hook
from .tasks import spinach

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
        member.save()
    elif data["action"] == "removed":
        member.is_member = False
        member.save()
コード例 #4
0
# flask app
app = Flask(__name__)

# twitter auth by tweepy
twitter_auth = tweepy.OAuthHandler(twitter_consumer_key,
                                   twitter_consumer_secret)
twitter_auth.set_access_token(twitter_access_token,
                              twitter_access_token_secret)
twitter_api = tweepy.API(twitter_auth)

# github webhooks & request checking options
app.config['GITHUB_WEBHOOKS_KEY'] = github_webhooks_secret
app.config['VALIDATE_IP'] = False
app.config['VALIDATE_SIGNATURE'] = True
hooks = Hooks(app, url='/webhooks')


# flask routes
@app.route('/')
def hello():
    return '<a href="{0}">{0}</a>'.format(
        'https://github.com/open-source-ideas')


@hooks.hook('issues')
def issues(data, delivery):
    twitter_update_status = 'This hook is not implemented'
    # Tweet only newly created issues
    if (data['action'] == 'opened'):
        tweet_max_len = 278
コード例 #5
0
ファイル: manage.py プロジェクト: cenkalti/putio-automator
        return None


client = None


def init_client(c=None):
    global client

    if c is None:
        c = putio.Client(app.config['PUTIO_TOKEN'], use_retry=True)
    client = c
    return c


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


@hooks.hook('push')
def push(data, guid):
    if app.config['DEPLOY_DEVELOP'] and data['ref'] == 'refs/heads/develop':
        subprocess.call('git pull'.split(' '))

    return 'OK'


manager = Manager(app)


@manager.command
def transfers_cancel_by_status(statuses):
コード例 #6
0
ファイル: app.py プロジェクト: Duckle29/webhook_server
from flask_hookserver import Hooks

from werkzeug.middleware.proxy_fix import ProxyFix
from werkzeug.exceptions import InternalServerError

config = ConfigParser(interpolation=None)
config.read('config.ini')

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1)

app.config['GITHUB_WEBHOOKS_KEY'] = config['main']['github_secret']
app.config['VALIDATE_IP'] = True
app.config['VALIDATE_SIGNATURE'] = True

deploy_hook = Hooks(app, url=config['main']['endpoint'])


@deploy_hook.hook('push')
def deploy(data, guid):
    """Pulls the new site, triggered by a github webhook

    Args:
        data (dict): The webhook payload
        guid ([type]): No clue. read the flask_hookserver docs ;)

    Raises:
        InternalServerError: If it fails to pull

    Returns:
        string: A string to log that it deployed a website
コード例 #7
0
def redirect_github_issue(match):
    """ Custom routing rule to redirect /issue/NNN to the corresponding
    issue on GitHub """
    return 'https://github.com/PlaidWeb/Publ/issues/' + match.group(1), True


@app.path_alias_regex(r'/site-issue/(.*)')
def redirect_github_site_issue(match):
    """ Custom routing rule to redirect /issue/NNN to the corresponding
    issue on GitHub """
    return 'https://github.com/PlaidWeb/Publ-site/issues/' + match.group(
        1), True


# Deployment hook for self-hosted instance
hooks = Hooks(app, url='/_gh')


@hooks.hook('push')
def deploy(data, delivery):
    import threading
    import subprocess
    import flask

    try:
        result = subprocess.check_output(['./deploy.sh', 'nokill'],
                                         stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as err:
        LOGGER.error("Deployment failed: %s", err.output)
        return flask.Response(err.output,
                              status_code=500,
コード例 #8
0
ファイル: app.py プロジェクト: pir8aye/flowbot-github
from flask import Flask
from bot import WebhookBot
from flask_hookserver import Hooks
from webhooks import GithubWebhookConsumer
from settings import settings

app = Flask(__name__)

app.config['GITHUB_WEBHOOKS_KEY'] = settings.get('github_webhook_secret')
app.config['VALIDATE_IP'] = settings.get('github_validate_ip', False)
app.config['VALIDATE_SIGNATURE'] = settings.get('github_validate_signature',
                                                True)  # NOQA

bot = WebhookBot(settings)
webhook_consumer = GithubWebhookConsumer(bot)
hooks = Hooks(app, bot.hooks_endpoint)


@hooks.hook('ping')
def ping_webhook(payload, guid):
    """Handle GitHub Ping (sent when webhook is created)."""
    return webhook_consumer.process(payload, 'ping')


@hooks.hook('issues')
def issue_webhook(payload, guid):
    """Handle GitHub Issue Events."""
    return webhook_consumer.process(payload, 'issues')


@hooks.hook('pull_request')
コード例 #9
0
pu = get_public_url()
print pu

if (pu != ''):
    update_github_webhook(config.get('github-token'),
                          config.get('github-owner'),
                          config.get('github-repo'), pu)
else:
    print "Fatal: unable to retrieve ngrok tunnel url"
    ngrok.terminate()
    sys.exit(0)

app = Flask(__name__)
app.config['VALIDATE_IP'] = False
app.config['VALIDATE_SIGNATURE'] = False
hooks = Hooks(app, url='/')


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


@hooks.hook('push')
def push(data, guid):
    g = git.cmd.Git('/root/porte42/')
    print "pulling..."
    g.pull()
    print "done."
    return 'pull'
コード例 #10
0
# -*- coding: utf-8 -*-
"""Extensions module. Each extension is initialized in the app factory located in app.py."""
from flask_admin import Admin
from flask_bcrypt import Bcrypt
from flask_caching import Cache
from flask_cors import CORS
from flask_debugtoolbar import DebugToolbarExtension
from flask_wtf.csrf import CSRFProtect
from flask_flatpages import FlatPages
from flask_hookserver import Hooks
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail

bcrypt = Bcrypt()
csrf = CSRFProtect()
admin = Admin(name='Admin Adopta Árbol', base_template='admin/adoptarbol.html')
login_manager = LoginManager()
db = SQLAlchemy()
migrate = Migrate()
cache = Cache()
debug_toolbar = DebugToolbarExtension()
pages = FlatPages()
api_manager = APIManager(flask_sqlalchemy_db=db)
hooks = Hooks(url='/hooks')
cors = CORS
mail = Mail()