14027.3.7
by Jeroen Vermeulen
Conflicts. |
1 |
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
|
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3 |
||
4 |
"""Event subscribers for branch merge proposals."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
||
9 |
from zope.app.security.principalregistry import UnauthenticatedPrincipal |
|
10 |
from zope.component import getUtility |
|
11 |
||
13333.13.54
by Gavin Panella
Rename BranchMergeProposalDelta to BranchMergeProposalNoPreviewDiffDelta and BranchMergeProposalWithPreviewDiffDelta to BranchMergeProposalDelta, and change BranchMergeProposalNoPreviewDiffDelta to inherit from BranchMergeProposalDelta. |
12 |
from lp.code.adapters.branch import BranchMergeProposalNoPreviewDiffDelta |
11807.4.4
by Tim Penhey
Don't send out modification emails if the proposal is work in progress. |
13 |
from lp.code.enums import BranchMergeProposalStatus |
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
14 |
from lp.code.interfaces.branchmergeproposal import ( |
11733.1.3
by Tim Penhey
Copied and pasted wrong name. D'oh. |
15 |
IMergeProposalNeedsReviewEmailJobSource, |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
16 |
IMergeProposalUpdatedEmailJobSource, |
17 |
IReviewRequestedEmailJobSource, |
|
18 |
IUpdatePreviewDiffJobSource, |
|
19 |
)
|
|
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
20 |
from lp.registry.interfaces.person import IPerson |
21 |
from lp.services.utils import text_delta |
|
22 |
||
23 |
||
24 |
def merge_proposal_created(merge_proposal, event): |
|
25 |
"""A new merge proposal has been created.
|
|
26 |
||
7675.624.20
by Tim Penhey
Also create an update preview diff job when a new merge proposal is created. |
27 |
Create a job to update the diff for the merge proposal.
|
28 |
Also create a job to email the subscribers about the new proposal.
|
|
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
29 |
"""
|
7675.624.20
by Tim Penhey
Also create an update preview diff job when a new merge proposal is created. |
30 |
getUtility(IUpdatePreviewDiffJobSource).create(merge_proposal) |
11733.1.4
by Tim Penhey
Add an extra event for the needs review, but keep the same functionality for now. |
31 |
|
32 |
||
33 |
def merge_proposal_needs_review(merge_proposal, event): |
|
34 |
"""A new merge proposal needs a review.
|
|
35 |
||
36 |
This event is raised when the proposal moves from work in progress to
|
|
37 |
needs review.
|
|
38 |
"""
|
|
11733.1.3
by Tim Penhey
Copied and pasted wrong name. D'oh. |
39 |
getUtility(IMergeProposalNeedsReviewEmailJobSource).create( |
11733.1.1
by Tim Penhey
Rename the MergeProposalCreatedJob to be MergeProposalReviewRequestedEmailJob. |
40 |
merge_proposal) |
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
41 |
|
42 |
||
43 |
def merge_proposal_modified(merge_proposal, event): |
|
44 |
"""Notify branch subscribers when merge proposals are updated."""
|
|
45 |
# Check the user.
|
|
46 |
if event.user is None: |
|
47 |
return
|
|
48 |
if isinstance(event.user, UnauthenticatedPrincipal): |
|
49 |
from_person = None |
|
50 |
else: |
|
51 |
from_person = IPerson(event.user) |
|
11807.4.4
by Tim Penhey
Don't send out modification emails if the proposal is work in progress. |
52 |
# If the merge proposal was work in progress, then we don't want to send
|
53 |
# out an email as the needs review email will cover that.
|
|
54 |
old_status = event.object_before_modification.queue_status |
|
55 |
if old_status == BranchMergeProposalStatus.WORK_IN_PROGRESS: |
|
11807.4.12
by Tim Penhey
Do send email if work in progress is merged. |
56 |
# Unless the new status is merged. If this occurs we really should
|
57 |
# send out an email.
|
|
58 |
if merge_proposal.queue_status != BranchMergeProposalStatus.MERGED: |
|
59 |
return
|
|
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
60 |
# Create a delta of the changes. If there are no changes to report, then
|
61 |
# we're done.
|
|
13333.13.54
by Gavin Panella
Rename BranchMergeProposalDelta to BranchMergeProposalNoPreviewDiffDelta and BranchMergeProposalWithPreviewDiffDelta to BranchMergeProposalDelta, and change BranchMergeProposalNoPreviewDiffDelta to inherit from BranchMergeProposalDelta. |
62 |
delta = BranchMergeProposalNoPreviewDiffDelta.construct( |
7675.624.15
by Tim Penhey
Move the event subscribers into the subscriber package. |
63 |
event.object_before_modification, merge_proposal) |
64 |
if delta is None: |
|
65 |
return
|
|
66 |
changes = text_delta( |
|
67 |
delta, delta.delta_values, delta.new_values, delta.interface) |
|
68 |
# Now create the job to send the email.
|
|
69 |
getUtility(IMergeProposalUpdatedEmailJobSource).create( |
|
70 |
merge_proposal, changes, from_person) |
|
71 |
||
72 |
||
73 |
def review_requested(vote_reference, event): |
|
74 |
"""Notify the reviewer that they have been requested to review."""
|
|
11807.4.8
by Tim Penhey
Don't send review requests if work in progress. |
75 |
# Don't send email if the proposal is work in progress.
|
76 |
bmp_status = vote_reference.branch_merge_proposal.queue_status |
|
77 |
if bmp_status != BranchMergeProposalStatus.WORK_IN_PROGRESS: |
|
78 |
getUtility(IReviewRequestedEmailJobSource).create(vote_reference) |