Skip to content

Commit e67a246

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 patterns provided in the argument. 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 patch level updates for v0.x dependencies by default, you can specify patterns for which patch level updates shouldn't be automerged in cookiecutter argument `automerge_patch_regexp_blocklist`.
1 parent f58f61e commit e67a246

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 global automerging of patch updates for v0.x dependencies is disabled, but automerging is
106+
# requested for some v0.x package patterns via `automerge_patch_v0_regexp_allowlist`, we generate an
107+
# additional package rule that enables automerge only for dependencies that are currently v0.x and
108+
# which match one of the patterns provided in `automerge_patch_v0_regexp_allowlist`.
109+
# This rule is not required and therefore not generated when `automerge_patch_v0` is enabled. If you
110+
# want to disable automerging for some v0.x patch level updates but automerge patch level updates
111+
# for v0.x dependencies by default, you can specify patterns for which patch level updates shouldn't
112+
# be automerged 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)