How to use the packit.config.Config.get_user_config function in packit

To help you get started, we’ve selected a few packit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github packit-service / packit / tests_recording / testbase.py View on Github external
def get_test_config():
        try:
            conf = Config.get_user_config()
        except PackitException:
            conf = Config()
        conf.dry_run = True
        return conf
github packit-service / packit / tests / unit / test_config.py View on Github external
def test_get_user_config(tmp_path):
    user_config_file_path = tmp_path / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        "debug: true\n"
        "fas_user: rambo\n"
        "keytab_path: './rambo.keytab'\n"
        "github_token: GITHUB_TOKEN\n"
        "pagure_user_token: PAGURE_TOKEN\n"
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmp_path)
    )
    config = Config.get_user_config()
    assert config.debug and isinstance(config.debug, bool)
    assert config.fas_user == "rambo"
    assert config.keytab_path == "./rambo.keytab"

    assert GithubService(token="GITHUB_TOKEN") in config.services
    assert PagureService(token="PAGURE_TOKEN") in config.services
github packit-service / packit / tests / integration / test_upstream.py View on Github external
fake_cert_path = tmp_path / "fake-cert.pem"
    fake_cert_path.write_text("hello!")

    user_config_file_path = tmp_path / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        f"authentication:\n"
        f"    github.com:\n"
        f"        github_app_private_key_path: {fake_cert_path}\n"
        f"        github_app_id: qwe\n"
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmp_path)
    )
    ups.config = Config.get_user_config()
    assert (
        GithubService(
            github_app_private_key_path=str(fake_cert_path), github_app_id="qwe"
        )
        in ups.config.services
    )
github packit-service / packit / tests / unit / test_config.py View on Github external
user_config_file_path.write_text(
        "---\n"
        "debug: true\n"
        "fas_user: rambo\n"
        "keytab_path: './rambo.keytab'\n"
        "authentication:\n"
        "    github.com:\n"
        "        token: GITHUB_TOKEN\n"
        "    pagure:\n"
        "        token: PAGURE_TOKEN\n"
        '        instance_url: "https://my.pagure.org"\n'
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmp_path)
    )
    config = Config.get_user_config()
    assert config.debug and isinstance(config.debug, bool)
    assert config.fas_user == "rambo"
    assert config.keytab_path == "./rambo.keytab"

    assert GithubService(token="GITHUB_TOKEN") in config.services
    assert (
        PagureService(token="PAGURE_TOKEN", instance_url="https://my.pagure.org")
        in config.services
    )
github packit-service / packit / tests / unit / test_config.py View on Github external
def test_user_config_fork_token(tmp_path, recwarn):
    user_config_file_path = tmp_path / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n" "pagure_fork_token: yes-is-true-in-yaml-are-you-kidding-me?\n"
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmp_path)
    )
    Config.get_user_config()
    w = recwarn.pop(UserWarning)
    assert "pagure_fork_token" in str(w.message)
github packit-service / packit / packit / service / web_hook.py View on Github external
def github_webhook():
    msg = request.get_json()

    if not msg:
        logger.debug("/webhooks/github: we haven't received any JSON data.")
        return "We haven't received any JSON data."

    if all([msg.get("zen"), msg.get("hook_id"), msg.get("hook")]):
        logger.debug(f"/webhooks/github received ping event: {msg['hook']}")
        return "Pong!"

    config = Config.get_user_config()

    if not _validate_signature(config):
        abort(401)  # Unauthorized

    # GitHub terminates the conn after 10 seconds:
    # https://developer.github.com/v3/guides/best-practices-for-integrators/#favor-asynchronous-work-over-synchronous
    # as a temporary workaround, before we start using celery, let's just respond right away
    # and send github 200 that we got it
    threadpool_executor.submit(_give_event_to_steve, msg, config)

    return "Webhook accepted. We thank you, Github."
github packit-service / packit / packit / cli / packit_base.py View on Github external
def packit_base(ctx, debug, fas_user, keytab, dry_run):
    """Integrate upstream open source projects into Fedora operating system."""
    if debug:
        # to be able to logger.debug() also in get_user_config()
        set_logging(level=logging.DEBUG)

    c = Config.get_user_config()
    c.debug = debug or c.debug
    c.dry_run = dry_run or c.dry_run
    c.fas_user = fas_user or c.fas_user
    c.keytab_path = keytab or c.keytab_path
    ctx.obj = c

    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        set_logging(logger_name="sandcastle", level=logging.DEBUG)
    else:
        set_logging(level=logging.INFO)

    packit_version = get_distribution("packitos").version
    logger.debug(f"Packit {packit_version} is being used.")