##// END OF EJS Templates
api/pull-requests: trigger events for comments/review status changes.
marcink -
r3416:ab643e3c stable
parent child
Show More
@@ -553,6 +553,7 def comment_pull_request(
553 )
553 )
554
554
555 if allowed_to_change_status and status:
555 if allowed_to_change_status and status:
556 old_calculated_status = pull_request.calculated_review_status()
556 ChangesetStatusModel().set_status(
557 ChangesetStatusModel().set_status(
557 pull_request.target_repo.repo_id,
558 pull_request.target_repo.repo_id,
558 status,
559 status,
@@ -563,6 +564,20 def comment_pull_request(
563 Session().flush()
564 Session().flush()
564
565
565 Session().commit()
566 Session().commit()
567
568 PullRequestModel().trigger_pull_request_hook(
569 pull_request, apiuser, 'comment',
570 data={'comment': comment})
571
572 if allowed_to_change_status and status:
573 # we now calculate the status of pull request, and based on that
574 # calculation we set the commits status
575 calculated_status = pull_request.calculated_review_status()
576 if old_calculated_status != calculated_status:
577 PullRequestModel().trigger_pull_request_hook(
578 pull_request, apiuser, 'review_status_change',
579 data={'status': calculated_status})
580
566 data = {
581 data = {
567 'pull_request_id': pull_request.pull_request_id,
582 'pull_request_id': pull_request.pull_request_id,
568 'comment_id': comment.comment_id if comment else None,
583 'comment_id': comment.comment_id if comment else None,
@@ -837,6 +852,7 def update_pull_request(
837
852
838 reviewers_changes = {"added": [], "removed": []}
853 reviewers_changes = {"added": [], "removed": []}
839 if reviewers:
854 if reviewers:
855 old_calculated_status = pull_request.calculated_review_status()
840 added_reviewers, removed_reviewers = \
856 added_reviewers, removed_reviewers = \
841 PullRequestModel().update_reviewers(pull_request, reviewers, apiuser)
857 PullRequestModel().update_reviewers(pull_request, reviewers, apiuser)
842
858
@@ -846,6 +862,13 def update_pull_request(
846 [get_user_or_error(n).username for n in removed_reviewers])
862 [get_user_or_error(n).username for n in removed_reviewers])
847 Session().commit()
863 Session().commit()
848
864
865 # trigger status changed if change in reviewers changes the status
866 calculated_status = pull_request.calculated_review_status()
867 if old_calculated_status != calculated_status:
868 PullRequestModel().trigger_pull_request_hook(
869 pull_request, apiuser, 'review_status_change',
870 data={'status': calculated_status})
871
849 data = {
872 data = {
850 'msg': 'Updated pull request `{}`'.format(
873 'msg': 'Updated pull request `{}`'.format(
851 pull_request.pull_request_id),
874 pull_request.pull_request_id),
@@ -44,7 +44,10 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