|
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"], |
| 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, |
81 | 85 | # negative match: do not match versions that match regex `^v?0\.`
|
82 | 86 | "matchCurrentVersion": "!/^v?0\\./",
|
83 | 87 | "automerge": True,
|
|
87 | 91 | "platformAutomerge": False,
|
88 | 92 | # NOTE: We need to add all the labels we want here, renovate doesn't inherit globally
|
89 | 93 | # specified labels for package rules
|
90 |
| - "labels": ["dependency", "automerge"], |
| 94 | + "labels": ["dependency", "automerge"] + extraLabels, |
91 | 95 | }
|
| 96 | + |
| 97 | + |
| 98 | +# automerge patch PRs if `automerge_patch` is True |
| 99 | +if automerge_patch: |
| 100 | + patch_rule = rule_defaults(["patch"]) |
92 | 101 | if automerge_patch_v0:
|
93 |
| - # 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` |
94 | 104 | del patch_rule["matchCurrentVersion"]
|
95 | 105 |
|
96 | 106 | # Set excludePackagePatterns to the provided list of package patterns for which patch PRs
|
|
112 | 122 | # be automerged in cookiecutter argument `automerge_patch_regexp_blocklist`.
|
113 | 123 | if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0:
|
114 | 124 | 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 |
| - } |
| 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 | + |
129 | 131 | renovatejson["packageRules"].append(patch_v0_rule)
|
130 | 132 |
|
131 | 133 | # NOTE: Later rules in `packageRules` take precedence
|
|
0 commit comments