def __sync_apps(team_config_git_repo: GitRepo, root_config_git_repo: GitRepo, git_user: str, git_email: str) -> None: logging.info("Team config repository: %s", team_config_git_repo.get_clone_url()) logging.info("Root config repository: %s", root_config_git_repo.get_clone_url()) repo_apps = __get_repo_apps(team_config_git_repo) logging.info("Found %s app(s) in apps repository: %s", len(repo_apps), ", ".join(repo_apps)) logging.info( "Searching apps repository in root repository's 'apps/' directory...") apps_config_file, apps_config_file_name, current_repo_apps, apps_from_other_repos = __find_apps_config_from_repo( team_config_git_repo, root_config_git_repo) if current_repo_apps == repo_apps: logging.info("Root repository already up-to-date. I'm done here.") return __check_if_app_already_exists(repo_apps, apps_from_other_repos) logging.info("Sync applications in root repository's %s.", apps_config_file_name) merge_yaml_element(apps_config_file, "applications", {repo_app: {} for repo_app in repo_apps}) __commit_and_push(team_config_git_repo, root_config_git_repo, git_user, git_email, apps_config_file_name)
def test_merge_yaml_element_create(self): test_file = self._create_file("""\ # Kept comment applications: null """) value = {"app2": {"key2": "value"}, "app3": None} merge_yaml_element(test_file, "applications", value) expected = """\ # Kept comment applications: app2: key2: value app3: """ actual = self._read_file(test_file) self.assertEqual(expected, actual)
def test_merge_yaml_element_root_dir(self): test_file = self._create_file("""\ applications: app1: # Lost comment app2: # Lost comment key: value # Lost comment """) value = {"applications": {"app2": {"key2": "value"}, "app3": None}} merge_yaml_element(test_file, ".", value) expected = """\ applications: app1: app2: key2: value app3: """ actual = self._read_file(test_file) self.assertEqual(expected, actual)