Skip to content

Commit

Permalink
Add options to configure patch automerging via component new and `c…
Browse files Browse the repository at this point in the history
…omponent update`
  • Loading branch information
simu committed Jun 4, 2024
1 parent 6559630 commit 35709ae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
25 changes: 24 additions & 1 deletion commodore/cli/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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()


Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions commodore/component/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
class ComponentTemplater(Templater):
library: bool
post_process: bool
_automerge_patch: bool
automerge_patch_v0: bool
_matrix_tests: bool

@classmethod
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_component_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 35709ae

Please # to comment.