def __init__(self, subject, template_name, recipients, merge_proposal, from_address, delta=None, message_id=None, requested_reviews=None, preview_diff=None, direct_email=False): BranchMailer.__init__(self, subject, template_name, recipients, from_address, delta=delta, message_id=message_id, notification_type='code-review') self.merge_proposal = merge_proposal if requested_reviews is None: requested_reviews = [] self.requested_reviews = requested_reviews self.preview_diff = preview_diff self.template_params = self._generateTemplateParams() self.direct_email = direct_email
def __init__(self, subject, template_name, recipients, merge_proposal, from_address, delta=None, message_id=None, requested_reviews=None, preview_diff=None, direct_email=False): BranchMailer.__init__( self, subject, template_name, recipients, from_address, message_id=message_id, notification_type='code-review') self.merge_proposal = merge_proposal if requested_reviews is None: requested_reviews = [] self.requested_reviews = requested_reviews self.preview_diff = preview_diff self.delta_text = delta self.template_params = self._generateTemplateParams() self.direct_email = direct_email
def _getTemplateParams(self, email, recipient): """Return a dict of values to use in the body and subject.""" # Expand the requested reviews. params = BranchMailer._getTemplateParams(self, email, recipient) params['related_bugtasks'] = self._getRelatedBugTasks(recipient) params.update(self.template_params) return params
def test_subject(self): # No string interpolation should occur on the subject. branch = self.factory.makeAnyBranch() # Subscribe the owner to get revision email. branch.getSubscription(branch.owner).notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", "content", "diff", "Testing %j foo") branch_owner_email = removeSecurityProxy(branch.owner).preferredemail.email self.assertEqual("Testing %j foo", mailer._getSubject(branch_owner_email, branch.owner))
def makeBobMailController(self, diff=None, max_lines=BranchSubscriptionDiffSize.WHOLEDIFF): bob = self.factory.makePerson(email="*****@*****.**") branch = self.factory.makeProductBranch(owner=bob) subscription = branch.getSubscription(bob) subscription.max_diff_lines = max_lines subscription.notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", contents="", diff=diff, subject="") return mailer.generateEmail("*****@*****.**", branch.owner)
def test_subject(self): # No string interpolation should occur on the subject. branch = self.factory.makeAnyBranch() # Subscribe the owner to get revision email. branch.getSubscription(branch.owner).notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', 'content', 'diff', 'Testing %j foo') branch_owner_email = removeSecurityProxy( branch.owner).preferredemail.email self.assertEqual('Testing %j foo', mailer._getSubject(branch_owner_email, branch.owner))
def makeBobMailController(self, diff=None, max_lines=BranchSubscriptionDiffSize.WHOLEDIFF): bob = self.factory.makePerson(email='*****@*****.**') branch = self.factory.makeProductBranch(owner=bob) subscription = branch.getSubscription(bob) subscription.max_diff_lines = max_lines subscription.notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', contents='', diff=diff, subject='') return mailer.generateEmail('*****@*****.**', branch.owner)
def test_branch_modified(self): # Test the email headers for a branch modified email. bob = self.factory.makePerson(email='*****@*****.**') branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forBranchModified(branch, branch.owner, None) mailer.message_id = '<foobar-example-com>' ctrl = mailer.generateEmail('*****@*****.**', branch.owner) self.assertEqual( { 'X-Launchpad-Branch': branch.unique_name, 'X-Launchpad-Message-Rationale': 'Subscriber', 'X-Launchpad-Notification-Type': 'branch-updated', 'X-Launchpad-Project': branch.product.name, 'Message-Id': '<foobar-example-com>' }, ctrl.headers)
def test_branch_modified(self): # Test the email headers for a branch modified email. bob = self.factory.makePerson(email="*****@*****.**") branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forBranchModified(branch, branch.owner, None) mailer.message_id = "<foobar-example-com>" ctrl = mailer.generateEmail("*****@*****.**", branch.owner) self.assertEqual( { "X-Launchpad-Branch": branch.unique_name, "X-Launchpad-Message-Rationale": "Subscriber", "X-Launchpad-Notification-Type": "branch-updated", "X-Launchpad-Project": branch.product.name, "Message-Id": "<foobar-example-com>", }, ctrl.headers, )
def test_branch_revision(self): # Test the email headers for new revision email. bob = self.factory.makePerson(email="*****@*****.**") branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", contents="", diff=None, subject="") mailer.message_id = "<foobar-example-com>" ctrl = mailer.generateEmail("*****@*****.**", branch.owner) self.assertEqual( { "X-Launchpad-Branch": branch.unique_name, "X-Launchpad-Message-Rationale": "Subscriber", "X-Launchpad-Notification-Type": "branch-revision", "X-Launchpad-Branch-Revision-Number": "1", "X-Launchpad-Project": branch.product.name, "Message-Id": "<foobar-example-com>", }, ctrl.headers, )
def test_branch_revision(self): # Test the email headers for new revision email. bob = self.factory.makePerson(email='*****@*****.**') branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', contents='', diff=None, subject='') mailer.message_id = '<foobar-example-com>' ctrl = mailer.generateEmail('*****@*****.**', branch.owner) self.assertEqual( { 'X-Launchpad-Branch': branch.unique_name, 'X-Launchpad-Message-Rationale': 'Subscriber', 'X-Launchpad-Notification-Type': 'branch-revision', 'X-Launchpad-Branch-Revision-Number': '1', 'X-Launchpad-Project': branch.product.name, 'Message-Id': '<foobar-example-com>' }, ctrl.headers)
def getMailerForRevision(self, revision, revno, generate_diff): """Return a BranchMailer for a revision. :param revision: A bzr revision. :param revno: The revno of the revision in this branch. :param generate_diffs: If true, generate a diff for the revision. """ message = self.getRevisionMessage(revision.revision_id, revno) # Use the first (non blank) line of the commit message # as part of the subject, limiting it to 100 characters # if it is longer. message_lines = [ line.strip() for line in revision.message.split('\n') if len(line.strip()) > 0] if len(message_lines) == 0: first_line = 'no commit message given' else: first_line = message_lines[0] if len(first_line) > SUBJECT_COMMIT_MESSAGE_LENGTH: offset = SUBJECT_COMMIT_MESSAGE_LENGTH - 3 first_line = first_line[:offset] + '...' subject = '[Branch %s] Rev %s: %s' % ( self.branch.unique_name, revno, first_line) if generate_diff: if len(revision.parent_ids) > 0: parent_id = revision.parent_ids[0] else: parent_id = NULL_REVISION diff_text = self.getDiffForRevisions( parent_id, revision.revision_id) else: diff_text = None return BranchMailer.forRevision( self.branch, revno, self.from_address, message, diff_text, subject)
def getMailerForRevision(self, revision, revno, generate_diff): """Return a BranchMailer for a revision. :param revision: A bzr revision. :param revno: The revno of the revision in this branch. :param generate_diffs: If true, generate a diff for the revision. """ message = self.getRevisionMessage(revision.revision_id, revno) # Use the first (non blank) line of the commit message # as part of the subject, limiting it to 100 characters # if it is longer. message_lines = [ line.strip() for line in revision.message.split('\n') if len(line.strip()) > 0] if len(message_lines) == 0: first_line = 'no commit message given' else: first_line = message_lines[0] if len(first_line) > SUBJECT_COMMIT_MESSAGE_LENGTH: offset = SUBJECT_COMMIT_MESSAGE_LENGTH - 3 first_line = first_line[:offset] + '...' subject = '[Branch %s] Rev %s: %s' % ( self.branch.unique_name, revno, first_line) if generate_diff: if len(revision.parent_ids) > 0: parent_id = revision.parent_ids[0] else: parent_id = NULL_REVISION diff_text = self.getDiffForRevisions( parent_id, revision.revision_id) else: diff_text = None return BranchMailer.forRevision( self.branch, self.from_address, message, diff_text, subject, revno=revno)
def _getHeaders(self, email): """Return the mail headers to use.""" headers = BranchMailer._getHeaders(self, email) if self.merge_proposal.root_message_id is not None: headers['In-Reply-To'] = self.merge_proposal.root_message_id return headers
def getMailer(self): """Return a BranchMailer for this job.""" return BranchMailer.forRevision( self.branch, self.revno, self.from_address, self.body, None, self.subject)
def getMailer(self): """Return a BranchMailer for this job.""" return BranchMailer.forRevision( self.branch, self.from_address, self.body, None, self.subject, revno=self.revno)
def getMailer(self): """Return a `BranchMailer` for this job.""" return BranchMailer.forBranchModified( self.branch, self.user, self.branch_delta)
def sendAll(self): BranchMailer.sendAll(self) if self.merge_proposal.root_message_id is None: self.merge_proposal.root_message_id = self.message_id
def getMailer(self): """Return a `BranchMailer` for this job.""" return BranchMailer.forBranchModified( self.repository, self.user, self.repository_delta, delta_for_editors=self.repository_delta_for_editors)
def _getHeaders(self, email, recipient): """Return the mail headers to use.""" headers = BranchMailer._getHeaders(self, email, recipient) if self.merge_proposal.root_message_id is not None: headers['In-Reply-To'] = self.merge_proposal.root_message_id return headers