diff --git a/commodore/cli/component.py b/commodore/cli/component.py index a796bf611..eff49a9d1 100644 --- a/commodore/cli/component.py +++ b/commodore/cli/component.py @@ -4,6 +4,7 @@ from collections.abc import Iterable from datetime import timedelta +from functools import reduce from pathlib import Path from typing import Optional @@ -27,6 +28,18 @@ def new_update_options(new_cmd: bool): def decorator(cmd): options.verbosity(cmd) + click.option( + "--automerge-patch-v0 / --no-automerge-patch-v0", + is_flag=True, + default=False if new_cmd else None, + help="Whether to configure the component to automerge patch-level dependency PRs for v0.x dependencies", + )(cmd) + click.option( + "--automerge-patch / --no-automerge-patch", + is_flag=True, + default=True if new_cmd else None, + help="Whether to configure the component to automerge patch-level dependency PRs", + )(cmd) click.option( "--additional-test-case", "-t", @@ -134,6 +147,8 @@ def component_new( template_url: str, template_version: str, additional_test_case: Iterable[str], + automerge_patch: bool, + automerge_patch_v0: bool, ): config.update_verbosity(verbose) t = ComponentTemplater( @@ -146,6 +161,8 @@ def component_new( t.golden_tests = golden_tests t.matrix_tests = matrix_tests t.test_cases = ["defaults"] + list(additional_test_case) + t.automerge_patch = automerge_patch + t.automerge_patch_v0 = automerge_patch_v0 t.create() @@ -167,7 +184,7 @@ def component_new( default=[], show_default=True, multiple=True, - help="Test cases to remove from the package. Can be repeated.", + help="Test cases to remove from the component. Can be repeated.", ) @click.option( "--commit / --no-commit", @@ -190,6 +207,8 @@ def component_update( additional_test_case: Iterable[str], remove_test_case: Iterable[str], commit: bool, + automerge_patch: Optional[bool], + automerge_patch_v0: Optional[bool], ): """This command updates the component at COMPONENT_PATH to the latest version of the template which was originally used to create it, if the template version is given as @@ -216,6 +235,10 @@ def component_update( t.library = lib if pp is not None: t.post_process = pp + if automerge_patch is not None: + t.automerge_patch = automerge_patch + if automerge_patch_v0 is not None: + t.automerge_patch_v0 = automerge_patch_v0 test_cases = t.test_cases test_cases.extend(additional_test_case) diff --git a/commodore/component/template.py b/commodore/component/template.py index 68739ed1b..92f4251a2 100644 --- a/commodore/component/template.py +++ b/commodore/component/template.py @@ -16,6 +16,8 @@ class ComponentTemplater(Templater): library: bool post_process: bool + _automerge_patch: bool + automerge_patch_v0: bool _matrix_tests: bool @classmethod @@ -79,6 +81,8 @@ def _initialize_from_cookiecutter_args(self, cookiecutter_args: dict[str, str]): self.library = cookiecutter_args["add_lib"] == "y" self.post_process = cookiecutter_args["add_pp"] == "y" self.matrix_tests = cookiecutter_args["add_matrix"] == "y" + self.automerge_patch = cookiecutter_args["automerge_patch"] == "y" + self.automerge_patch_v0 = cookiecutter_args["automerge_patch_v0"] == "y" return update_cruft_json @@ -88,8 +92,25 @@ def cookiecutter_args(self) -> dict[str, str]: args["add_lib"] = "y" if self.library else "n" args["add_pp"] = "y" if self.post_process else "n" args["add_matrix"] = "y" if self.matrix_tests else "n" + args["automerge_patch"] = "y" if self.automerge_patch else "n" + args["automerge_patch_v0"] = "y" if self.automerge_patch_v0 else "n" return args + @property + def automerge_patch(self) -> bool: + # TODO(sg): do we want this behavior? + if self.automerge_patch_v0: + click.echo( + " > Forcing automerging of patch dependencies to be enabled " + + "when automerging of v0.x patch dependencies is requested" + ) + return True + return self._automerge_patch + + @automerge_patch.setter + def automerge_patch(self, automerge_patch: bool) -> None: + self._automerge_patch = automerge_patch + @property def matrix_tests(self) -> bool: if len(self.test_cases) > 1: diff --git a/tests/test_component_template.py b/tests/test_component_template.py index 685cb3040..fcfb60c8c 100644 --- a/tests/test_component_template.py +++ b/tests/test_component_template.py @@ -687,6 +687,8 @@ def test_cookiecutter_args_no_cruft_json(tmp_path: P, config: Config): t.post_process = False t.copyright_holder = "" t.github_owner = "projectsyn" + t.automerge_patch = True + t.automerge_patch_v0 = False templater_cookiecutter_args = t.cookiecutter_args