Skip to content

Commit

Permalink
Merge pull request #987 from projectsyn/fix/template/update-from-old
Browse files Browse the repository at this point in the history
Ensure `component update` can update components without automerge settings
  • Loading branch information
simu authored Jun 17, 2024
2 parents 79f6645 + ba0be41 commit 44c00b8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
8 changes: 5 additions & 3 deletions commodore/component/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ 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"
self.autorelease = cookiecutter_args["auto_release"] == "y"
self.automerge_patch = cookiecutter_args.get("automerge_patch", "y") == "y"
self.automerge_patch_v0 = (
cookiecutter_args.get("automerge_patch_v0", "n") == "y"
)
self.autorelease = cookiecutter_args.get("auto_release", "y") == "y"

self._initialize_automerge_pattern_lists_from_cookiecutter_args(
cookiecutter_args
Expand Down
38 changes: 38 additions & 0 deletions tests/test_component_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,3 +1896,41 @@ def test_component_templater_read_from_modulesync_config(

assert t.cookiecutter_args["copyright_holder"] == expected_holder
assert t.cookiecutter_args["copyright_year"] == expected_year


def test_component_templater_read_from_old_cruft_json(
tmp_path: P,
cli_runner: RunnerFunc,
config: Config,
):
component_name = "test-component"
call_component_new(tmp_path, cli_runner, component_name)
component_path = tmp_path / "dependencies" / component_name
r = Repo(component_path)

with open(component_path / ".cruft.json", "r", encoding="utf-8") as f:
cruft_json = json.load(f)

# remove all the automerge settings from the cruft json
del cruft_json["context"]["cookiecutter"]["automerge_patch"]
del cruft_json["context"]["cookiecutter"]["automerge_patch_v0"]
del cruft_json["context"]["cookiecutter"]["auto_release"]
del cruft_json["context"]["cookiecutter"]["automerge_patch_regexp_blocklist"]
del cruft_json["context"]["cookiecutter"]["automerge_patch_v0_regexp_allowlist"]
del cruft_json["context"]["cookiecutter"]["automerge_minor_regexp_allowlist"]

with open(component_path / ".cruft.json", "w", encoding="utf-8") as f:
json.dump(cruft_json, f, indent=2)
f.write("\n")
r.index.add([".cruft.json"])

r.index.commit("Update component template metadata")

t = template.ComponentTemplater.from_existing(config, component_path)

assert t.cookiecutter_args["automerge_patch"] == "y"
assert t.cookiecutter_args["automerge_patch_v0"] == "n"
assert t.cookiecutter_args["auto_release"] == "y"
assert t.cookiecutter_args["automerge_patch_regexp_blocklist"] == ""
assert t.cookiecutter_args["automerge_patch_v0_regexp_allowlist"] == ""
assert t.cookiecutter_args["automerge_minor_regexp_allowlist"] == ""

0 comments on commit 44c00b8

Please sign in to comment.