|
74 | 74 | # We always add an empty package rules list
|
75 | 75 | renovatejson["packageRules"] = []
|
76 | 76 |
|
77 |
| -if automerge_patch: |
78 |
| - # automerge patch PRs |
79 |
| - patch_rule = { |
80 |
| - "matchUpdateTypes": ["patch"], |
81 |
| - # negative match: do not match versions that match regex `^v?0\.` |
82 |
| - "matchCurrentVersion": "!/^v?0\\./", |
| 77 | + |
| 78 | +def rule_defaults(updateTypes, extraLabels=[]): |
| 79 | + return { |
| 80 | + "matchUpdateTypes": updateTypes, |
83 | 81 | "automerge": True,
|
84 | 82 | # NOTE: We can't use Platform Automerge because the repositories are configured manually,
|
85 | 83 | # so we can't be sure the "require status checks" option is always enabled, and without
|
86 | 84 | # that, platformAutomerge does not wait for tests to pass.
|
87 | 85 | "platformAutomerge": False,
|
88 | 86 | # NOTE: We need to add all the labels we want here, renovate doesn't inherit globally
|
89 | 87 | # specified labels for package rules
|
90 |
| - "labels": ["dependency", "automerge"], |
| 88 | + "labels": ["dependency", "automerge"] + extraLabels, |
91 | 89 | }
|
92 |
| - if automerge_patch_v0: |
93 |
| - # remove match current version if we want v0.x patch automerge |
94 |
| - del patch_rule["matchCurrentVersion"] |
| 90 | + |
| 91 | + |
| 92 | +if automerge_patch: |
| 93 | + # automerge patch PRs |
| 94 | + patch_rule = rule_defaults(["patch"]) |
| 95 | + if not automerge_patch_v0: |
| 96 | + # If automerging patch updates for v0.x dependencies isn't enabled, do not match versions |
| 97 | + # that match regex `^v?0\.` |
| 98 | + patch_rule["matchCurrentVersion"] = "!/^v?0\\./" |
95 | 99 |
|
96 | 100 | # Set excludePackagePatterns to the provided list of package patterns for which patch PRs
|
97 | 101 | # shouldn't be automerged. Only set the field if the provided list isn't empty.
|
|
112 | 116 | # be automerged in cookiecutter argument `automerge_patch_regexp_blocklist`.
|
113 | 117 | if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0:
|
114 | 118 | 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 |
| - } |
| 119 | + |
| 120 | + patch_v0_rule = rule_defaults(["patch"]) |
| 121 | + # only apply for packages whose current version matches `v?0\.` |
| 122 | + patch_v0_rule["matchCurrentVersion"] = "/^v?0\\./" |
| 123 | + patch_v0_rule["matchPackagePatterns"] = patterns |
| 124 | + |
129 | 125 | renovatejson["packageRules"].append(patch_v0_rule)
|
130 | 126 |
|
131 | 127 | # NOTE: Later rules in `packageRules` take precedence
|
|
0 commit comments