示例#1
0
    def getNotificationRecipients(self, min_level):
        """See IBranchMergeProposal.getNotificationRecipients"""
        recipients = {}
        branch_identity_cache = {
            self.source_branch: self.source_branch.bzr_identity,
            self.target_branch: self.target_branch.bzr_identity,
        }
        branches = [self.source_branch, self.target_branch]
        if self.prerequisite_branch is not None:
            branches.append(self.prerequisite_branch)
        for branch in branches:
            branch_recipients = branch.getNotificationRecipients()
            for recipient in branch_recipients:
                # If the recipient cannot see either of the branches, skip
                # them.
                if (not self.source_branch.visibleByUser(recipient)
                        or not self.target_branch.visibleByUser(recipient)):
                    continue
                subscription, rationale = branch_recipients.getReason(
                    recipient)
                if (subscription.review_level < min_level):
                    continue
                recipients[recipient] = RecipientReason.forBranchSubscriber(
                    subscription,
                    recipient,
                    rationale,
                    self,
                    branch_identity_cache=branch_identity_cache)
        # Add in all the individuals that have been asked for a review,
        # or who have reviewed.  These people get added to the recipients
        # with the rationale of "Reviewer".
        # Don't add a team reviewer to the recipients as they are only going
        # to get emails normally if they are subscribed to one of the
        # branches, and if they are subscribed, they'll be getting this email
        # aleady.
        for review in self.votes:
            reviewer = review.reviewer
            pending = review.comment is None
            recipients[reviewer] = RecipientReason.forReviewer(
                self,
                pending,
                reviewer,
                branch_identity_cache=branch_identity_cache)
        # If the registrant of the proposal is getting emails, update the
        # rationale to say that they registered it.  Don't however send them
        # emails if they aren't asking for any.
        if self.registrant in recipients:
            recipients[self.registrant] = RecipientReason.forRegistrant(
                self, branch_identity_cache=branch_identity_cache)
        # If the owner of the source branch is getting emails, override the
        # rationale to say they are the owner of the souce branch.
        source_owner = self.source_branch.owner
        if source_owner in recipients:
            reason = RecipientReason.forSourceOwner(
                self, branch_identity_cache=branch_identity_cache)
            if reason is not None:
                recipients[source_owner] = reason

        return recipients
    def getNotificationRecipients(self, min_level):
        """See IBranchMergeProposal.getNotificationRecipients"""
        recipients = {}
        branch_identity_cache = {
            self.source_branch: self.source_branch.bzr_identity,
            self.target_branch: self.target_branch.bzr_identity,
            }
        branches = [self.source_branch, self.target_branch]
        if self.prerequisite_branch is not None:
            branches.append(self.prerequisite_branch)
        for branch in branches:
            branch_recipients = branch.getNotificationRecipients()
            for recipient in branch_recipients:
                # If the recipient cannot see either of the branches, skip
                # them.
                if (not self.source_branch.visibleByUser(recipient) or
                    not self.target_branch.visibleByUser(recipient)):
                    continue
                subscription, rationale = branch_recipients.getReason(
                    recipient)
                if (subscription.review_level < min_level):
                    continue
                recipients[recipient] = RecipientReason.forBranchSubscriber(
                    subscription, recipient, rationale, self,
                    branch_identity_cache=branch_identity_cache)
        # Add in all the individuals that have been asked for a review,
        # or who have reviewed.  These people get added to the recipients
        # with the rationale of "Reviewer".
        # Don't add a team reviewer to the recipients as they are only going
        # to get emails normally if they are subscribed to one of the
        # branches, and if they are subscribed, they'll be getting this email
        # aleady.
        for review in self.votes:
            reviewer = review.reviewer
            pending = review.comment is None
            recipients[reviewer] = RecipientReason.forReviewer(
                self, pending, reviewer,
                branch_identity_cache=branch_identity_cache)
        # If the registrant of the proposal is getting emails, update the
        # rationale to say that they registered it.  Don't however send them
        # emails if they aren't asking for any.
        if self.registrant in recipients:
            recipients[self.registrant] = RecipientReason.forRegistrant(
                self, branch_identity_cache=branch_identity_cache)
        # If the owner of the source branch is getting emails, override the
        # rationale to say they are the owner of the souce branch.
        source_owner = self.source_branch.owner
        if source_owner in recipients:
            reason = RecipientReason.forSourceOwner(
                self, branch_identity_cache=branch_identity_cache)
            if reason is not None:
                recipients[source_owner] = reason

        return recipients
示例#3
0
 def run(self):
     """See `IRunnableJob`."""
     reason = RecipientReason.forReviewer(self.branch_merge_proposal, True,
                                          self.reviewer)
     mailer = BMPMailer.forReviewRequest(reason, self.branch_merge_proposal,
                                         self.requester)
     mailer.sendAll()
