Skip to content

Commit 4a11211

Browse files
committed
Allow selectively enabling patch dependency automerge for v0.x dependencies
This commit introduces a new cookiecutter argument `automerge_patch_v0_regexp_allowlist` which can be used to selectively enable patch automerging for v0.x dependencies. The template expects that the content of the new argument is a string which contains zero or more regexp patterns separated by semicolons. If global automerging of patch updates for v0.x dependencies is disabled, but `automerge_patch_v0_regexp_allowlist` isn't empty, the template generates 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. If you want to disable automerging for some v0.x patch level updates but automerge those patch level updates for v0.x dependencies by default, you can specify patterns for which no patch level updates should be merged in cookiecutter argument `automerge_patch_regexp_blocklist`.
1 parent f58f61e commit 4a11211

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cookiecutter.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"automerge_patch_v0": "n",
1616

1717
"automerge_patch_regexp_blocklist": "",
18+
"automerge_patch_v0_regexp_allowlist": "",
1819

1920
"copyright_holder": "VSHN AG <info@vshn.ch>",
2021
"copyright_year": "1950",

hooks/post_gen_project.py

+29
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
automerge_patch_v0 = "{{ cookiecutter.automerge_patch_v0 }}" == "y"
1414

1515
automerge_patch_regexp_blocklist = "{{ cookiecutter.automerge_patch_regexp_blocklist }}"
16+
automerge_patch_v0_regexp_allowlist = (
17+
"{{ cookiecutter.automerge_patch_v0_regexp_allowlist }}"
18+
)
1619

1720
if not create_lib:
1821
shutil.rmtree("lib")
@@ -99,6 +102,32 @@
99102

100103
renovatejson["packageRules"].append(patch_rule)
101104

105+
# If automerging of patch updates for v0.x dependencies is disabled by default, but automerging
106+
# is requested for some v0.x package patterns, we generate an additional package rule that
107+
# enables automerge only for dependencies that are currently v0.x and which match one of the
108+
# provided patterns.
109+
# This rule is not required and therefore not generated when `automerge_patch_v0` is enabled
110+
# globally. If you want to disable automerging for some v0.x patch level updates but merge those
111+
# updates by default, you can specify patterns for which no patch level updates should be merged
112+
# in cookiecutter argument `automerge_patch_regexp_blocklist`.
113+
if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0:
114+
patterns = automerge_patch_v0_regexp_allowlist.split(";")
115+
patch_v0_rule = {
116+
"matchUpdateTypes": ["patch"],
117+
# only apply for packages whose current version matches `v?0\.`
118+
"matchCurrentVersion": "/^v?0\\./",
119+
"automerge": True,
120+
# NOTE: We can't use Platform Automerge because the repositories are configured manually,
121+
# so we can't be sure the "require status checks" option is always enabled, and without
122+
# that, platformAutomerge does not wait for tests to pass.
123+
"platformAutomerge": False,
124+
# NOTE: We need to add all the labels we want here, renovate doesn't inherit globally
125+
# specified labels for package rules
126+
"labels": ["dependency", "automerge"],
127+
"matchPackagePatterns": patterns,
128+
}
129+
renovatejson["packageRules"].append(patch_v0_rule)
130+
102131
# NOTE: Later rules in `packageRules` take precedence
103132

104133
with open("renovate.json", "w", encoding="utf-8") as f:

0 commit comments

Comments
 (0)