def test_gather_repository_list_filter_public_remove( mock_list_all_repositories: Mock): mock_list_all_repositories.return_value = [ _get_fake_repository_tuple( owner="owner", name="public", public=True, archived=False, ), _get_fake_repository_tuple( owner="owner", name="private", public=False, archived=False, ), ] result = gather_repository_list( Mock(), filters=[ Filter(FILTER_MODE_ADD, match_owner=".+"), Filter(FILTER_MODE_REMOVE, public=False), ], ) assert len(result) == 1 assert result[0].name == "public"
def pull(fetch_repo_list: bool, update_repos: bool, process_count: int): """Pull down repositories based on configuration""" cfg = workdir.read_config(WORKDIR) gh = github.create_github_client(cfg.credentials.api_key) user = github.get_user(gh) click.secho(f"Running under user '{user.name}' with email '{user.email}'") # get repositories db_old = workdir.read_database(WORKDIR) if fetch_repo_list: click.secho("Gathering repository list...") repositories = github.gather_repository_list(gh, cfg.repositories) # merge existing database with new one click.secho("Updating database") db_new = database.Database(user=user, repositories=repositories) db_old.merge_into(db_new) workdir.write_database(WORKDIR, db_old) else: click.secho("Not gathering repository list") repositories = db_old.repositories_to_process() # pull all repositories click.secho("Pulling repositories...") repo.pull_repositories_parallel( user, Path(cfg.credentials.ssh_key_file), WORKDIR.repos_dir, repositories, update_repos, process_count, )
def test_gather_repository_list_no_filters(mock_list_all_repositories: Mock): mock_list_all_repositories.return_value = [ _get_fake_repository_tuple( owner="owner", name="name", public=True, archived=False, ), ] result = gather_repository_list(Mock(), []) assert len(result) == 1 assert result[0].owner == "owner"
def test_gather_repository_list_filter_owner(mock_list_all_repositories: Mock): mock_list_all_repositories.return_value = [ _get_fake_repository_tuple( owner="fred", name="fred-repo", public=True, archived=True, ), _get_fake_repository_tuple( owner="boris", name="boris-repo", public=False, archived=False, ), ] result = gather_repository_list( Mock(), filters=[Filter(FILTER_MODE_ADD, match_owner="^fred*")]) assert len(result) == 1 assert result[0].name == "fred-repo"
def test_gather_repository_list_filter_archived( mock_list_all_repositories: Mock): mock_list_all_repositories.return_value = [ _get_fake_repository_tuple( owner="owner", name="archived", public=True, archived=True, ), _get_fake_repository_tuple( owner="owner", name="non-archived", public=False, archived=False, ), ] result = gather_repository_list( Mock(), filters=[Filter(FILTER_MODE_ADD, archived=True)]) assert len(result) == 1 assert result[0].name == "archived"