##// END OF EJS Templates
api/pull-requests: trigger events for comments/review status changes.
marcink -
r3399:820d474e default
parent child Browse files
Show More
@@ -566,6 +566,7 b' def comment_pull_request('
566 )
566 )
567
567
568 if allowed_to_change_status and status:
568 if allowed_to_change_status and status:
569 old_calculated_status = pull_request.calculated_review_status()
569 ChangesetStatusModel().set_status(
570 ChangesetStatusModel().set_status(
570 pull_request.target_repo.repo_id,
571 pull_request.target_repo.repo_id,
571 status,
572 status,
@@ -576,6 +577,20 b' def comment_pull_request('
576 Session().flush()
577 Session().flush()
577
578
578 Session().commit()
579 Session().commit()
580
581 PullRequestModel().trigger_pull_request_hook(
582 pull_request, apiuser, 'comment',
583 data={'comment': comment})
584
585 if allowed_to_change_status and status:
586 # we now calculate the status of pull request, and based on that
587 # calculation we set the commits status
588 calculated_status = pull_request.calculated_review_status()
589 if old_calculated_status != calculated_status:
590 PullRequestModel().trigger_pull_request_hook(
591 pull_request, apiuser, 'review_status_change',
592 data={'status': calculated_status})
593
579 data = {
594 data = {
580 'pull_request_id': pull_request.pull_request_id,
595 'pull_request_id': pull_request.pull_request_id,
581 'comment_id': comment.comment_id if comment else None,
596 'comment_id': comment.comment_id if comment else None,
@@ -857,6 +872,7 b' def update_pull_request('
857
872
858 reviewers_changes = {"added": [], "removed": []}
873 reviewers_changes = {"added": [], "removed": []}
859 if reviewers:
874 if reviewers:
875 old_calculated_status = pull_request.calculated_review_status()
860 added_reviewers, removed_reviewers = \
876 added_reviewers, removed_reviewers = \
861 PullRequestModel().update_reviewers(pull_request, reviewers, apiuser)
877 PullRequestModel().update_reviewers(pull_request, reviewers, apiuser)
862
878
@@ -866,6 +882,13 b' def update_pull_request('
866 [get_user_or_error(n).username for n in removed_reviewers])
882 [get_user_or_error(n).username for n in removed_reviewers])
867 Session().commit()
883 Session().commit()
868
884
885 # trigger status changed if change in reviewers changes the status
886 calculated_status = pull_request.calculated_review_status()
887 if old_calculated_status != calculated_status:
888 PullRequestModel().trigger_pull_request_hook(
889 pull_request, apiuser, 'review_status_change',
890 data={'status': calculated_status})
891
869 data = {
892 data = {
870 'msg': 'Updated pull request `{}`'.format(
893 'msg': 'Updated pull request `{}`'.format(
871 pull_request.pull_request_id),
894 pull_request.pull_request_id),
@@ -44,7 +44,10 b' from rhodecode.events import ('
44 ])
44 ])
45 def test_pullrequest_events_serialized(EventClass, pr_util, config_stub):
45 def test_pullrequest_events_serialized(EventClass, pr_util, config_stub):
46 pr = pr_util.create_pull_request()
46 pr = pr_util.create_pull_request()
47 event = EventClass(pr)
47 if EventClass == PullRequestReviewEvent:
48 event = EventClass(pr, 'approved')
49 else:
50 event = EventClass(pr)
48 data = event.as_dict()
51 data = event.as_dict()
49 assert data['name'] == EventClass.name
52 assert data['name'] == EventClass.name
50 assert data['repo']['repo_name'] == pr.target_repo.repo_name
53 assert data['repo']['repo_name'] == pr.target_repo.repo_name
General Comments 0
You need to be logged in to leave comments. Login now