##// END OF EJS Templates
pull-requests: add merge check that detects WIP marker in title. This will prevent merges in such case....
ergo -
r4099:c12e69d0 default
parent child Browse files
Show More
@@ -4002,6 +4002,14 b' class _PullRequestBase(BaseModel):'
4002 def reviewer_data_json(self):
4002 def reviewer_data_json(self):
4003 return json.dumps(self.reviewer_data)
4003 return json.dumps(self.reviewer_data)
4004
4004
4005 @property
4006 def work_in_progress(self):
4007 """checks if pull request is work in progress by checking the title"""
4008 title = self.title.upper()
4009 if re.match(r'^(\[WIP\]\s*|WIP:\s*|WIP\s+)', title):
4010 return True
4011 return False
4012
4005 @hybrid_property
4013 @hybrid_property
4006 def description_safe(self):
4014 def description_safe(self):
4007 from rhodecode.lib import helpers as h
4015 from rhodecode.lib import helpers as h
@@ -1614,6 +1614,7 b' class MergeCheck(object):'
1614 PERM_CHECK = 'perm'
1614 PERM_CHECK = 'perm'
1615 REVIEW_CHECK = 'review'
1615 REVIEW_CHECK = 'review'
1616 MERGE_CHECK = 'merge'
1616 MERGE_CHECK = 'merge'
1617 WIP_CHECK = 'wip'
1617
1618
1618 def __init__(self):
1619 def __init__(self):
1619 self.review_status = None
1620 self.review_status = None
@@ -1638,6 +1639,15 b' class MergeCheck(object):'
1638 _ = translator
1639 _ = translator
1639 merge_check = cls()
1640 merge_check = cls()
1640
1641
1642 # title has WIP:
1643 if pull_request.work_in_progress:
1644 log.debug("MergeCheck: cannot merge, title has wip: marker.")
1645
1646 msg = _('WIP marker in title prevents from accidental merge.')
1647 merge_check.push_error('error', msg, cls.WIP_CHECK, pull_request.title)
1648 if fail_early:
1649 return merge_check
1650
1641 # permissions to merge
1651 # permissions to merge
1642 user_allowed_to_merge = PullRequestModel().check_user_merge(
1652 user_allowed_to_merge = PullRequestModel().check_user_merge(
1643 pull_request, auth_user)
1653 pull_request, auth_user)
@@ -402,7 +402,7 b' class TestPullRequestModel(object):'
402 assert pull_request.merge_rev is None
402 assert pull_request.merge_rev is None
403
403
404 def test_get_commit_ids(self, pull_request):
404 def test_get_commit_ids(self, pull_request):
405 # The PR has been not merget yet, so expect an exception
405 # The PR has been not merged yet, so expect an exception
406 with pytest.raises(ValueError):
406 with pytest.raises(ValueError):
407 PullRequestModel()._get_commit_ids(pull_request)
407 PullRequestModel()._get_commit_ids(pull_request)
408
408
@@ -433,6 +433,20 b' class TestPullRequestModel(object):'
433 )
433 )
434 assert type(title) == unicode
434 assert type(title) == unicode
435
435
436 @pytest.mark.parametrize('title, has_wip', [
437 ('hello', False),
438 ('hello wip', False),
439 ('hello wip: xxx', False),
440 ('[wip] hello', True),
441 ('[wip] hello', True),
442 ('wip: hello', True),
443 ('wip hello', True),
444
445 ])
446 def test_wip_title_marker(self, pull_request, title, has_wip):
447 pull_request.title = title
448 assert pull_request.work_in_progress == has_wip
449
436
450
437 @pytest.mark.usefixtures('config_stub')
451 @pytest.mark.usefixtures('config_stub')
438 class TestIntegrationMerge(object):
452 class TestIntegrationMerge(object):
General Comments 0
You need to be logged in to leave comments. Login now