##// END OF EJS Templates
pr: Use new update response object from pr model. #3950
Martin Bornhold -
r1076:ab17456b default
parent child Browse files
Show More
@@ -45,7 +45,7 b' from rhodecode.lib.auth import ('
45 45 from rhodecode.lib.channelstream import channelstream_request
46 46 from rhodecode.lib.utils import jsonify
47 47 from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode
48 from rhodecode.lib.vcs.backends.base import EmptyCommit
48 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
49 49 from rhodecode.lib.vcs.exceptions import (
50 50 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError)
51 51 from rhodecode.lib.diffs import LimitedDiffContainer
@@ -518,31 +518,31 b' class PullrequestsController(BaseRepoCon'
518 518 return
519 519
520 520 def _update_commits(self, pull_request):
521 try:
522 if PullRequestModel().has_valid_update_type(pull_request):
523 updated_version, changes = PullRequestModel().update_commits(
524 pull_request)
525 if updated_version:
521 resp = PullRequestModel().update_commits(pull_request)
522 msg = PullRequestModel.UPDATE_STATUS_MESSAGES[resp.reason]
523
524 # Abort if pull request update failed.
525 if not resp.success:
526 h.flash(msg, category='error')
527 return
528
529 if resp.reason == UpdateFailureReason.NONE:
526 530 msg = _(
527 531 u'Pull request updated to "{source_commit_id}" with '
528 u'{count_added} added, {count_removed} removed '
529 u'commits.'
530 ).format(
532 u'{count_added} added, {count_removed} removed commits.')
533 msg = msg.format(
531 534 source_commit_id=pull_request.source_ref_parts.commit_id,
532 count_added=len(changes.added),
533 count_removed=len(changes.removed))
535 count_added=len(resp.changes.added),
536 count_removed=len(resp.changes.removed))
534 537 h.flash(msg, category='success')
538
535 539 registry = get_current_registry()
536 rhodecode_plugins = getattr(registry,
537 'rhodecode_plugins', {})
538 channelstream_config = rhodecode_plugins.get(
539 'channelstream', {})
540 rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
541 channelstream_config = rhodecode_plugins.get('channelstream', {})
540 542 if channelstream_config.get('enabled'):
541 message = msg + ' - <a onclick="' \
542 'window.location.reload()">' \
543 '<strong>{}</strong></a>'.format(
544 _('Reload page')
545 )
543 message = msg + (
544 ' - <a onclick="window.location.reload()">'
545 '<strong>{}</strong></a>'.format(_('Reload page')))
546 546 channel = '/repo${}$/pr/{}'.format(
547 547 pull_request.target_repo.repo_name,
548 548 pull_request.pull_request_id
@@ -558,20 +558,14 b' class PullrequestsController(BaseRepoCon'
558 558 'topic': '/notifications'
559 559 }
560 560 }
561 channelstream_request(channelstream_config, [payload],
562 '/message', raise_exc=False)
563 else:
564 h.flash(_("Nothing changed in pull request."),
565 category='warning')
561 channelstream_request(
562 channelstream_config, [payload], '/message',
563 raise_exc=False)
564 elif resp.reason == UpdateFailureReason.NO_CHANGE:
565 # Display a warning if no update is needed.
566 h.flash(msg, category='warning')
566 567 else:
567 msg = _(
568 u"Skipping update of pull request due to reference "
569 u"type: {reference_type}"
570 ).format(reference_type=pull_request.source_ref_parts.type)
571 h.flash(msg, category='warning')
572 except CommitDoesNotExistError:
573 h.flash(
574 _(u'Update failed due to missing commits.'), category='error')
568 h.flash(msg, category='error')
575 569
576 570 @auth.CSRFRequired()
577 571 @LoginRequired()
General Comments 0
You need to be logged in to leave comments. Login now