# HG changeset patch # User Martin Bornhold # Date 2016-10-27 11:55:58 # Node ID b76addfd96e21d8b38aeb3040f6c72f26c82de5d # Parent 6047da4a91bb0ed9ea6e47747b589b80bb0e801b pr: Refactor PR update error message handling. diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -519,14 +519,8 @@ class PullrequestsController(BaseRepoCon def _update_commits(self, pull_request): resp = PullRequestModel().update_commits(pull_request) - msg = PullRequestModel.UPDATE_STATUS_MESSAGES[resp.reason] - # Abort if pull request update failed. - if not resp.success: - h.flash(msg, category='error') - return - - if resp.reason == UpdateFailureReason.NONE: + if resp.success: msg = _( u'Pull request updated to "{source_commit_id}" with ' u'{count_added} added, {count_removed} removed commits.') @@ -561,11 +555,14 @@ class PullrequestsController(BaseRepoCon channelstream_request( channelstream_config, [payload], '/message', raise_exc=False) - elif resp.reason == UpdateFailureReason.NO_CHANGE: - # Display a warning if no update is needed. - h.flash(msg, category='warning') else: - h.flash(msg, category='error') + msg = PullRequestModel.UPDATE_STATUS_MESSAGES[resp.reason] + warning_reasons = [ + UpdateFailureReason.NO_CHANGE, + UpdateFailureReason.WRONG_REF_TPYE, + ] + category = 'warning' if resp.reason in warning_reasons else 'error' + h.flash(msg, category=category) @auth.CSRFRequired() @LoginRequired() diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -537,7 +537,7 @@ class PullRequestModel(BaseModel): if source_ref_id == source_commit.raw_id: log.debug("Nothing changed in pull request %s", pull_request) return UpdateResponse( - success=True, + success=False, reason=UpdateFailureReason.NO_CHANGE, old=pull_request, new=None, changes=None)