Ejemplo n.º 1
0
    def _get_notification_data(self,
                               repo,
                               comment,
                               author,
                               comment_text,
                               line_no=None,
                               revision=None,
                               pull_request=None,
                               status_change=None,
                               closing_pr=False):
        """
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = cs.short_id

            threading = [
                '%s-rev-%s@%s' %
                (repo.repo_name, revision, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' %
                                 (repo.repo_name, revision, line_no,
                                  h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                                          repo_name=repo.repo_name,
                                          revision=revision,
                                          anchor='comment-%s' %
                                          comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = _list_changeset_commenters(revision)
            # add changeset author if it's known locally
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                # FIXME: just use committer name even if not a user
                cs_author = repo.owner
            recipients.append(cs_author)

            email_kwargs = {
                'status_change':
                status_change,
                'cs_comment_user':
                author.full_name_and_username,
                'cs_target_repo':
                h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url':
                comment_url,
                'cs_url':
                h.canonical_url('changeset_home',
                                repo_name=repo.repo_name,
                                revision=revision),
                'raw_id':
                revision,
                'message':
                cs.message,
                'message_short':
                h.shorter(cs.message, 50, firstline=True),
                'cs_author':
                cs_author,
                'repo_name':
                repo.repo_name,
                'short_id':
                h.short_id(revision),
                'branch':
                cs.branch,
                'comment_username':
                author.username,
                'threading':
                threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(
                ':')
            _other_ref_type, other_ref_name, _other_rev = comment.pull_request.other_ref.split(
                ':')
            threading = [
                '%s-pr-%s@%s' %
                (pull_request.other_repo.repo_name,
                 pull_request.pull_request_id, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' %
                                 (pull_request.other_repo.repo_name,
                                  pull_request.pull_request_id, line_no,
                                  h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                                           anchor='comment-%s' %
                                           comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request %(pr_nice_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_nice_id': comment.pull_request.nice_id(),
                           'line': line},
                          comment_url)
            )
            # get the current participants of this pull request
            recipients = _list_pull_request_commenters(pull_request)
            recipients.append(pull_request.owner)
            recipients += pull_request.get_reviewer_users()

            #set some variables for email notification
            email_kwargs = {
                'pr_title':
                pull_request.title,
                'pr_title_short':
                h.shorter(pull_request.title, 50),
                'pr_nice_id':
                pull_request.nice_id(),
                'status_change':
                status_change,
                'closing_pr':
                closing_pr,
                'pr_comment_url':
                comment_url,
                'pr_url':
                pull_request.url(canonical=True),
                'pr_comment_user':
                author.full_name_and_username,
                'pr_target_repo':
                h.canonical_url('summary_home',
                                repo_name=pull_request.other_repo.repo_name),
                'pr_target_branch':
                other_ref_name,
                'pr_source_repo':
                h.canonical_url('summary_home',
                                repo_name=pull_request.org_repo.repo_name),
                'pr_source_branch':
                org_ref_name,
                'pr_owner':
                pull_request.owner,
                'pr_owner_username':
                pull_request.owner.username,
                'repo_name':
                pull_request.other_repo.repo_name,
                'comment_username':
                author.username,
                'threading':
                threading,
            }

        return subj, body, recipients, notification_type, email_kwargs
Ejemplo n.º 2
0
    def _get_notification_data(self, repo, comment, user, comment_text,
                               line_no=None, revision=None, pull_request=None,
                               status_change=None, closing_pr=False):
        """
        Get notification data

        :param comment_text:
        :param line:
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s" % (cs.short_id)

            threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' % (repo.repo_name, revision, line_no,
                                                           h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                repo_name=repo.repo_name,
                revision=revision,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = ChangesetComment.get_users(revision=revision)
            # add changeset author if it's in kallithea system
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                cs_author = repo.user
            recipients += [cs_author]
            email_kwargs = {
                'status_change': status_change,
                'cs_comment_user': h.person(user, 'username_and_name'),
                'cs_target_repo': h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url': comment_url,
                'raw_id': revision,
                'message': cs.message,
                'repo_name': repo.repo_name,
                'short_id': h.short_id(revision),
                'branch': cs.branch,
                'comment_username': user.username,
                'threading': threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
            threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
                                          pull_request.pull_request_id,
                                          h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name,
                                                          pull_request.pull_request_id, line_no,
                                                          h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_id': comment.pull_request.pull_request_id,
                           'line': line},
                          comment_url)
            )
            # 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_title': pull_request.title,
                'pr_id': pull_request.pull_request_id,
                'status_change': status_change,
                'closing_pr': closing_pr,
                'pr_comment_url': comment_url,
                'pr_comment_user': h.person(user, 'username_and_name'),
                'pr_target_repo': h.canonical_url('summary_home',
                                   repo_name=pull_request.other_repo.repo_name),
                'repo_name': pull_request.other_repo.repo_name,
                'ref': org_ref_name,
                'comment_username': user.username,
                'threading': threading,
            }

        return subj, body, recipients, notification_type, email_kwargs
