|
12 | 12 | automerge_patch = "{{ cookiecutter.automerge_patch }}" == "y"
|
13 | 13 | automerge_patch_v0 = "{{ cookiecutter.automerge_patch_v0 }}" == "y"
|
14 | 14 |
|
| 15 | +automerge_patch_regexp_blocklist = "{{ cookiecutter.automerge_patch_regexp_blocklist }}" |
| 16 | +automerge_patch_v0_regexp_allowlist = ( |
| 17 | + "{{ cookiecutter.automerge_patch_v0_regexp_allowlist }}" |
| 18 | +) |
| 19 | + |
15 | 20 | if not create_lib:
|
16 | 21 | shutil.rmtree("lib")
|
17 | 22 |
|
|
69 | 74 | # We always add an empty package rules list
|
70 | 75 | renovatejson["packageRules"] = []
|
71 | 76 |
|
72 |
| -if automerge_patch: |
73 |
| - # automerge patch PRs |
74 |
| - patch_rule = { |
75 |
| - "matchUpdateTypes": ["patch"], |
| 77 | + |
| 78 | +def rule_defaults(updateTypes, extraLabels=[]): |
| 79 | + """Returns a dict containing a base package rule configuration for automerging. |
| 80 | +
|
| 81 | + By default automerging is disabled for dependencies whose current version matches `^v?0\.` |
| 82 | + """ |
| 83 | + return { |
| 84 | + "matchUpdateTypes": updateTypes, |
76 | 85 | # negative match: do not match versions that match regex `^v?0\.`
|
77 | 86 | "matchCurrentVersion": "!/^v?0\\./",
|
78 | 87 | "automerge": True,
|
|
82 | 91 | "platformAutomerge": False,
|
83 | 92 | # NOTE: We need to add all the labels we want here, renovate doesn't inherit globally
|
84 | 93 | # specified labels for package rules
|
85 |
| - "labels": ["dependency", "automerge"], |
| 94 | + "labels": ["dependency", "automerge"] + extraLabels, |
86 | 95 | }
|
| 96 | + |
| 97 | + |
| 98 | +# automerge patch PRs if `automerge_patch` is True |
| 99 | +if automerge_patch: |
| 100 | + patch_rule = rule_defaults(["patch"]) |
87 | 101 | if automerge_patch_v0:
|
88 |
| - # remove match current version if we want v0.x patch automerge |
| 102 | + # If automerging patch updates for v0.x dependencies is enabled, remove field |
| 103 | + # `matchCurrentVersion` |
89 | 104 | del patch_rule["matchCurrentVersion"]
|
90 | 105 |
|
| 106 | + # Set excludePackagePatterns to the provided list of package patterns for which patch PRs |
| 107 | + # shouldn't be automerged. Only set the field if the provided list isn't empty. |
| 108 | + if len(automerge_patch_regexp_blocklist) > 0: |
| 109 | + # NOTE: We expect that the provided pattern list is a string with patterns separated by ; |
| 110 | + patterns = automerge_patch_regexp_blocklist.split(";") |
| 111 | + patch_rule["excludePackagePatterns"] = patterns |
| 112 | + |
91 | 113 | renovatejson["packageRules"].append(patch_rule)
|
92 | 114 |
|
| 115 | +# If global automerging of patch updates for v0.x dependencies is disabled, but automerging is |
| 116 | +# requested for some v0.x package patterns via `automerge_patch_v0_regexp_allowlist`, we generate an |
| 117 | +# additional package rule that enables automerge only for dependencies that are currently v0.x and |
| 118 | +# which match one of the patterns provided in `automerge_patch_v0_regexp_allowlist`. |
| 119 | +# This rule is not required and therefore not generated when `automerge_patch_v0` is enabled. If you |
| 120 | +# want to disable automerging for some v0.x patch level updates but automerge patch level updates |
| 121 | +# for v0.x dependencies by default, you can specify patterns for which patch level updates shouldn't |
| 122 | +# be automerged in cookiecutter argument `automerge_patch_regexp_blocklist`. |
| 123 | +if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0: |
| 124 | + patterns = automerge_patch_v0_regexp_allowlist.split(";") |
| 125 | + |
| 126 | + patch_v0_rule = rule_defaults(["patch"]) |
| 127 | + # only apply for packages whose current version matches `v?0\.` |
| 128 | + patch_v0_rule["matchCurrentVersion"] = "/^v?0\\./" |
| 129 | + patch_v0_rule["matchPackagePatterns"] = patterns |
| 130 | + |
| 131 | + renovatejson["packageRules"].append(patch_v0_rule) |
| 132 | + |
93 | 133 | # NOTE: Later rules in `packageRules` take precedence
|
94 | 134 |
|
95 | 135 | with open("renovate.json", "w", encoding="utf-8") as f:
|
|
0 commit comments