示例#4
0
 def test_getReasonPerson(self):
     """Ensure the correct reason is generated for individuals."""
     merge_proposal, subscription = self.makeProposalWithSubscription()
     reason = RecipientReason.forBranchSubscriber(subscription, subscription.person, "", merge_proposal)
     self.assertEqual(
         "You are subscribed to branch %s." % merge_proposal.source_branch.bzr_identity, reason.getReason()
     )
示例#5
0
 def test_forReviewer(self):
     """Test values when created from a branch subscription."""
     merge_proposal, vote_reference, subscriber = self.makeReviewerAndSubscriber()
     pending_review = vote_reference.comment is None
     reason = RecipientReason.forReviewer(merge_proposal, pending_review, subscriber)
     self.assertEqual(subscriber, reason.subscriber)
     self.assertEqual(subscriber, reason.recipient)
     self.assertEqual(vote_reference.branch_merge_proposal.source_branch, reason.branch)
示例#6
0
 def test_forBranchSubscriber(self):
     """Test values when created from a branch subscription."""
     merge_proposal, subscription = self.makeProposalWithSubscription()
     subscriber = subscription.person
     reason = RecipientReason.forBranchSubscriber(subscription, subscriber, "", merge_proposal)
     self.assertEqual(subscriber, reason.subscriber)
     self.assertEqual(subscriber, reason.recipient)
     self.assertEqual(merge_proposal.source_branch, reason.branch)
示例#7
0
 def test_forBranchSubscriber(self):
     """Test values when created from a branch subscription."""
     merge_proposal, subscription = self.makeProposalWithSubscription()
     subscriber = subscription.person
     reason = RecipientReason.forBranchSubscriber(subscription, subscriber,
                                                  '', merge_proposal)
     self.assertEqual(subscriber, reason.subscriber)
     self.assertEqual(subscriber, reason.recipient)
     self.assertEqual(merge_proposal.source_branch, reason.branch)
示例#8
0
 def test_getReasonTeam(self):
     """Ensure the correct reason is generated for teams."""
     team_member = self.factory.makePerson(displayname="Foo Bar", email="*****@*****.**")
     team = self.factory.makeTeam(team_member, displayname="Qux")
     bmp, subscription = self.makeProposalWithSubscription(team)
     reason = RecipientReason.forBranchSubscriber(subscription, team_member, "", bmp)
     self.assertEqual(
         "Your team Qux is subscribed to branch %s." % bmp.source_branch.bzr_identity, reason.getReason()
     )
示例#9
0
 def test_forReview_individual_in_progress(self):
     bmp = self.factory.makeBranchMergeProposal()
     reviewer = self.factory.makePerson(name='eric')
     reason = RecipientReason.forReviewer(bmp, False, reviewer)
     self.assertEqual('Reviewer', reason.mail_header)
     self.assertEqual(
         'You are reviewing the proposed merge of %s into %s.' %
         (bmp.source_branch.bzr_identity, bmp.target_branch.bzr_identity),
         reason.getReason())
示例#10
0
 def test_getReasonPerson(self):
     """Ensure the correct reason is generated for individuals."""
     merge_proposal, subscription = self.makeProposalWithSubscription()
     reason = RecipientReason.forBranchSubscriber(subscription,
                                                  subscription.person, '',
                                                  merge_proposal)
     self.assertEqual(
         'You are subscribed to branch %s.' %
         merge_proposal.source_branch.bzr_identity, reason.getReason())
示例#11
0
 def test_forReview_team_pending(self):
     bmp = self.factory.makeBranchMergeProposal()
     reviewer = self.factory.makeTeam(name='vikings')
     reason = RecipientReason.forReviewer(bmp, True, reviewer)
     self.assertEqual('Reviewer @vikings', reason.mail_header)
     self.assertEqual(
         'Your team Vikings is requested to review the proposed merge'
         ' of %s into %s.' %
         (bmp.source_branch.bzr_identity, bmp.target_branch.bzr_identity),
         reason.getReason())
示例#12
0
 def test_forReview_team_pending(self):
     bmp = self.factory.makeBranchMergeProposal()
     reviewer = self.factory.makeTeam(name="vikings")
     reason = RecipientReason.forReviewer(bmp, True, reviewer)
     self.assertEqual("Reviewer @vikings", reason.mail_header)
     self.assertEqual(
         "Your team Vikings is requested to review the proposed merge"
         " of %s into %s." % (bmp.source_branch.bzr_identity, bmp.target_branch.bzr_identity),
         reason.getReason(),
     )