Ejemplo n.º 3
0
    def _get_notification_data(self, repo, comment, author, comment_text,
                               line_no=None, revision=None, pull_request=None,
                               status_change=None, closing_pr=False):
        """
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = cs.short_id

            threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' % (repo.repo_name, revision, line_no,
                                                           h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                repo_name=repo.repo_name,
                revision=revision,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = _list_changeset_commenters(revision)
            # add changeset author if it's known locally
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                # FIXME: just use committer name even if not a user
                cs_author = repo.owner
            recipients.append(cs_author)

            email_kwargs = {
                'status_change': status_change,
                'cs_comment_user': author.full_name_and_username,
                'cs_target_repo': h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url': comment_url,
                'cs_url': h.canonical_url('changeset_home', repo_name=repo.repo_name, revision=revision),
                'raw_id': revision,
                'message': cs.message,
                'message_short': h.shorter(cs.message, 50, firstline=True),
                'cs_author': cs_author,
                'repo_name': repo.repo_name,
                'short_id': h.short_id(revision),
                'branch': cs.branch,
                'comment_username': author.username,
                'threading': threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
            _other_ref_type, other_ref_name, _other_rev = comment.pull_request.other_ref.split(':')
            threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
                                          pull_request.pull_request_id,
                                          h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name,
                                                          pull_request.pull_request_id, line_no,
                                                          h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request %(pr_nice_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_nice_id': comment.pull_request.nice_id(),
                           'line': line},
                          comment_url)
            )
            # get the current participants of this pull request
            recipients = _list_pull_request_commenters(pull_request)
            recipients.append(pull_request.owner)
            recipients += pull_request.get_reviewer_users()

            #set some variables for email notification
            email_kwargs = {
                'pr_title': pull_request.title,
                'pr_title_short': h.shorter(pull_request.title, 50),
                'pr_nice_id': pull_request.nice_id(),
                'status_change': status_change,
                'closing_pr': closing_pr,
                'pr_comment_url': comment_url,
                'pr_url': pull_request.url(canonical=True),
                'pr_comment_user': author.full_name_and_username,
                'pr_target_repo': h.canonical_url('summary_home',
                                   repo_name=pull_request.other_repo.repo_name),
                'pr_target_branch': other_ref_name,
                'pr_source_repo': h.canonical_url('summary_home',
                                   repo_name=pull_request.org_repo.repo_name),
                'pr_source_branch': org_ref_name,
                'pr_owner': pull_request.owner,
                'pr_owner_username': pull_request.owner.username,
                'repo_name': pull_request.other_repo.repo_name,
                'comment_username': author.username,
                'threading': threading,
            }

        return subj, body, recipients, notification_type, email_kwargs
Ejemplo n.º 4
0
    def _get_notification_data(self,
                               repo,
                               comment,
                               user,
                               comment_text,
                               line_no=None,
                               revision=None,
                               pull_request=None,
                               status_change=None,
                               closing_pr=False):
        """
        Get notification data

        :param comment_text:
        :param line:
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s" % (cs.short_id)

            threading = [
                '%s-rev-%s@%s' %
                (repo.repo_name, revision, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' %
                                 (repo.repo_name, revision, line_no,
                                  h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                                          repo_name=repo.repo_name,
                                          revision=revision,
                                          anchor='comment-%s' %
                                          comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = ChangesetComment.get_users(revision=revision)
            # add changeset author if it's in kallithea system
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                cs_author = repo.user
            recipients += [cs_author]
            email_kwargs = {
                'status_change':
                status_change,
                'cs_comment_user':
                h.person(user, 'username_and_name'),
                'cs_target_repo':
                h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url':
                comment_url,
                'raw_id':
                revision,
                'message':
                cs.message,
                'repo_name':
                repo.repo_name,
                'short_id':
                h.short_id(revision),
                'branch':
                cs.branch,
                'comment_username':
                user.username,
                'threading':
                threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(
                ':')
            threading = [
                '%s-pr-%s@%s' %
                (pull_request.other_repo.repo_name,
                 pull_request.pull_request_id, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' %
                                 (pull_request.other_repo.repo_name,
                                  pull_request.pull_request_id, line_no,
                                  h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                                           anchor='comment-%s' %
                                           comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_id': comment.pull_request.pull_request_id,
                           'line': line},
                          comment_url)
            )
            # 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_title':
                pull_request.title,
                'pr_id':
                pull_request.pull_request_id,
                'status_change':
                status_change,
                'closing_pr':
                closing_pr,
                'pr_comment_url':
                comment_url,
                'pr_comment_user':
                h.person(user, 'username_and_name'),
                'pr_target_repo':
                h.canonical_url('summary_home',
                                repo_name=pull_request.other_repo.repo_name),
                'repo_name':
                pull_request.other_repo.repo_name,
                'ref':
                org_ref_name,
                'comment_username':
                user.username,
                'threading':
                threading,
            }

        return subj, body, recipients, notification_type, email_kwargs