Merge lp:~cjwatson/launchpad/notify-changed-by-field into lp:launchpad

Proposed by Colin Watson on 2016-10-16
Status: Merged
Merged at revision: 18253
Proposed branch: lp:~cjwatson/launchpad/notify-changed-by-field
Merge into: lp:launchpad
Diff against target: 146 lines (+70/-2)
2 files modified
lib/lp/soyuz/mail/packageupload.py (+18/-1)
lib/lp/soyuz/mail/tests/test_packageupload.py (+52/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/notify-changed-by-field
Reviewer Review Type Date Requested Status
William Grant code 2016-10-16 Approve on 2016-11-03
Review via email: mp+308587@code.launchpad.net

Commit message

Notify the Changed-By address for PPA uploads if the .changes contains "Launchpad-Notify-Changed-By: yes".

To post a comment you must log in.
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/soyuz/mail/packageupload.py'
2--- lib/lp/soyuz/mail/packageupload.py 2015-09-02 12:05:15 +0000
3+++ lib/lp/soyuz/mail/packageupload.py 2016-11-04 10:45:21 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2011-2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2011-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -133,6 +133,7 @@
11
12 def fetch_information(spr, bprs, changes, previous_version=None):
13 changelog = date = changedby = maintainer = None
14+ notify_changed_by = False
15
16 if changes:
17 changelog = ChangesFile.formatChangesComment(
18@@ -148,6 +149,8 @@
19 changes.get('Maintainer'), 'Maintainer')
20 except ParseMaintError:
21 pass
22+ notify_changed_by = changes.get(
23+ 'Launchpad-Notify-Changed-By', '') == 'yes'
24 elif spr or bprs:
25 if not spr and bprs:
26 spr = bprs[0].build.source_package_release
27@@ -166,6 +169,7 @@
28 'date': date,
29 'changedby': changedby,
30 'maintainer': maintainer,
31+ 'notify_changed_by': notify_changed_by,
32 }
33
34
35@@ -338,6 +342,19 @@
36 add_recipient(
37 recipients, permission.person,
38 PackageUploadRecipientReason.forPPAUploader, logger=logger)
39+
40+ # If the "Launchpad-Notify-Changed-By: yes" field is set in the
41+ # .changes file, we also consider changed-by. The latter is
42+ # intended for use by systems that automatically sign uploads on
43+ # behalf of developers, in which case we want to make sure to
44+ # notify the developer in question. We assume that any systems
45+ # clever enough to set this field are also clever enough to set
46+ # a reasonable Changed-By field.
47+ if info['notify_changed_by']:
48+ debug(logger, "Adding changed-by to recipients")
49+ add_recipient(
50+ recipients, changer,
51+ PackageUploadRecipientReason.forChangedBy, logger=logger)
52 elif archive.is_copy:
53 # For copy archives, notifying anyone else will probably only
54 # confuse them.
55
56=== modified file 'lib/lp/soyuz/mail/tests/test_packageupload.py'
57--- lib/lp/soyuz/mail/tests/test_packageupload.py 2015-09-11 12:20:23 +0000
58+++ lib/lp/soyuz/mail/tests/test_packageupload.py 2016-11-04 10:45:21 +0000
59@@ -2,7 +2,7 @@
60 # NOTE: The first line above must stay first; do not move the copyright
61 # notice to the top. See http://www.python.org/dev/peps/pep-0263/.
62 #
63-# Copyright 2011-2015 Canonical Ltd. This software is licensed under the
64+# Copyright 2011-2016 Canonical Ltd. This software is licensed under the
65 # GNU Affero General Public License version 3 (see the file LICENSE).
66
67 from textwrap import dedent
68@@ -267,6 +267,26 @@
69 ]
70 for field in fields:
71 self.assertEqual((u'Foo Bar', u'foo.bar@example.com'), field)
72+ self.assertFalse(info['notify_changed_by'])
73+
74+ def test_fetch_information_changes_notify_changed_by(self):
75+ changes = {
76+ 'Date': '2001-01-01',
77+ 'Changed-By': 'Foo Bar <foo.bar@example.com>',
78+ 'Maintainer': 'Foo Bar <foo.bar@example.com>',
79+ 'Changes': ' * Foo!',
80+ 'Launchpad-Notify-Changed-By': 'yes',
81+ }
82+ info = fetch_information(None, None, changes)
83+ self.assertEqual('2001-01-01', info['date'])
84+ self.assertEqual(' * Foo!', info['changelog'])
85+ fields = [
86+ info['changedby'],
87+ info['maintainer'],
88+ ]
89+ for field in fields:
90+ self.assertEqual((u'Foo Bar', u'foo.bar@example.com'), field)
91+ self.assertTrue(info['notify_changed_by'])
92
93 def test_fetch_information_spr(self):
94 creator = self.factory.makePerson(displayname=u"foø")
95@@ -280,6 +300,7 @@
96 (u"foø", spr.creator.preferredemail.email), info['changedby'])
97 self.assertEqual(
98 (u"bær", spr.maintainer.preferredemail.email), info['maintainer'])
99+ self.assertFalse(info['notify_changed_by'])
100
101 def test_fetch_information_bprs(self):
102 bpr = self.factory.makeBinaryPackageRelease()
103@@ -293,6 +314,7 @@
104 self.assertEqual(
105 (spr.maintainer.displayname, spr.maintainer.preferredemail.email),
106 info['maintainer'])
107+ self.assertFalse(info['notify_changed_by'])
108
109 def test_calculate_subject_spr(self):
110 spr = self.factory.makeSourcePackageRelease()
111@@ -433,6 +455,35 @@
112 [], changes, None, maintainer, changer,
113 purpose=ArchivePurpose.COPY)
114
115+ def test_getRecipientsForAction_ppa(self):
116+ # Notifications for PPA uploads normally only go to the person who
117+ # signed the upload.
118+ blamer, maintainer, changer = self._setup_recipients()
119+ changes = {
120+ 'Date': '2001-01-01',
121+ 'Changed-By': 'Changer <changer@example.com>',
122+ 'Maintainer': 'Maintainer <maintainer@example.com>',
123+ 'Changes': ' * Foo!',
124+ }
125+ self.assertRecipientsEqual(
126+ [blamer], changes, blamer, maintainer, changer,
127+ purpose=ArchivePurpose.PPA)
128+
129+ def test_getRecipientsForAction_ppa_notify_changed_by(self):
130+ # If the .changes file contains "Launchpad-Notify-Changed-By: yes",
131+ # notifications go to the changer even for PPA uploads.
132+ blamer, maintainer, changer = self._setup_recipients()
133+ changes = {
134+ 'Date': '2001-01-01',
135+ 'Changed-By': 'Changer <changer@example.com>',
136+ 'Maintainer': 'Maintainer <maintainer@example.com>',
137+ 'Changes': ' * Foo!',
138+ 'Launchpad-Notify-Changed-By': 'yes',
139+ }
140+ self.assertRecipientsEqual(
141+ [blamer, changer], changes, blamer, maintainer, changer,
142+ purpose=ArchivePurpose.PPA)
143+
144 def test__getHeaders_primary(self):
145 # _getHeaders returns useful values for headers used for filtering.
146 # For a primary archive, this includes the maintainer and changer.