Skip to content

Commit

Permalink
Allow enabling minor automerge based on patterns
Browse files Browse the repository at this point in the history
This commit introduces a new cookiecutter argument which is expected to
hold zero or more patterns matching dependencies whose minor level
updates should be automerged.

The template expects that the new argument is a string which contains
zero or more regex patterns separated by semicolons. The resulting list
of patterns is used in field `matchPackagePatterns` of a new package
rule that enables automerge for minor updates.

The template doesn't exclude dependencies whose current version is v0.x
from minor automerging if the dependency name matches one of the
provided patterns.
  • Loading branch information
simu committed Jun 7, 2024
1 parent 6bc56bd commit c53d851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

"automerge_patch_regexp_blocklist": "",
"automerge_patch_v0_regexp_allowlist": "",
"automerge_minor_regexp_allowlist": "",

"copyright_holder": "VSHN AG <info@vshn.ch>",
"copyright_year": "1950",
Expand Down
10 changes: 10 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
automerge_patch_v0_regexp_allowlist = (
"{{ cookiecutter.automerge_patch_v0_regexp_allowlist }}"
)
automerge_minor_regexp_allowlist = "{{ cookiecutter.automerge_minor_regexp_allowlist }}"

if not create_lib:
shutil.rmtree("lib")
Expand Down Expand Up @@ -130,6 +131,15 @@ def rule_defaults(updateTypes, extraLabels=[]):

renovatejson["packageRules"].append(patch_v0_rule)

if len(automerge_minor_regexp_allowlist) > 0:
# NOTE: We expect that the provided pattern list is a string with patterns separated by ;
patterns = automerge_minor_regexp_allowlist.split(";")
minor_rule = rule_defaults(["minor"])
# Don't exclude dependencies whose current version is v0.x from minor automerge
del minor_rule["matchCurrentVersion"]
minor_rule["matchPackagePatterns"] = patterns
renovatejson["packageRules"].append(minor_rule)

# NOTE: Later rules in `packageRules` take precedence

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

0 comments on commit c53d851

Please sign in to comment.