# HG changeset patch # User Marcin Kuzminski # Date 2019-01-18 12:34:54 # Node ID 820d474ee70879a0e0d1d38ad52410c2092cbc06 # Parent 030252b4857627171230bf23d05f3f5df6b992a7 api/pull-requests: trigger events for comments/review status changes. diff --git a/rhodecode/api/views/pull_request_api.py b/rhodecode/api/views/pull_request_api.py --- a/rhodecode/api/views/pull_request_api.py +++ b/rhodecode/api/views/pull_request_api.py @@ -566,6 +566,7 @@ def comment_pull_request( ) if allowed_to_change_status and status: + old_calculated_status = pull_request.calculated_review_status() ChangesetStatusModel().set_status( pull_request.target_repo.repo_id, status, @@ -576,6 +577,20 @@ def comment_pull_request( Session().flush() Session().commit() + + PullRequestModel().trigger_pull_request_hook( + pull_request, apiuser, 'comment', + data={'comment': comment}) + + if allowed_to_change_status and status: + # we now calculate the status of pull request, and based on that + # calculation we set the commits status + calculated_status = pull_request.calculated_review_status() + if old_calculated_status != calculated_status: + PullRequestModel().trigger_pull_request_hook( + pull_request, apiuser, 'review_status_change', + data={'status': calculated_status}) + data = { 'pull_request_id': pull_request.pull_request_id, 'comment_id': comment.comment_id if comment else None, @@ -857,6 +872,7 @@ def update_pull_request( reviewers_changes = {"added": [], "removed": []} if reviewers: + old_calculated_status = pull_request.calculated_review_status() added_reviewers, removed_reviewers = \ PullRequestModel().update_reviewers(pull_request, reviewers, apiuser) @@ -866,6 +882,13 @@ def update_pull_request( [get_user_or_error(n).username for n in removed_reviewers]) Session().commit() + # trigger status changed if change in reviewers changes the status + calculated_status = pull_request.calculated_review_status() + if old_calculated_status != calculated_status: + PullRequestModel().trigger_pull_request_hook( + pull_request, apiuser, 'review_status_change', + data={'status': calculated_status}) + data = { 'msg': 'Updated pull request `{}`'.format( pull_request.pull_request_id), diff --git a/rhodecode/tests/events/test_pullrequest.py b/rhodecode/tests/events/test_pullrequest.py --- a/rhodecode/tests/events/test_pullrequest.py +++ b/rhodecode/tests/events/test_pullrequest.py @@ -44,7 +44,10 @@ from rhodecode.events import ( ]) def test_pullrequest_events_serialized(EventClass, pr_util, config_stub): pr = pr_util.create_pull_request() - event = EventClass(pr) + if EventClass == PullRequestReviewEvent: + event = EventClass(pr, 'approved') + else: + event = EventClass(pr) data = event.as_dict() assert data['name'] == EventClass.name assert data['repo']['repo_name'] == pr.target_repo.repo_name