Changeset - 0a623ec24b62
[Not reviewed]
beta
0 2 1
Marcin Kuzminski - 13 years ago 2012-09-05 00:08:38
marcin@python-works.com
part2 of pull-request notification improvements
3 files changed with 42 insertions and 12 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/comment.py
Show inline comments
 
@@ -122,47 +122,60 @@ class ChangesetCommentsModel(BaseModel):
 
            # get the current participants of this changeset
 
            recipients = ChangesetComment.get_users(revision=revision)
 
            # add changeset author if it's in rhodecode system
 
            recipients += [User.get_by_email(author_email)]
 
        #pull request
 
        elif pull_request:
 
            _url = h.url('pullrequest_show',
 
                repo_name=pull_request.other_repo.repo_name,
 
                pull_request_id=pull_request.pull_request_id,
 
                anchor='comment-%s' % comment.comment_id,
 
                qualified=True,
 
            )
 
            subj = safe_unicode(
 
                h.link_to('Re pull request: %(desc)s %(line)s' % \
 
                          {'desc': desc, 'line': line},
 
                          h.url('pullrequest_show',
 
                                repo_name=pull_request.other_repo.repo_name,
 
                                pull_request_id=pull_request.pull_request_id,
 
                                anchor='comment-%s' % comment.comment_id,
 
                                qualified=True,
 
                          )
 
                )
 
                          {'desc': desc, 'line': line}, _url)
 
            )
 

	
 
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
 
            # get the current participants of this pull request
 
            recipients = ChangesetComment.get_users(pull_request_id=
 
                                                pull_request.pull_request_id)
 
            # add pull request author
 
            recipients += [pull_request.author]
 

	
 
            # add the reviewers to notification
 
            recipients += [x.user for x in pull_request.reviewers]
 

	
 
            #set some variables for email notification
 
            kwargs = {
 
                'pr_id': pull_request.pull_request_id,
 
                'status_change': status_change,
 
                'pr_comment_url': _url,
 
                'pr_comment_user': h.person(user.email),
 
                'pr_target_repo': h.url('summary_home',
 
                                   repo_name=pull_request.other_repo.repo_name,
 
                                   qualified=True)
 
            }
 
        # create notification objects, and emails
 
        NotificationModel().create(
 
          created_by=user, subject=subj, body=body,
 
          recipients=recipients, type_=notification_type,
 
          email_kwargs={'status_change': status_change}
 
            created_by=user, subject=subj, body=body,
 
            recipients=recipients, type_=notification_type,
 
            email_kwargs=kwargs
 
        )
 

	
 
        mention_recipients = set(self._extract_mentions(body))\
 
                                .difference(recipients)
 
        if mention_recipients:
 
            kwargs.update({'pr_mention': True})
 
            subj = _('[Mention]') + ' ' + subj
 
            NotificationModel().create(
 
                created_by=user, subject=subj, body=body,
 
                recipients=mention_recipients,
 
                type_=notification_type,
 
                email_kwargs={'status_change': status_change}
 
                email_kwargs=kwargs
 
            )
 

	
 
        return comment
 

	
 
    def delete(self, comment):
 
        """
rhodecode/model/notification.py
Show inline comments
 
@@ -242,24 +242,26 @@ class NotificationModel(BaseModel):
 
class EmailNotificationModel(BaseModel):
 

	
 
    TYPE_CHANGESET_COMMENT = Notification.TYPE_CHANGESET_COMMENT
 
    TYPE_PASSWORD_RESET = 'passoword_link'
 
    TYPE_REGISTRATION = Notification.TYPE_REGISTRATION
 
    TYPE_PULL_REQUEST = Notification.TYPE_PULL_REQUEST
 
    TYPE_PULL_REQUEST_COMMENT = Notification.TYPE_PULL_REQUEST_COMMENT
 
    TYPE_DEFAULT = 'default'
 

	
 
    def __init__(self):
 
        self._template_root = rhodecode.CONFIG['pylons.paths']['templates'][0]
 
        self._tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
 

	
 
        self.email_types = {
 
         self.TYPE_CHANGESET_COMMENT: 'email_templates/changeset_comment.html',
 
         self.TYPE_PASSWORD_RESET: 'email_templates/password_reset.html',
 
         self.TYPE_REGISTRATION: 'email_templates/registration.html',
 
         self.TYPE_DEFAULT: 'email_templates/default.html',
 
         self.TYPE_PULL_REQUEST: 'email_templates/pull_request.html',
 
         self.TYPE_PULL_REQUEST_COMMENT: 'email_templates/pull_request_comment.html',
 
        }
 

	
 
    def get_email_tmpl(self, type_, **kwargs):
 
        """
 
        return generated template for email based on given type
 

	
rhodecode/templates/email_templates/pull_request_comment.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-
 
<%inherit file="main.html"/>
 
            
 
User <b>${pr_comment_user}</b> commented on pull request #${pr_id} for
 
repository ${pr_target_repo}
 

	
 
<p>
 
${body}
 

	
 
%if status_change:
 
    <span>New status -> ${status_change}</span>
 
%endif
 
</p>
 

	
 
View this comment here: ${pr_comment_url}
0 comments (0 inline, 0 general)