Skip to content

Commit

Permalink
ConfFileManager: preserve main branch for tools
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Sep 13, 2024
1 parent a1c3f47 commit e3d5c99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
8 changes: 5 additions & 3 deletions oca_repo_maintainer/tools/conf_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ 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())

frozen_branches = ("master", "main")

def _can_add_new_branch(self, branch, repo_data):
branches = repo_data["branches"]
return (
branch not in branches
and "master" not in branches
and repo_data.get("default_branch") != "master"
and all(x not in branches for x in self.frozen_branches)
and repo_data.get("default_branch") not in self.frozen_branches
)

def _can_change_default_branch(self, repo_data):
Expand All @@ -51,5 +53,5 @@ def _can_change_default_branch(self, repo_data):
"default_branch" in repo_data
# If the branch is "master" it means this is likely the repo of a tool
# and we have only one working branch.
and repo_data["default_branch"] != "master"
and repo_data["default_branch"] not in self.frozen_branches
)
13 changes: 11 additions & 2 deletions tests/conf_with_tools/repo/repo_for_tools.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# For testing: this repo must NOT exist to test creation
test-repo-for-tools:
name: Repository for tools
test-repo-for-tools-1:
name: Repository for tools with branch = master
description: Repo used to run real tests on oca-repo-manage tool.
category: Accounting
psc: test-team-2
Expand All @@ -9,6 +9,15 @@ test-repo-for-tools:
default_branch: "master"
branches:
- "master"
test-repo-for-tools-2:
name: Repository for tools with branch = main
description: Repo used to run real tests on oca-repo-manage tool.
category: Accounting
psc: test-team-2
maintainers:
- simahawk
default_branch: "main"
branches: []
test-repo-for-tools-with-no-branches:
name: Repository for tools
description: Repo used to run real tests on oca-repo-manage tool.
Expand Down
12 changes: 8 additions & 4 deletions tests/test_conf_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def test_preserve_master(self):

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-tools"]["branches"], ["master"])
self.assertEqual(conf["test-repo-for-tools"]["default_branch"], "master")
self.assertEqual(conf["test-repo-for-tools-1"]["branches"], ["master"])
self.assertEqual(conf["test-repo-for-tools-1"]["default_branch"], "master")
self.assertEqual(conf["test-repo-for-tools-2"]["branches"], [])
self.assertEqual(conf["test-repo-for-tools-2"]["default_branch"], "main")
self.assertEqual(
conf["test-repo-for-tools-with-no-branches"]["branches"], []
)
Expand All @@ -65,8 +67,10 @@ def test_preserve_master(self):
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-tools"]["branches"], ["master"])
self.assertEqual(conf["test-repo-for-tools"]["default_branch"], "master")
self.assertEqual(conf["test-repo-for-tools-1"]["branches"], ["master"])
self.assertEqual(conf["test-repo-for-tools-1"]["default_branch"], "master")
self.assertEqual(conf["test-repo-for-tools-2"]["branches"], [])
self.assertEqual(conf["test-repo-for-tools-2"]["default_branch"], "main")
self.assertEqual(
conf["test-repo-for-tools-with-no-branches"]["branches"], []
)
Expand Down

0 comments on commit e3d5c99

Please sign in to comment.