Skip to content

Commit

Permalink
oca-repo-add-branch: add --repo-whitelist option
Browse files Browse the repository at this point in the history
Allows to change only a subset of repos.
  • Loading branch information
simahawk committed Oct 7, 2024
1 parent 3bdba40 commit 46c4641
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions oca_repo_maintainer/cli/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
14 changes: 10 additions & 4 deletions oca_repo_maintainer/tools/conf_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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")
Expand Down

0 comments on commit 46c4641

Please sign in to comment.