예제 #1
0
파일: feed.py 프로젝트: jeffjirsa/rhodecode
 def _get_title(self, cs):
     return "%s" % (
         h.shorter(cs.message, 160)
     )
예제 #2
0
    def create(self, text, repo, user, revision=None, pull_request=None,
               f_path=None, line_no=None, status_change=None):
        """
        Creates new comment for changeset or pull request.
        IF status_change is not none this comment is associated with a
        status change of changeset or changesets associated with pull request

        :param text:
        :param repo:
        :param user:
        :param revision:
        :param pull_request:
        :param f_path:
        :param line_no:
        :param status_change:
        """
        if not text:
            return

        repo = self._get_repo(repo)
        user = self._get_user(user)
        comment = ChangesetComment()
        comment.repo = repo
        comment.author = user
        comment.text = text
        comment.f_path = f_path
        comment.line_no = line_no

        if revision:
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256))
            author_email = cs.author_email
            comment.revision = revision
        elif pull_request:
            pull_request = self.__get_pull_request(pull_request)
            comment.pull_request = pull_request
            desc = pull_request.pull_request_id
        else:
            raise Exception('Please specify revision or pull_request_id')

        self.sa.add(comment)
        self.sa.flush()

        # make notification
        line = ''
        body = text

        #changeset
        if revision:
            if line_no:
                line = _('on line %s') % line_no
            subj = safe_unicode(
                h.link_to('Re commit: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          h.url('changeset_home', repo_name=repo.repo_name,
                                revision=revision,
                                anchor='comment-%s' % comment.comment_id,
                                qualified=True,
                          )
                )
            )
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            # 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)]
            email_kwargs = {
                'status_change': status_change,
            }
        #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}, _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
            email_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=email_kwargs
        )

        mention_recipients = set(self._extract_mentions(body))\
                                .difference(recipients)
        if mention_recipients:
            email_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=email_kwargs
            )

        return comment
예제 #3
0
    def create(self,
               text,
               repo_id,
               user_id,
               revision,
               f_path=None,
               line_no=None):
        """
        Creates new comment for changeset

        :param text:
        :param repo_id:
        :param user_id:
        :param revision:
        :param f_path:
        :param line_no:
        """

        if text:
            repo = Repository.get(repo_id)
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256))
            author_email = cs.author_email
            comment = ChangesetComment()
            comment.repo = repo
            comment.user_id = user_id
            comment.revision = revision
            comment.text = text
            comment.f_path = f_path
            comment.line_no = line_no

            self.sa.add(comment)
            self.sa.flush()
            # make notification
            line = ''
            if line_no:
                line = _('on line %s') % line_no
            subj = safe_unicode(
                h.link_to('Re commit: %(commit_desc)s %(line)s' % \
                          {'commit_desc': desc, 'line': line},
                          h.url('changeset_home', repo_name=repo.repo_name,
                                revision=revision,
                                anchor='comment-%s' % comment.comment_id,
                                qualified=True,
                          )
                )
            )

            body = text

            # 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)]

            NotificationModel().create(
                created_by=user_id,
                subject=subj,
                body=body,
                recipients=recipients,
                type_=Notification.TYPE_CHANGESET_COMMENT)

            mention_recipients = set(self._extract_mentions(body))\
                                    .difference(recipients)
            if mention_recipients:
                subj = _('[Mention]') + ' ' + subj
                NotificationModel().create(
                    created_by=user_id,
                    subject=subj,
                    body=body,
                    recipients=mention_recipients,
                    type_=Notification.TYPE_CHANGESET_COMMENT)

            return comment
예제 #4
0
 def _get_title(self, cs):
     return "%s" % (
         h.shorter(cs.message, 160)
     )
예제 #5
0
 def _get_title(self, commit):
     return h.shorter(commit.message, 160)
예제 #6
0
    def create(self, text, repo_id, user_id, revision, f_path=None,
               line_no=None):
        """
        Creates new comment for changeset

        :param text:
        :param repo_id:
        :param user_id:
        :param revision:
        :param f_path:
        :param line_no:
        """

        if text:
            repo = Repository.get(repo_id)
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256))
            author_email = cs.author_email
            comment = ChangesetComment()
            comment.repo = repo
            comment.user_id = user_id
            comment.revision = revision
            comment.text = text
            comment.f_path = f_path
            comment.line_no = line_no

            self.sa.add(comment)
            self.sa.flush()
            # make notification
            line = ''
            if line_no:
                line = _('on line %s') % line_no
            subj = safe_unicode(
                h.link_to('Re commit: %(commit_desc)s %(line)s' % \
                          {'commit_desc': desc, 'line': line},
                          h.url('changeset_home', repo_name=repo.repo_name,
                                revision=revision,
                                anchor='comment-%s' % comment.comment_id,
                                qualified=True,
                          )
                )
            )

            body = text

            # 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)]

            NotificationModel().create(
              created_by=user_id, subject=subj, body=body,
              recipients=recipients, type_=Notification.TYPE_CHANGESET_COMMENT
            )

            mention_recipients = set(self._extract_mentions(body))\
                                    .difference(recipients)
            if mention_recipients:
                subj = _('[Mention]') + ' ' + subj
                NotificationModel().create(
                    created_by=user_id, subject=subj, body=body,
                    recipients=mention_recipients,
                    type_=Notification.TYPE_CHANGESET_COMMENT
                )

            return comment