Merge lp:~cjwatson/launchpad/bmp-export-scheduleDiffUpdates into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18511
Proposed branch: lp:~cjwatson/launchpad/bmp-export-scheduleDiffUpdates
Merge into: lp:launchpad
Diff against target: 172 lines (+70/-15)
5 files modified
lib/lp/code/interfaces/branchmergeproposal.py (+14/-1)
lib/lp/code/model/branch.py (+2/-11)
lib/lp/code/model/branchmergeproposal.py (+17/-0)
lib/lp/code/model/gitrepository.py (+1/-2)
lib/lp/code/model/tests/test_branchmergeproposal.py (+36/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bmp-export-scheduleDiffUpdates
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+334256@code.launchpad.net

Commit message

Add and export BranchMergeProposal.scheduleDiffUpdates.

Description of the change

There are various situations where we might reasonably want to ask Launchpad to update an MP's preview diff, and there's no good way to do that right now, short of rescanning the branch or the repository - quite an invasive operation, particularly in the Git case. This is a bit more targeted.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
--- lib/lp/code/interfaces/branchmergeproposal.py 2017-07-26 11:21:31 +0000
+++ lib/lp/code/interfaces/branchmergeproposal.py 2017-11-25 14:13:35 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""The interface for branch merge proposals."""4"""The interface for branch merge proposals."""
@@ -510,6 +510,19 @@
510 :param conflicts: Text describing the conflicts if any.510 :param conflicts: Text describing the conflicts if any.
511 """511 """
512512
513 @call_with(return_jobs=False)
514 @export_write_operation()
515 @operation_for_version('devel')
516 def scheduleDiffUpdates(return_jobs=True):
517 """Schedule updates of the diffs for this proposal.
518
519 This can be used if the previous attempt to generate diffs crashed,
520 or if Launchpad failed to notice that the current diffs are outdated
521 for some reason.
522
523 :param return_jobs: If True, return the created jobs.
524 """
525
513 @call_with(user=REQUEST_USER)526 @call_with(user=REQUEST_USER)
514 @rename_parameters_as(revision_id='revid')527 @rename_parameters_as(revision_id='revid')
515 @operation_parameters(528 @operation_parameters(
516529
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2017-11-06 09:32:45 +0000
+++ lib/lp/code/model/branch.py 2017-11-25 14:13:35 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -653,18 +653,9 @@
653653
654 def scheduleDiffUpdates(self):654 def scheduleDiffUpdates(self):
655 """See `IBranch`."""655 """See `IBranch`."""
656 from lp.code.model.branchmergeproposaljob import (
657 GenerateIncrementalDiffJob,
658 UpdatePreviewDiffJob,
659 )
660 jobs = []656 jobs = []
661 for merge_proposal in self.active_landing_targets:657 for merge_proposal in self.active_landing_targets:
662 if merge_proposal.target_branch.last_scanned_id is None:658 jobs.extend(merge_proposal.scheduleDiffUpdates())
663 continue
664 jobs.append(UpdatePreviewDiffJob.create(merge_proposal))
665 for old, new in merge_proposal.getMissingIncrementalDiffs():
666 GenerateIncrementalDiffJob.create(
667 merge_proposal, old.revision_id, new.revision_id)
668 return jobs659 return jobs
669660
670 def markRecipesStale(self):661 def markRecipesStale(self):
671662
=== modified file 'lib/lp/code/model/branchmergeproposal.py'
--- lib/lp/code/model/branchmergeproposal.py 2017-05-23 08:24:55 +0000
+++ lib/lp/code/model/branchmergeproposal.py 2017-11-25 14:13:35 +0000
@@ -1179,6 +1179,23 @@
1179 for diff in diffs)1179 for diff in diffs)
1180 return [diff_dict.get(revisions) for revisions in revision_list]1180 return [diff_dict.get(revisions) for revisions in revision_list]
11811181
1182 def scheduleDiffUpdates(self, return_jobs=True):
1183 """See `IBranchMergeProposal`."""
1184 from lp.code.model.branchmergeproposaljob import (
1185 GenerateIncrementalDiffJob,
1186 UpdatePreviewDiffJob,
1187 )
1188 jobs = []
1189 if (self.target_branch is None or
1190 self.target_branch.last_scanned_id is not None):
1191 jobs.append(UpdatePreviewDiffJob.create(self))
1192 if self.target_branch is not None:
1193 for old, new in self.getMissingIncrementalDiffs():
1194 jobs.append(GenerateIncrementalDiffJob.create(
1195 self, old.revision_id, new.revision_id))
1196 if return_jobs:
1197 return jobs
1198
1182 @property1199 @property
1183 def revision_end_date(self):1200 def revision_end_date(self):
1184 """The cutoff date for showing revisions.1201 """The cutoff date for showing revisions.
11851202
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2017-11-06 09:32:45 +0000
+++ lib/lp/code/model/gitrepository.py 2017-11-25 14:13:35 +0000
@@ -1011,10 +1011,9 @@
10111011
1012 def updateLandingTargets(self, paths):1012 def updateLandingTargets(self, paths):
1013 """See `IGitRepository`."""1013 """See `IGitRepository`."""
1014 from lp.code.model.branchmergeproposaljob import UpdatePreviewDiffJob
1015 jobs = []1014 jobs = []
1016 for merge_proposal in self.getActiveLandingTargets(paths):1015 for merge_proposal in self.getActiveLandingTargets(paths):
1017 jobs.append(UpdatePreviewDiffJob.create(merge_proposal))1016 jobs.extend(merge_proposal.scheduleDiffUpdates())
1018 return jobs1017 return jobs
10191018
1020 def _getRecipes(self, paths=None):1019 def _getRecipes(self, paths=None):
10211020
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
--- lib/lp/code/model/tests/test_branchmergeproposal.py 2017-10-04 01:53:48 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2017-11-25 14:13:35 +0000
@@ -60,6 +60,7 @@
60 BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG,60 BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG,
61 IBranchMergeProposal,61 IBranchMergeProposal,
62 IBranchMergeProposalGetter,62 IBranchMergeProposalGetter,
63 IBranchMergeProposalJobSource,
63 notify_modified,64 notify_modified,
64 )65 )
65from lp.code.model.branchmergeproposal import (66from lp.code.model.branchmergeproposal import (
@@ -82,6 +83,7 @@
82from lp.services.config import config83from lp.services.config import config
83from lp.services.database.constants import UTC_NOW84from lp.services.database.constants import UTC_NOW
84from lp.services.features.testing import FeatureFixture85from lp.services.features.testing import FeatureFixture
86from lp.services.job.interfaces.job import JobStatus
85from lp.services.webapp import canonical_url87from lp.services.webapp import canonical_url
86from lp.services.xref.interfaces import IXRefSet88from lp.services.xref.interfaces import IXRefSet
87from lp.testing import (89from lp.testing import (
@@ -2082,7 +2084,7 @@
20822084
20832085
2084class TestUpdatePreviewDiff(TestCaseWithFactory):2086class TestUpdatePreviewDiff(TestCaseWithFactory):
2085 """Test the updateMergeDiff method of BranchMergeProposal."""2087 """Test the updatePreviewDiff method of BranchMergeProposal."""
20862088
2087 layer = LaunchpadFunctionalLayer2089 layer = LaunchpadFunctionalLayer
20882090
@@ -2137,6 +2139,39 @@
2137 diff_id, removeSecurityProxy(merge_proposal.preview_diff).diff_id)2139 diff_id, removeSecurityProxy(merge_proposal.preview_diff).diff_id)
21382140
21392141
2142class TestScheduleDiffUpdates(TestCaseWithFactory):
2143 """Test scheduling of diff updates."""
2144
2145 layer = DatabaseFunctionalLayer
2146
2147 def setUp(self):
2148 super(TestScheduleDiffUpdates, self).setUp()
2149 self.job_source = removeSecurityProxy(
2150 getUtility(IBranchMergeProposalJobSource))
2151
2152 def test_scheduleDiffUpdates_bzr(self):
2153 bmp = self.factory.makeBranchMergeProposal()
2154 self.factory.makeRevisionsForBranch(bmp.source_branch)
2155 self.factory.makeRevisionsForBranch(bmp.target_branch)
2156 [job] = self.job_source.iterReady()
2157 removeSecurityProxy(job).job._status = JobStatus.COMPLETED
2158 self.assertEqual([], list(self.job_source.iterReady()))
2159 with person_logged_in(bmp.merge_target.owner):
2160 bmp.scheduleDiffUpdates()
2161 [job] = self.job_source.iterReady()
2162 self.assertIsInstance(job, UpdatePreviewDiffJob)
2163
2164 def test_scheduleDiffUpdates_git(self):
2165 bmp = self.factory.makeBranchMergeProposalForGit()
2166 [job] = self.job_source.iterReady()
2167 removeSecurityProxy(job).job._status = JobStatus.COMPLETED
2168 self.assertEqual([], list(self.job_source.iterReady()))
2169 with person_logged_in(bmp.merge_target.owner):
2170 bmp.scheduleDiffUpdates()
2171 [job] = self.job_source.iterReady()
2172 self.assertIsInstance(job, UpdatePreviewDiffJob)
2173
2174
2140class TestNextPreviewDiffJob(TestCaseWithFactory):2175class TestNextPreviewDiffJob(TestCaseWithFactory):
21412176
2142 layer = DatabaseFunctionalLayer2177 layer = DatabaseFunctionalLayer