From 98b96193a0ce4c5503e0bd6469b23506ce357ec1 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 13 Sep 2024 15:28:26 +0200 Subject: [PATCH] ConfFileManager: add manual_branch_mgmt option Repos marked with this flag won't be manageable by oca-repo-add-branch --- README.md | 2 ++ .../tools/conf_file_manager.py | 9 +++++ .../conf_with_tools/repo/repo_for_addons.yml | 11 ++++++ tests/test_conf_file_manager.py | 35 +++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/README.md b/README.md index 7b195d0..a5bfbde 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ Go to the conf repo on your file system and run this: Review, stage all the changes, commit and open a PR. +You can prevent this tool to edit a repo by adding ``manual_branch_mgmt`` boolean flag to repo's conf. + ## Licenses This repository is licensed under [AGPL-3.0](LICENSE). diff --git a/oca_repo_maintainer/tools/conf_file_manager.py b/oca_repo_maintainer/tools/conf_file_manager.py index 9b2d1ab..7a335a4 100644 --- a/oca_repo_maintainer/tools/conf_file_manager.py +++ b/oca_repo_maintainer/tools/conf_file_manager.py @@ -30,6 +30,12 @@ def add_branch(self, branch, default=True): """Add a branch to all repositories in the configuration.""" for filepath, repo in self.conf_repo.items(): for repo_data in repo.values(): + if self._has_manual_branch_mgmt(repo_data): + _logger.info( + "Skipping repo %s as manual_branch_mgmt is enabled.", + filepath.as_posix(), + ) + continue if self._can_add_new_branch(branch, repo_data): repo_data["branches"].append(branch) if default and self._can_change_default_branch(repo_data): @@ -37,6 +43,9 @@ def add_branch(self, branch, default=True): 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") + frozen_branches = ("master", "main") def _can_add_new_branch(self, branch, repo_data): diff --git a/tests/conf_with_tools/repo/repo_for_addons.yml b/tests/conf_with_tools/repo/repo_for_addons.yml index daf0fa7..5872ff1 100644 --- a/tests/conf_with_tools/repo/repo_for_addons.yml +++ b/tests/conf_with_tools/repo/repo_for_addons.yml @@ -10,3 +10,14 @@ test-repo-for-addons: branches: - "16.0" - "15.0" +test-repo-for-addons-manual: + name: Test repo for addons with manual mgmt flag + description: Repo used to run real tests on oca-repo-manage tool. + category: Logistics + psc: test-team-1 + maintainers: [] + default_branch: "16.0" + branches: + - "16.0" + - "15.0" + manual_branch_mgmt: true diff --git a/tests/test_conf_file_manager.py b/tests/test_conf_file_manager.py index 0e09e9c..886551f 100644 --- a/tests/test_conf_file_manager.py +++ b/tests/test_conf_file_manager.py @@ -77,3 +77,38 @@ def test_preserve_master(self): self.assertEqual( conf["test-repo-for-tools-with-no-branches"]["default_branch"], "master" ) + + def test_skip_manual_mgmt(self): + with tempfile.TemporaryDirectory() as temp_dir: + shutil.copytree( + conf_path_with_tools.as_posix(), temp_dir, dirs_exist_ok=True + ) + manager = ConfFileManager(temp_dir) + conf = manager.conf_loader.load_conf("repo") + + self.assertEqual(conf["test-repo-for-addons"]["branches"], ["16.0", "15.0"]) + self.assertEqual(conf["test-repo-for-addons"]["default_branch"], "16.0") + self.assertEqual( + conf["test-repo-for-addons-manual"]["branches"], ["16.0", "15.0"] + ) + self.assertEqual( + conf["test-repo-for-addons-manual"]["default_branch"], "16.0" + ) + self.assertEqual( + conf["test-repo-for-addons-manual"]["manual_branch_mgmt"], True + ) + + manager.add_branch("100.0") + + conf = manager.conf_loader.load_conf("repo") + + self.assertEqual( + conf["test-repo-for-addons"]["branches"], ["16.0", "15.0", "100.0"] + ) + self.assertEqual(conf["test-repo-for-addons"]["default_branch"], "100.0") + self.assertEqual( + conf["test-repo-for-addons-manual"]["branches"], ["16.0", "15.0"] + ) + self.assertEqual( + conf["test-repo-for-addons-manual"]["default_branch"], "16.0" + )