##// 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 from rhodecode.lib.channelstream import channelstream_request
45 from rhodecode.lib.channelstream import channelstream_request
46 from rhodecode.lib.utils import jsonify
46 from rhodecode.lib.utils import jsonify
47 from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode
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 from rhodecode.lib.vcs.exceptions import (
49 from rhodecode.lib.vcs.exceptions import (
50 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError)
50 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError)
51 from rhodecode.lib.diffs import LimitedDiffContainer
51 from rhodecode.lib.diffs import LimitedDiffContainer
@@ -518,60 +518,54 b' class PullrequestsController(BaseRepoCon'
518 return
518 return
519
519
520 def _update_commits(self, pull_request):
520 def _update_commits(self, pull_request):
521 try:
521 resp = PullRequestModel().update_commits(pull_request)
522 if PullRequestModel().has_valid_update_type(pull_request):
522 msg = PullRequestModel.UPDATE_STATUS_MESSAGES[resp.reason]
523 updated_version, changes = PullRequestModel().update_commits(
523
524 pull_request)
524 # Abort if pull request update failed.
525 if updated_version:
525 if not resp.success:
526 msg = _(
526 h.flash(msg, category='error')
527 u'Pull request updated to "{source_commit_id}" with '
527 return
528 u'{count_added} added, {count_removed} removed '
528
529 u'commits.'
529 if resp.reason == UpdateFailureReason.NONE:
530 ).format(
530 msg = _(
531 source_commit_id=pull_request.source_ref_parts.commit_id,
531 u'Pull request updated to "{source_commit_id}" with '
532 count_added=len(changes.added),
532 u'{count_added} added, {count_removed} removed commits.')
533 count_removed=len(changes.removed))
533 msg = msg.format(
534 h.flash(msg, category='success')
534 source_commit_id=pull_request.source_ref_parts.commit_id,
535 registry = get_current_registry()
535 count_added=len(resp.changes.added),
536 rhodecode_plugins = getattr(registry,
536 count_removed=len(resp.changes.removed))
537 'rhodecode_plugins', {})
537 h.flash(msg, category='success')
538 channelstream_config = rhodecode_plugins.get(
538
539 'channelstream', {})
539 registry = get_current_registry()
540 if channelstream_config.get('enabled'):
540 rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
541 message = msg + ' - <a onclick="' \
541 channelstream_config = rhodecode_plugins.get('channelstream', {})
542 'window.location.reload()">' \
542 if channelstream_config.get('enabled'):
543 '<strong>{}</strong></a>'.format(
543 message = msg + (
544 _('Reload page')
544 ' - <a onclick="window.location.reload()">'
545 )
545 '<strong>{}</strong></a>'.format(_('Reload page')))
546 channel = '/repo${}$/pr/{}'.format(
546 channel = '/repo${}$/pr/{}'.format(
547 pull_request.target_repo.repo_name,
547 pull_request.target_repo.repo_name,
548 pull_request.pull_request_id
548 pull_request.pull_request_id
549 )
549 )
550 payload = {
550 payload = {
551 'type': 'message',
551 'type': 'message',
552 'user': 'system',
552 'user': 'system',
553 'exclude_users': [request.user.username],
553 'exclude_users': [request.user.username],
554 'channel': channel,
554 'channel': channel,
555 'message': {
555 'message': {
556 'message': message,
556 'message': message,
557 'level': 'success',
557 'level': 'success',
558 'topic': '/notifications'
558 'topic': '/notifications'
559 }
559 }
560 }
560 }
561 channelstream_request(channelstream_config, [payload],
561 channelstream_request(
562 '/message', raise_exc=False)
562 channelstream_config, [payload], '/message',
563 else:
563 raise_exc=False)
564 h.flash(_("Nothing changed in pull request."),
564 elif resp.reason == UpdateFailureReason.NO_CHANGE:
565 category='warning')
565 # Display a warning if no update is needed.
566 else:
566 h.flash(msg, category='warning')
567 msg = _(
567 else:
568 u"Skipping update of pull request due to reference "
568 h.flash(msg, category='error')
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')
575
569
576 @auth.CSRFRequired()
570 @auth.CSRFRequired()
577 @LoginRequired()
571 @LoginRequired()
General Comments 0
You need to be logged in to leave comments. Login now