Beispiel #1
0
def create_app(name, register_blueprints=True):
    """
    Create a flask app based on Baldrick.

    Parameters
    ----------
    name : `str`
        The name to be passed to ``Flask``. This will also be used as the bot
        user name. This can be overridden with ``app.bot_username``.

    register_blueprints : `bool`
        Register the default blueprints included with Baldrick.

    Returns
    -------
    app

    """
    # Setup loguru integration, must be run before import flask.
    import baldrick.logging  # noqa

    from flask import Flask

    try:
        from werkzeug.middleware.proxy_fix import ProxyFix
    except ImportError:
        from werkzeug.contrib.fixers import ProxyFix

    from baldrick.config import load, Config
    from baldrick.blueprints import github_blueprint, circleci_blueprint

    app = Flask(name)

    app.wsgi_app = ProxyFix(app.wsgi_app)

    # Check if there is a global configuration
    app.conf = Config()
    if os.path.exists(GLOBAL_TOML):
        conf = load(GLOBAL_TOML, tool=name)
        if conf:
            app.conf = conf

    app.integration_id = int(os.environ['GITHUB_APP_INTEGRATION_ID'])
    app.private_key = os.environ['GITHUB_APP_PRIVATE_KEY']

    app.bot_username = name

    if register_blueprints:
        app.register_blueprint(github_blueprint)
        app.register_blueprint(circleci_blueprint)

    @app.route("/")
    def index():
        return "Nothing to see here"

    @app.route("/installation_authorized")
    def installation_authorized():
        return "Installation authorized"

    return app
Beispiel #2
0
def test_load(tmpdir):
    filename = tmpdir.join('pyproject.toml').strpath
    with open(filename, 'w') as f:
        f.write(GLOBAL_TOML)
    assert load(filename) == loads(GLOBAL_TOML)