##// END OF EJS Templates
review-rules: allow regex syntax for more flexiblity on writing rule patterns
marcink -
r2877:5151caf6 default
parent child Browse files
Show More
@@ -4221,7 +4221,7 b' class RepoReviewRule(Base, BaseModel):'
4221 rule_users = relationship('RepoReviewRuleUser')
4221 rule_users = relationship('RepoReviewRuleUser')
4222 rule_user_groups = relationship('RepoReviewRuleUserGroup')
4222 rule_user_groups = relationship('RepoReviewRuleUserGroup')
4223
4223
4224 def _validate_glob(self, value):
4224 def _validate_pattern(self, value):
4225 re.compile('^' + glob2re(value) + '$')
4225 re.compile('^' + glob2re(value) + '$')
4226
4226
4227 @hybrid_property
4227 @hybrid_property
@@ -4230,7 +4230,7 b' class RepoReviewRule(Base, BaseModel):'
4230
4230
4231 @source_branch_pattern.setter
4231 @source_branch_pattern.setter
4232 def source_branch_pattern(self, value):
4232 def source_branch_pattern(self, value):
4233 self._validate_glob(value)
4233 self._validate_pattern(value)
4234 self._branch_pattern = value or '*'
4234 self._branch_pattern = value or '*'
4235
4235
4236 @hybrid_property
4236 @hybrid_property
@@ -4239,7 +4239,7 b' class RepoReviewRule(Base, BaseModel):'
4239
4239
4240 @target_branch_pattern.setter
4240 @target_branch_pattern.setter
4241 def target_branch_pattern(self, value):
4241 def target_branch_pattern(self, value):
4242 self._validate_glob(value)
4242 self._validate_pattern(value)
4243 self._target_branch_pattern = value or '*'
4243 self._target_branch_pattern = value or '*'
4244
4244
4245 @hybrid_property
4245 @hybrid_property
@@ -4248,7 +4248,7 b' class RepoReviewRule(Base, BaseModel):'
4248
4248
4249 @file_pattern.setter
4249 @file_pattern.setter
4250 def file_pattern(self, value):
4250 def file_pattern(self, value):
4251 self._validate_glob(value)
4251 self._validate_pattern(value)
4252 self._file_pattern = value or '*'
4252 self._file_pattern = value or '*'
4253
4253
4254 def matches(self, source_branch, target_branch, files_changed):
4254 def matches(self, source_branch, target_branch, files_changed):
@@ -4269,14 +4269,20 b' class RepoReviewRule(Base, BaseModel):'
4269 if self.source_branch_pattern == '*':
4269 if self.source_branch_pattern == '*':
4270 source_branch_match = True
4270 source_branch_match = True
4271 else:
4271 else:
4272 source_branch_regex = re.compile(
4272 if self.source_branch_pattern.startswith('re:'):
4273 '^' + glob2re(self.source_branch_pattern) + '$')
4273 source_pattern = self.source_branch_pattern[3:]
4274 else:
4275 source_pattern = '^' + glob2re(self.source_branch_pattern) + '$'
4276 source_branch_regex = re.compile(source_pattern)
4274 source_branch_match = bool(source_branch_regex.search(source_branch))
4277 source_branch_match = bool(source_branch_regex.search(source_branch))
4275 if self.target_branch_pattern == '*':
4278 if self.target_branch_pattern == '*':
4276 target_branch_match = True
4279 target_branch_match = True
4277 else:
4280 else:
4278 target_branch_regex = re.compile(
4281 if self.target_branch_pattern.startswith('re:'):
4279 '^' + glob2re(self.target_branch_pattern) + '$')
4282 target_pattern = self.target_branch_pattern[3:]
4283 else:
4284 target_pattern = '^' + glob2re(self.target_branch_pattern) + '$'
4285 target_branch_regex = re.compile(target_pattern)
4280 target_branch_match = bool(target_branch_regex.search(target_branch))
4286 target_branch_match = bool(target_branch_regex.search(target_branch))
4281
4287
4282 branch_matches = source_branch_match and target_branch_match
4288 branch_matches = source_branch_match and target_branch_match
@@ -4284,7 +4290,11 b' class RepoReviewRule(Base, BaseModel):'
4284 files_matches = True
4290 files_matches = True
4285 if self.file_pattern != '*':
4291 if self.file_pattern != '*':
4286 files_matches = False
4292 files_matches = False
4287 file_regex = re.compile(glob2re(self.file_pattern))
4293 if self.file_pattern.startswith('re:'):
4294 file_pattern = self.file_pattern[3:]
4295 else:
4296 file_pattern = glob2re(self.file_pattern)
4297 file_regex = re.compile(file_pattern)
4288 for filename in files_changed:
4298 for filename in files_changed:
4289 if file_regex.search(filename):
4299 if file_regex.search(filename):
4290 files_matches = True
4300 files_matches = True
General Comments 0
You need to be logged in to leave comments. Login now