Skip to content

Commit

Permalink
ConfFileManager: add manual_branch_mgmt option
Browse files Browse the repository at this point in the history
Repos marked with this flag won't be manageable by oca-repo-add-branch
  • Loading branch information
simahawk committed Sep 13, 2024
1 parent e3d5c99 commit 98b9619
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
9 changes: 9 additions & 0 deletions oca_repo_maintainer/tools/conf_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ 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):
repo_data["default_branch"] = branch
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):
Expand Down
11 changes: 11 additions & 0 deletions tests/conf_with_tools/repo/repo_for_addons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions tests/test_conf_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 98b9619

Please sign in to comment.