Exemplo n.º 1
0
def test_output_for_diff_on_web_hooks(mock_confirm, log_info):
    mock_confirm.return_value = None
    log_info.return_value = None
    mock_confirm.sealed = True
    log_info.sealed = True

    current_hooks = [{
        "name": "web",
        "config": {
            "url": "http://chooserandom.com"
        },
        "active": True
    }]
    new_hooks = [{
        "name": "web",
        "config": {
            "url": "http://chooserandom.com"
        },
        "active": False
    }]

    utils.confirm_changes(dict(hooks=current_hooks), dict(hooks=new_hooks))

    assert 1 == mock_confirm.call_count
    log_info.assert_any_call(
        StringContains("C ", "http://chooserandom.com", "True", "False"))
Exemplo n.º 2
0
def _update_all_repos(gh, org, input_file, repo_filter=None):
    """Updates all repos of an org with the specified repo config

    This will iterate over all repos in the org and update them with the template provided
    "Repo specific fields" will be ignored if presents in the repo file

    If a repo filter is provided the name of the repo have to match with that
    """
    ignored_options = ["name", "description", "homepage"]

    new_config = utils.load_yaml(input_file)
    if any(_ in new_config["options"] for _ in ignored_options):
        message = ("{} keys wont be updated but they are present in {}.\n"
                   "Continue anyway?".format(ignored_options, input_file))
        click.confirm(message, abort=True, default=True)

    for field in ignored_options:
        new_config["options"].pop(field, None)

    for repo_name in org.repos:
        if repo_filter and not fnmatch.fnmatch(repo_name, repo_filter):
            LOG.info("Skipping '{}/{}'".format(org.name, repo_name))
            continue
        LOG.info("Updating %s", repo_name)
        r = Repo(gh, org.name, repo_name)
        current_config = r.describe()
        for field in set(ignored_options) - {"name"}:
            current_config["options"].pop(field, None)
        new_config["options"]["name"] = repo_name
        if utils.confirm_changes(current_config, new_config):
            r.update(new_config)

    LOG.info("All repos in %s processed", org.name)
Exemplo n.º 3
0
def test_confirm_changes_str_unicode_changes_are_ignored(mock_confirm):
    mock_confirm.return_value = None
    mock_confirm.sealed = True

    utils.confirm_changes(dict(options=u"B"), dict(options="B"))
    assert 0 == mock_confirm.call_count
Exemplo n.º 4
0
def test_confirm_changes_missing_keys_are_ignored(mock_confirm):
    mock_confirm.return_value = None
    mock_confirm.sealed = True

    utils.confirm_changes(dict(options="B", hooks="C"), dict(options="B"))
    assert 0 == mock_confirm.call_count
Exemplo n.º 5
0
def test_confirm_changes_with_changes(mock_confirm):
    mock_confirm.return_value = None
    mock_confirm.sealed = True

    utils.confirm_changes(dict(options="B"), dict(options="A"))
    assert 1 == mock_confirm.call_count
Exemplo n.º 6
0
def test_confirm_changes_no_change(mock_confirm):
    mock_confirm.return_value = None
    mock_confirm.sealed = True

    utils.confirm_changes({}, {})
    assert 0 == mock_confirm.call_count
Exemplo n.º 7
0
def _push_org(org, input_file):
    """Update the organization config in github"""
    new_config = utils.load_yaml(input_file)
    current_config = org.describe()
    if utils.confirm_changes(current_config, new_config, abort=True):
        org.update(new_config)
Exemplo n.º 8
0
def _push_repo(repo, input_file):
    """Update the repository config in github"""
    new_config = utils.load_yaml(input_file)
    current_config = repo.describe()
    if utils.confirm_changes(current_config, new_config, abort=True):
        repo.update(new_config)