def test_update_travis_4_pages():
    path_old, path_expected = _prepare_old_file("travis_3", ".yml")

    args = ['--travisfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_update_travis_installer_only_import_to_fixed_hash():
    path_old, path_expected = _prepare_old_file("travis_5", ".yml")

    args = ['--travisfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_update_clang_filter_branch():
    """ Clone dummy project, filter by branch and update it.
    """
    args = [
        '--remote', 'uilianries/conan-base64', '--dry-run', '--branch-pattern',
        'testing/*'
    ]
    command = Command()
    command.run(args)
def test_travis_update_url():
    """ Create a README.md file and update it.
    """

    path_old, path_expected = _prepare_old_file("readme_1", ".md")

    args = ['--readme', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_conanfile_2():
    """ Try to update an conanfile which old Conan recipe references
    """

    path_old, path_expected = _prepare_old_file("conan_2", ".py")

    args = ['--conanfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_gha():
    """ Try to update an GitHub actions file
    """

    path_old, path_expected = _prepare_old_file("gha_1", ".yml")

    args = ['--ghafile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_appveyor_update():
    """ Try to update an AppVeyor file
    """

    path_old, path_expected = _prepare_old_file("appveyor_1", ".yml")

    args = ['--appveyorfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_update_travis_file():
    """ Create a standard travis file and update it.
    """

    path_old, path_expected = _prepare_old_file("travis_1", ".yml")

    args = ['--travisfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_appveyor_update_new_compiler_jobs():
    """ Try to update an AppVeyor file, new compiler jobs should be added
    """

    path_old, path_expected = _prepare_old_file("appveyor_2", ".yml")

    args = ['--appveyorfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_conanfile_default_options():
    """ Try to update an conanfile which has old styled default options
    """

    path_old, path_expected = _prepare_old_file("conan_1", ".py")

    args = ['--conanfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_appveyor_3_32bit_builds_update():
    """ Update AppVeyor config file with 32bit builds, which should get removed
    """

    path_old, path_expected = _prepare_old_file("appveyor_3_32bit_builds",
                                                ".yml")

    args = ['--appveyorfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_updated_conanfile():
    """ Try to update an already up-to-date file, nothing should change
    """

    path_old, path_expected = _prepare_old_file("conan_1",
                                                ".py",
                                                old="conan_1_expected")

    args = ['--conanfile', path_old]
    command = Command()
    command.run(args)

    assert _compare_file(path_old, path_expected)
def test_conanfile_default_options():
    """ Try to update an up-to-date file
    """
    _, conan_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(conan_path, 'w') as file:
        file.write(CONAN_FILE_OLD)

    _, expected_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(expected_path, 'w') as file:
        file.write(EXPECTED_CONAN_FILE)

    args = ['--conanfile', conan_path]
    command = Command()
    command.run(args)

    assert filecmp.cmp(conan_path, expected_path)
Example #14
0
def test_update_travis_file_with_global():
    """ Create a standard travis file and update it.
    """
    _, travis_path = tempfile.mkstemp(prefix='travis', suffix='.yml')
    with open(travis_path, 'w') as file:
        file.write(TRAVIS_FILE_WITH_GLOBAL)

    _, expected_path = tempfile.mkstemp(prefix='travis', suffix='.yml')
    with open(expected_path, 'w') as file:
        file.write(EXPECTED_TRAVIS_FILE_WITH_GLOBAL)

    args = ['--travisfile', travis_path]
    command = Command()
    command.run(args)

    assert filecmp.cmp(travis_path, expected_path)
Example #15
0
def test_appveyor_update():
    """ Try to update an up-to-date file
    """
    _, appveyor_path = tempfile.mkstemp(prefix='appveyor', suffix='.yml')
    with open(appveyor_path, 'w') as file:
        file.write(APPVEYOR_FILE)

    _, expected_path = tempfile.mkstemp(prefix='appveyor', suffix='.yml')
    with open(expected_path, 'w') as file:
        file.write(EXPECTED_APPVEYOR_FILE)

    args = ['--appveyorfile', appveyor_path]
    command = Command()
    command.run(args)

    assert filecmp.cmp(appveyor_path, expected_path)
Example #16
0
def test_conanfile_default_options_mutiline():
    """ Try to update an conanfile which has old styled multiline default options
    """
    _, conan_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(conan_path, 'w') as file:
        file.write(CONAN_FILE_OLD_MULTILINE)

    _, expected_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(expected_path, 'w') as file:
        file.write(EXPECTED_CONAN_FILE)

    args = ['--conanfile', conan_path]
    command = Command()
    command.run(args)

    assert filecmp.cmp(conan_path, expected_path)
Example #17
0
def test_updated_conanfile():
    """ Try to update an already up-to-date file, nothing should change
    """
    _, conan_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(conan_path, 'w') as file:
        file.write(EXPECTED_CONAN_FILE)

    _, expected_path = tempfile.mkstemp(prefix='conanfile', suffix='.py')
    with open(expected_path, 'w') as file:
        file.write(EXPECTED_CONAN_FILE)

    args = ['--conanfile', conan_path]
    command = Command()
    command.run(args)

    assert filecmp.cmp(conan_path, expected_path)
 def file_contains(self, file, word):
     command = Command()
     return command.file_contains(file, word)
Example #19
0
    def run_action(self):
        fork_action = ForkCreateAction(repo_from=self._repo_branch_from.repo,
                                       user_to=self._user_to,
                                       interactive=self._interactive)
        fork_action.action()

        self._repo_to = fork_action.repo_to

        clone_action = RepoCloneAction(repo_from=self._repo_branch_from.repo,
                                       repo_to=self._repo_to,
                                       wd=self._wd,
                                       keep_clone=self._keep_clone,
                                       branch=self._repo_branch_from.branch)
        clone_action.action()

        repo = git.Repo(clone_action.repo_wd)

        updated = False

        def commit_changes(repo, message):
            nonlocal updated
            repo.git.add(all=True)
            if repo.is_dirty():
                repo.index.commit(message=message)
                updated = True

        if self._run_conventions:
            if self._interactive:
                if not input_ask_question_yn(
                        'Run bincrafters-conventions script?', default=True):
                    raise ActionInterrupted()
            print('Running bincrafters-conventions...')
            with chdir(clone_action.repo_wd):
                cmd = BincraftersConventionsCommand()
                cmd.run([
                    '--local',
                ])

            commit_changes(
                repo,
                'Run bincrafters-conventions\n\ncommit by {}'.format(NAME))

        if self._run_readme:
            if self._interactive:
                if not input_ask_question_yn(
                        'Run conan-readme-generator script?', default=True):
                    raise ActionInterrupted()
            print('Running conan-readme-generator...')
            with chdir(clone_action.repo_wd):
                with chargv(['']):
                    conan_readme_generator_run()

            commit_changes(
                repo,
                'Run conan-readme-generator\n\ncommit by {}'.format(NAME))

        def remote_branch_from_local(local):
            try:
                channel, version = local.split('/', 1)
                return '{}_{}/{}'.format(channel, self._channel_suffix,
                                         version)
            except ValueError:
                return '{}_{}'.format(local, self._channel_suffix)

        self._work_done = False
        if updated:
            branch_to = remote_branch_from_local(repo.active_branch.name)
            if self._interactive:
                from .util import editor_interactive_remove_comments
                branch_to = editor_interactive_remove_comments(
                    '{branch}\n\n# Enter the name of the remote branch (repo={repo})'
                    .format(branch=branch_to,
                            repo=self._repo_to.full_name)).strip()
                if not branch_to or not input_ask_question_yn(
                        'Push changes to remote branch (user={user}) "{branch}"?'
                        .format(user=self._user_to.login, branch=branch_to),
                        default=True):
                    raise ActionInterrupted()
            repo.remote(clone_action.repo_to_name).push('{}:{}'.format(
                repo.active_branch.name, branch_to))
            self._branch_to = branch_to
            self._work_done = True
def test_const_dry_run():
    """ Clone dummy project, filter by branch and update it.
    """
    args = ["--remote=bincrafters/conan-libmodplug", "--dry-run"]
    command = Command()
    result = command.run(args)
def test_update_clang_remote_project():
    """ Clone dummy project and update it.
    """
    args = ['--remote', 'uilianries/conan-base64', '--dry-run']
    command = Command()
    command.run(args)
Example #22
0
def apply_scripts_and_push(
        repo_name: str,
        from_branch: str,
        from_user: GithubUser,
        to_user: AuthenticatedUser,
        git_wd: Path,
        channel_suffix: str,
        run_conventions: bool = True,
        run_readme: bool = True,
        keep_clone: bool = False) -> typing.Optional[ConventionsApplyResult]:

    from_repo, to_repo = fork_create(repo_name, from_user, to_user)

    remote_origin = 'origin'
    remote_user = '******'

    git_repo_wd = git_wd / repo_name
    clone_repo(repo_name, keep_clone, git_wd, from_repo, to_repo,
               remote_origin, remote_user, from_branch)

    repo = git.Repo(git_repo_wd)

    updated = False

    def commit_changes(repo, message):
        nonlocal updated
        repo.git.add(all=True)
        if repo.is_dirty():
            repo.index.commit(message=message)
            updated = True

    if run_conventions:
        print('Running bincrafters-conventions...')
        with chdir(git_repo_wd):
            cmd = BincraftersConventionsCommand()
            cmd.run([
                '--local',
            ])

        commit_changes(
            repo, 'Run bincrafters-conventions\n\ncommit by {}'.format(NAME))

    if run_readme:
        print('Running conan-readme-generator...')
        with chdir(git_repo_wd):
            with chargv(['']):
                conan_readme_generator_run()

        commit_changes(
            repo, 'Run conan-readme-generator\n\ncommit by {}'.format(NAME))

    def remote_branch_from_local(local):
        try:
            channel, version = local.split('/', 1)
            return '{}_{}/{}'.format(channel, channel_suffix, version)
        except ValueError:
            return '{}_{}'.format(local, channel_suffix)

    if updated:
        remote_branch_name = remote_branch_from_local(repo.active_branch.name)
        repo.remote(remote_user).push('{}:{}'.format(repo.active_branch.name,
                                                     remote_branch_name))
        return ConventionsApplyResult(from_repo=from_repo,
                                      from_branch=from_branch,
                                      to_repo=to_repo,
                                      to_branch=remote_branch_name)
    else:
        return None