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
1=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
2--- lib/lp/code/interfaces/branchmergeproposal.py 2017-07-26 11:21:31 +0000
3+++ lib/lp/code/interfaces/branchmergeproposal.py 2017-11-25 14:13:35 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """The interface for branch merge proposals."""
10@@ -510,6 +510,19 @@
11 :param conflicts: Text describing the conflicts if any.
12 """
13
14+ @call_with(return_jobs=False)
15+ @export_write_operation()
16+ @operation_for_version('devel')
17+ def scheduleDiffUpdates(return_jobs=True):
18+ """Schedule updates of the diffs for this proposal.
19+
20+ This can be used if the previous attempt to generate diffs crashed,
21+ or if Launchpad failed to notice that the current diffs are outdated
22+ for some reason.
23+
24+ :param return_jobs: If True, return the created jobs.
25+ """
26+
27 @call_with(user=REQUEST_USER)
28 @rename_parameters_as(revision_id='revid')
29 @operation_parameters(
30
31=== modified file 'lib/lp/code/model/branch.py'
32--- lib/lp/code/model/branch.py 2017-11-06 09:32:45 +0000
33+++ lib/lp/code/model/branch.py 2017-11-25 14:13:35 +0000
34@@ -1,4 +1,4 @@
35-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
36+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
37 # GNU Affero General Public License version 3 (see the file LICENSE).
38
39 __metaclass__ = type
40@@ -653,18 +653,9 @@
41
42 def scheduleDiffUpdates(self):
43 """See `IBranch`."""
44- from lp.code.model.branchmergeproposaljob import (
45- GenerateIncrementalDiffJob,
46- UpdatePreviewDiffJob,
47- )
48 jobs = []
49 for merge_proposal in self.active_landing_targets:
50- if merge_proposal.target_branch.last_scanned_id is None:
51- continue
52- jobs.append(UpdatePreviewDiffJob.create(merge_proposal))
53- for old, new in merge_proposal.getMissingIncrementalDiffs():
54- GenerateIncrementalDiffJob.create(
55- merge_proposal, old.revision_id, new.revision_id)
56+ jobs.extend(merge_proposal.scheduleDiffUpdates())
57 return jobs
58
59 def markRecipesStale(self):
60
61=== modified file 'lib/lp/code/model/branchmergeproposal.py'
62--- lib/lp/code/model/branchmergeproposal.py 2017-05-23 08:24:55 +0000
63+++ lib/lp/code/model/branchmergeproposal.py 2017-11-25 14:13:35 +0000
64@@ -1179,6 +1179,23 @@
65 for diff in diffs)
66 return [diff_dict.get(revisions) for revisions in revision_list]
67
68+ def scheduleDiffUpdates(self, return_jobs=True):
69+ """See `IBranchMergeProposal`."""
70+ from lp.code.model.branchmergeproposaljob import (
71+ GenerateIncrementalDiffJob,
72+ UpdatePreviewDiffJob,
73+ )
74+ jobs = []
75+ if (self.target_branch is None or
76+ self.target_branch.last_scanned_id is not None):
77+ jobs.append(UpdatePreviewDiffJob.create(self))
78+ if self.target_branch is not None:
79+ for old, new in self.getMissingIncrementalDiffs():
80+ jobs.append(GenerateIncrementalDiffJob.create(
81+ self, old.revision_id, new.revision_id))
82+ if return_jobs:
83+ return jobs
84+
85 @property
86 def revision_end_date(self):
87 """The cutoff date for showing revisions.
88
89=== modified file 'lib/lp/code/model/gitrepository.py'
90--- lib/lp/code/model/gitrepository.py 2017-11-06 09:32:45 +0000
91+++ lib/lp/code/model/gitrepository.py 2017-11-25 14:13:35 +0000
92@@ -1011,10 +1011,9 @@
93
94 def updateLandingTargets(self, paths):
95 """See `IGitRepository`."""
96- from lp.code.model.branchmergeproposaljob import UpdatePreviewDiffJob
97 jobs = []
98 for merge_proposal in self.getActiveLandingTargets(paths):
99- jobs.append(UpdatePreviewDiffJob.create(merge_proposal))
100+ jobs.extend(merge_proposal.scheduleDiffUpdates())
101 return jobs
102
103 def _getRecipes(self, paths=None):
104
105=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
106--- lib/lp/code/model/tests/test_branchmergeproposal.py 2017-10-04 01:53:48 +0000
107+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2017-11-25 14:13:35 +0000
108@@ -60,6 +60,7 @@
109 BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG,
110 IBranchMergeProposal,
111 IBranchMergeProposalGetter,
112+ IBranchMergeProposalJobSource,
113 notify_modified,
114 )
115 from lp.code.model.branchmergeproposal import (
116@@ -82,6 +83,7 @@
117 from lp.services.config import config
118 from lp.services.database.constants import UTC_NOW
119 from lp.services.features.testing import FeatureFixture
120+from lp.services.job.interfaces.job import JobStatus
121 from lp.services.webapp import canonical_url
122 from lp.services.xref.interfaces import IXRefSet
123 from lp.testing import (
124@@ -2082,7 +2084,7 @@
125
126
127 class TestUpdatePreviewDiff(TestCaseWithFactory):
128- """Test the updateMergeDiff method of BranchMergeProposal."""
129+ """Test the updatePreviewDiff method of BranchMergeProposal."""
130
131 layer = LaunchpadFunctionalLayer
132
133@@ -2137,6 +2139,39 @@
134 diff_id, removeSecurityProxy(merge_proposal.preview_diff).diff_id)
135
136
137+class TestScheduleDiffUpdates(TestCaseWithFactory):
138+ """Test scheduling of diff updates."""
139+
140+ layer = DatabaseFunctionalLayer
141+
142+ def setUp(self):
143+ super(TestScheduleDiffUpdates, self).setUp()
144+ self.job_source = removeSecurityProxy(
145+ getUtility(IBranchMergeProposalJobSource))
146+
147+ def test_scheduleDiffUpdates_bzr(self):
148+ bmp = self.factory.makeBranchMergeProposal()
149+ self.factory.makeRevisionsForBranch(bmp.source_branch)
150+ self.factory.makeRevisionsForBranch(bmp.target_branch)
151+ [job] = self.job_source.iterReady()
152+ removeSecurityProxy(job).job._status = JobStatus.COMPLETED
153+ self.assertEqual([], list(self.job_source.iterReady()))
154+ with person_logged_in(bmp.merge_target.owner):
155+ bmp.scheduleDiffUpdates()
156+ [job] = self.job_source.iterReady()
157+ self.assertIsInstance(job, UpdatePreviewDiffJob)
158+
159+ def test_scheduleDiffUpdates_git(self):
160+ bmp = self.factory.makeBranchMergeProposalForGit()
161+ [job] = self.job_source.iterReady()
162+ removeSecurityProxy(job).job._status = JobStatus.COMPLETED
163+ self.assertEqual([], list(self.job_source.iterReady()))
164+ with person_logged_in(bmp.merge_target.owner):
165+ bmp.scheduleDiffUpdates()
166+ [job] = self.job_source.iterReady()
167+ self.assertIsInstance(job, UpdatePreviewDiffJob)
168+
169+
170 class TestNextPreviewDiffJob(TestCaseWithFactory):
171
172 layer = DatabaseFunctionalLayer