Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add options to configure dependency patch automerge behavior in components via component new and component update #974

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions commodore/cli/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Iterable
from datetime import timedelta
from pathlib import Path
from typing import Optional
from typing import Optional, Tuple

import click

Expand All @@ -18,6 +18,23 @@
import commodore.cli.options as options


def _generate_option_text_snippets(new_cmd: bool) -> Tuple[str, str]:
if new_cmd:
test_case_help = (
"Additional test cases to generate in the new component. "
+ "Can be repeated. Test case `defaults` will always be generated. "
+ "Commodore will deduplicate test cases by name."
)
else:
test_case_help = (
"Additional test cases to add to the component. Can be repeated. "
+ "Commodore will deduplicate test cases by name."
)
add_text = "Add" if new_cmd else "Add or remove"

return add_text, test_case_help


def new_update_options(new_cmd: bool):
"""Shared command options for component new and component update.

Expand All @@ -28,18 +45,22 @@ def new_update_options(new_cmd: bool):
unchanged by default by `component update`.
"""

add_text, test_case_help = _generate_option_text_snippets(new_cmd)

def decorator(cmd):
if new_cmd:
test_case_help = (
"Additional test cases to generate in the new component. "
+ "Can be repeated. Test case `defaults` will always be generated. "
+ "Commodore will deduplicate test cases by name."
)
else:
test_case_help = (
"Additional test cases to add to the component. Can be repeated. "
+ "Commodore will deduplicate test cases by name."
)
click.option(
"--automerge-patch-v0 / --no-automerge-patch-v0",
is_flag=True,
default=False if new_cmd else None,
help="Enable automerging of 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="Enable automerging of patch-level dependency PRs.",
)(cmd)
click.option(
"--additional-test-case",
"-t",
Expand All @@ -49,7 +70,6 @@ def decorator(cmd):
multiple=True,
help=test_case_help,
)(cmd)
add_text = "Add" if new_cmd else "Add or remove"
click.option(
"--matrix-tests/--no-matrix-tests",
default=True if new_cmd else None,
Expand Down Expand Up @@ -147,6 +167,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 @@ -159,6 +181,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 Down Expand Up @@ -204,6 +228,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 @@ -230,6 +256,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
20 changes: 20 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,24 @@ 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:
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
16 changes: 16 additions & 0 deletions docs/modules/ROOT/pages/reference/cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ Defaults to `--no-force`.
Test case `defaults` will always be generated.
Commodore will deduplicate the provided test cases.

*--automerge-patch / --no-automerge-patch*::
Enable automerging of patch-level dependency PRs.

*--automerge-patch-v0 / --no-automerge-patch-v0*::
Enable automerging of patch-level dependency PRs for v0.x dependencies.
+
NOTE: Enabling automerging of patch-level dependency PRs for v0.x dependencies implicitly enables automerging of all patch-level dependency PRs.

*--help*::
Show component new usage and options then exit.

Expand Down Expand Up @@ -254,6 +262,14 @@ Defaults to `--no-force`.
*--commit / --no-commit*::
Whether to commit the rendered template changes.

*--automerge-patch / --no-automerge-patch*::
Enable automerging of patch-level dependency PRs.

*--automerge-patch-v0 / --no-automerge-patch-v0*::
Enable automerging of patch-level dependency PRs for v0.x dependencies.
+
NOTE: Enabling automerging of patch-level dependency PRs for v0.x dependencies implicitly enables automerging of all patch-level dependency PRs.

*--help*::
Show component new usage and options then exit.

Expand Down
Loading
Loading