示例#13
0
 def test_forReview_individual_in_progress(self):
     bmp = self.factory.makeBranchMergeProposal()
     reviewer = self.factory.makePerson(name="eric")
     reason = RecipientReason.forReviewer(bmp, False, reviewer)
     self.assertEqual("Reviewer", reason.mail_header)
     self.assertEqual(
         "You are reviewing the proposed merge of %s into %s."
         % (bmp.source_branch.bzr_identity, bmp.target_branch.bzr_identity),
         reason.getReason(),
     )
示例#14
0
 def test_forReviewer(self):
     """Test values when created from a branch subscription."""
     merge_proposal, vote_reference, subscriber = (
         self.makeReviewerAndSubscriber())
     pending_review = vote_reference.comment is None
     reason = RecipientReason.forReviewer(merge_proposal, pending_review,
                                          subscriber)
     self.assertEqual(subscriber, reason.subscriber)
     self.assertEqual(subscriber, reason.recipient)
     self.assertEqual(vote_reference.branch_merge_proposal.source_branch,
                      reason.branch)
示例#15
0
 def test_getReasonTeam(self):
     """Ensure the correct reason is generated for teams."""
     team_member = self.factory.makePerson(displayname='Foo Bar',
                                           email='*****@*****.**')
     team = self.factory.makeTeam(team_member, displayname='Qux')
     bmp, subscription = self.makeProposalWithSubscription(team)
     reason = RecipientReason.forBranchSubscriber(subscription, team_member,
                                                  '', bmp)
     self.assertEqual(
         'Your team Qux is subscribed to branch %s.' %
         bmp.source_branch.bzr_identity, reason.getReason())
 def makeReviewRequest(self):
     diff_text = ''.join(unified_diff('', "Make a diff."))
     candidate = self.factory.makePerson(
         displayname='Candidate', email='*****@*****.**')
     merge_proposal, subscriber_ = self.makeProposalWithSubscriber(
         diff_text=diff_text, initial_comment="Initial comment",
         reviewer=candidate)
     requester = self.factory.makePerson(
         displayname='Requester', email='*****@*****.**')
     reason = RecipientReason.forReviewer(merge_proposal, True, candidate)
     return reason, requester
示例#17
0
 def makeReviewRequest(self):
     diff_text = ''.join(unified_diff('', "Make a diff."))
     candidate = self.factory.makePerson(
         displayname='Candidate', email='*****@*****.**')
     merge_proposal, subscriber_ = self.makeProposalWithSubscriber(
         diff_text=diff_text, initial_comment="Initial comment",
         reviewer=candidate)
     requester = self.factory.makePerson(
         displayname='Requester', email='*****@*****.**')
     reason = RecipientReason.forReviewer(merge_proposal, True, candidate)
     return reason, requester
示例#18
0
    def test_usesBranchIdentityCache(self):
        """Ensure that the cache is used for branches if provided."""
        branch = self.factory.makeAnyBranch()
        subscription = branch.getSubscription(branch.owner)
        branch_cache = {branch: "lp://fake"}

        def blowup(self):
            raise AssertionError("boom")

        patched = Branch.bzr_identity
        Branch.bzr_identity = property(blowup)

        def cleanup():
            Branch.bzr_identity = patched

        self.addCleanup(cleanup)
        self.assertRaises(AssertionError, getattr, branch, "bzr_identity")
        reason = RecipientReason.forBranchSubscriber(
            subscription, subscription.person, "", branch_identity_cache=branch_cache
        )
        self.assertEqual("You are subscribed to branch lp://fake.", reason.getReason())
示例#19
0
    def test_usesBranchIdentityCache(self):
        """Ensure that the cache is used for branches if provided."""
        branch = self.factory.makeAnyBranch()
        subscription = branch.getSubscription(branch.owner)
        branch_cache = {branch: 'lp://fake'}

        def blowup(self):
            raise AssertionError('boom')

        patched = Branch.bzr_identity
        Branch.bzr_identity = property(blowup)

        def cleanup():
            Branch.bzr_identity = patched

        self.addCleanup(cleanup)
        self.assertRaises(AssertionError, getattr, branch, 'bzr_identity')
        reason = RecipientReason.forBranchSubscriber(
            subscription,
            subscription.person,
            '',
            branch_identity_cache=branch_cache)
        self.assertEqual('You are subscribed to branch lp://fake.',
                         reason.getReason())
 def run(self):
     """See `IRunnableJob`."""
     reason = RecipientReason.forReviewer(self.branch_merge_proposal, True, self.reviewer)
     mailer = BMPMailer.forReviewRequest(reason, self.branch_merge_proposal, self.requester)
     mailer.sendAll()