def run(self): """See `IRunnableJob`.""" self.checkReady() if self.branch_merge_proposal.source_branch is not None: server_context = server(get_ro_server(), no_replace=True) else: # A no-op context manager. (This could be simplified with # contextlib.ExitStack from Python 3.3.) server_context = contextmanager(lambda: (None for _ in [None]))() # Update related bug links based on commits in the source branch. self.branch_merge_proposal.updateRelatedBugsFromSource() with server_context: with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)
def test_fromBranchMergeProposal_does_not_warn_on_conflicts(self): """PreviewDiff generation emits no conflict warnings.""" reload(trace) bmp, source_rev_id, target_rev_id = self.createExampleMerge() handler = RecordLister() logger = logging.getLogger('bzr') logger.addHandler(handler) try: PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual(handler.records, []) # check that our handler would normally intercept warnings. trace.warning('foo!') self.assertNotEqual(handler.records, []) finally: logger.removeHandler(handler)
def updatePreviewDiff(self, diff_content, source_revision_id, target_revision_id, prerequisite_revision_id=None, conflicts=None): """See `IBranchMergeProposal`.""" return PreviewDiff.create( self, diff_content, source_revision_id, target_revision_id, prerequisite_revision_id, conflicts)
def test_fromBranchMergeProposal(self): # Correctly generates a PreviewDiff from a BranchMergeProposal. bmp, source_rev_id, target_rev_id = self.createExampleMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual(source_rev_id, preview.source_revision_id) self.assertEqual(target_rev_id, preview.target_revision_id) transaction.commit() self.checkExampleMerge(preview.text) self.assertEqual({'foo': (5, 0)}, preview.diffstat)
def test_fromBranchMergeProposal_with_prerequisite(self): # Correctly generates a PreviewDiff from a BranchMergeProposal. prerequisite_branch = self.factory.makeProductBranch() bmp = self.factory.makeBranchMergeProposal( prerequisite_branch=prerequisite_branch) self.preparePrerequisiteMerge(bmp) preview = PreviewDiff.fromBranchMergeProposal(bmp) transaction.commit() self.assertIn('+source text\n', preview.text) self.assertNotIn('+prerequisite text\n', preview.text)
def updatePreviewDiff(self, diff_content, source_revision_id, target_revision_id, prerequisite_revision_id=None, conflicts=None): """See `IBranchMergeProposal`.""" return PreviewDiff.create(self, diff_content, source_revision_id, target_revision_id, prerequisite_revision_id, conflicts)
def test_fromPreviewDiff_with_no_conflicts(self): """Test fromPreviewDiff when no conflicts are present.""" self.useBzrBranches(direct_database=True) bmp = self.factory.makeBranchMergeProposal() bzr_target = self.createBzrBranch(bmp.target_branch) commit_file(bmp.target_branch, 'foo', 'a\n') self.createBzrBranch(bmp.source_branch, bzr_target) commit_file(bmp.source_branch, 'foo', 'a\nb\n') commit_file(bmp.target_branch, 'foo', 'c\na\n') diff = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('', diff.conflicts) self.assertFalse(diff.has_conflicts)
def makeProposalWithSubscriber(self, diff_text=None, initial_comment=None, prerequisite=False, needs_review=True, reviewer=None): registrant = self.factory.makePerson( name='bazqux', displayname='Baz Qux', email='*****@*****.**') product = self.factory.makeProduct(name='super-product') if prerequisite: prerequisite_branch = self.factory.makeProductBranch(product) else: prerequisite_branch = None if needs_review: initial_status = BranchMergeProposalStatus.NEEDS_REVIEW else: initial_status = BranchMergeProposalStatus.WORK_IN_PROGRESS bmp = self.factory.makeBranchMergeProposal( registrant=registrant, product=product, set_state=initial_status, prerequisite_branch=prerequisite_branch, initial_comment=initial_comment, reviewer=reviewer) if diff_text: PreviewDiff.create( bmp, diff_text, unicode(self.factory.getUniqueString('revid')), unicode(self.factory.getUniqueString('revid')), None, None) transaction.commit() subscriber = self.factory.makePerson(displayname='Baz Quxx', email='*****@*****.**') bmp.source_branch.subscribe(subscriber, BranchSubscriptionNotificationLevel.NOEMAIL, None, CodeReviewNotificationLevel.FULL, subscriber) bmp.source_branch.owner.name = 'bob' bmp.source_branch.name = 'fix-foo-for-bar' bmp.target_branch.owner.name = 'mary' bmp.target_branch.name = 'bar' bmp.commit_message = 'commit message' # Call the function that is normally called through the event system # to auto reload the fields updated by the db triggers. update_trigger_modified_fields(bmp.source_branch) update_trigger_modified_fields(bmp.target_branch) return bmp, subscriber
def test_fromBranchMergeProposal_sets_conflicts(self): """Conflicts are set on the PreviewDiff.""" bmp, source_rev_id, target_rev_id = self.createExampleMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('Text conflict in foo\n', preview.conflicts) self.assertTrue(preview.has_conflicts)
def run(self): """See `IRunnableJob`.""" self.checkReady() with server(get_ro_server(), no_replace=True): with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)
def test_fromBranchMergeProposalForGit_sets_conflicts(self): # Conflicts are set on the PreviewDiff. bmp, source_rev_id, target_rev_id, _ = self.createExampleGitMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('Conflict in foo\n', preview.conflicts) self.assertTrue(preview.has_conflicts)