diff --git a/cookiecutter.json b/cookiecutter.json index 0b5845d..b9d4149 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -15,6 +15,7 @@ "automerge_patch_v0": "n", "automerge_patch_regexp_blocklist": "", + "automerge_patch_v0_regexp_allowlist": "", "copyright_holder": "VSHN AG ", "copyright_year": "1950", diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index f17f904..ab24969 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -13,6 +13,9 @@ automerge_patch_v0 = "{{ cookiecutter.automerge_patch_v0 }}" == "y" automerge_patch_regexp_blocklist = "{{ cookiecutter.automerge_patch_regexp_blocklist }}" +automerge_patch_v0_regexp_allowlist = ( + "{{ cookiecutter.automerge_patch_v0_regexp_allowlist }}" +) if not create_lib: shutil.rmtree("lib") @@ -99,6 +102,32 @@ renovatejson["packageRules"].append(patch_rule) +# If automerging of patch updates for v0.x dependencies is disabled by default, but automerging +# is requested for some v0.x package patterns, we generate an additional package rule that +# enables automerge only for dependencies that are currently v0.x and which match one of the +# provided patterns. +# This rule is not required and therefore not generated when `automerge_patch_v0` is enabled +# globally. If you want to disable automerging for some v0.x patch level updates but merge those +# updates by default, you can specify patterns for which no patch level updates should be merged +# in cookiecutter argument `automerge_patch_regexp_blocklist`. +if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0: + patterns = automerge_patch_v0_regexp_allowlist.split(";") + patch_v0_rule = { + "matchUpdateTypes": ["patch"], + # only apply for packages whose current version matches `v?0\.` + "matchCurrentVersion": "/^v?0\\./", + "automerge": True, + # NOTE: We can't use Platform Automerge because the repositories are configured manually, + # so we can't be sure the "require status checks" option is always enabled, and without + # that, platformAutomerge does not wait for tests to pass. + "platformAutomerge": False, + # NOTE: We need to add all the labels we want here, renovate doesn't inherit globally + # specified labels for package rules + "labels": ["dependency", "automerge"], + "matchPackagePatterns": patterns, + } + renovatejson["packageRules"].append(patch_v0_rule) + # NOTE: Later rules in `packageRules` take precedence with open("renovate.json", "w", encoding="utf-8") as f: