Beispiel #1
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()
Beispiel #2
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 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)
Beispiel #4
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())
Beispiel #5
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())
 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(),
     )
 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(),
     )
Beispiel #8
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
Beispiel #9
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)
    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 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
 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()