diff --git a/oca_repo_maintainer/cli/manage.py b/oca_repo_maintainer/cli/manage.py index 394b33c..ab52a1a 100644 --- a/oca_repo_maintainer/cli/manage.py +++ b/oca_repo_maintainer/cli/manage.py @@ -32,9 +32,14 @@ def manage(conf_dir, org, token): @click.option( "--default/--no-default", default=True, help="Set default branch as default." ) -def add_branch(conf_dir, branch, default=True): +@click.option("--repo-whitelist", help="CSV list of repo names to update") +def add_branch(conf_dir, branch, default=True, repo_whitelist=None): """Add a branch to all repositories in the configuration.""" - ConfFileManager(conf_dir).add_branch(branch, default=default) + if repo_whitelist: + repo_whitelist = [x.strip() for x in repo_whitelist.split(",") if x.strip()] + ConfFileManager(conf_dir).add_branch( + branch, default=default, repo_whitelist=repo_whitelist + ) if __name__ == "__main__": diff --git a/oca_repo_maintainer/tools/conf_file_manager.py b/oca_repo_maintainer/tools/conf_file_manager.py index 7a335a4..8897784 100644 --- a/oca_repo_maintainer/tools/conf_file_manager.py +++ b/oca_repo_maintainer/tools/conf_file_manager.py @@ -26,10 +26,13 @@ def __init__(self, conf_dir): "repo", checksum=False, by_filepath=True ) - def add_branch(self, branch, default=True): + def add_branch(self, branch, default=True, repo_whitelist=None): """Add a branch to all repositories in the configuration.""" for filepath, repo in self.conf_repo.items(): - for repo_data in repo.values(): + changed = False + for repo_slug, repo_data in repo.items(): + if repo_whitelist and repo_slug not in repo_whitelist: + continue if self._has_manual_branch_mgmt(repo_data): _logger.info( "Skipping repo %s as manual_branch_mgmt is enabled.", @@ -38,10 +41,13 @@ def add_branch(self, branch, default=True): continue if self._can_add_new_branch(branch, repo_data): repo_data["branches"].append(branch) + changed = True if default and self._can_change_default_branch(repo_data): repo_data["default_branch"] = branch - self.conf_loader.save_conf(filepath, repo) - _logger.info("Branch %s added to %s.", branch, filepath.as_posix()) + changed = True + if changed: + self.conf_loader.save_conf(filepath, repo) + _logger.info("Branch %s added to %s.", branch, filepath.as_posix()) def _has_manual_branch_mgmt(self, repo_data): return repo_data.get("manual_branch_mgmt")