Merge lp:~matsubara/launchpad/ec2-land-update-mp into lp:launchpad

Proposed by Diogo Matsubara
Status: Merged
Approved by: Māris Fogels
Approved revision: no longer in the source branch.
Merged at revision: 11886
Proposed branch: lp:~matsubara/launchpad/ec2-land-update-mp
Merge into: lp:launchpad
Diff against target: 192 lines (+64/-16)
3 files modified
lib/devscripts/autoland.py (+19/-5)
lib/devscripts/ec2test/builtins.py (+10/-1)
lib/devscripts/tests/test_autoland.py (+35/-10)
To merge this branch: bzr merge lp:~matsubara/launchpad/ec2-land-update-mp
Reviewer Review Type Date Requested Status
Māris Fogels (community) Approve
Review via email: mp+40231@code.launchpad.net

Commit message

[r=mars][ui=none][bug=672519] Change ec2 land command to update the merge proposal commit message attribute with the built commit message with proper QA tags.

Description of the change

Hi there,

this branch changes the ec2 land command to add the built commit message to the merge proposal. This is done in preparation for https://dev.launchpad.net/Foundations/Proposals/SimplifyMergeMachinery

It also changes the method to get_commit_message to build_commit_message to make it more clear what it's doing.

To run tests: bin/test -tt test_autoland

To post a comment you must log in.
Revision history for this message
Māris Fogels (mars) wrote :

Hi Diogo,

This code looks very good. r=mars.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/devscripts/autoland.py'
2--- lib/devscripts/autoland.py 2010-10-24 21:00:11 +0000
3+++ lib/devscripts/autoland.py 2010-11-05 20:24:17 +0000
4@@ -160,21 +160,35 @@
5 # URL. Do it ourselves.
6 return URI(scheme='bzr+ssh', host=host, path='/' + branch.unique_name)
7
8- def get_commit_message(self, commit_text, testfix=False, no_qa=False,
9+ def build_commit_message(self, commit_text, testfix=False, no_qa=False,
10 incremental=False, rollback=None):
11 """Get the Launchpad-style commit message for a merge proposal."""
12 reviews = self.get_reviews()
13 bugs = self.get_bugs()
14
15- tags = ''.join([
16+ tags = [
17 get_testfix_clause(testfix),
18 get_reviewer_clause(reviews),
19 get_bugs_clause(bugs),
20 get_qa_clause(bugs, no_qa,
21 incremental, rollback=rollback),
22- ])
23-
24- return '%s %s' % (tags, commit_text)
25+ ]
26+
27+ # Make sure we don't add duplicated tags to commit_text.
28+ commit_tags = tags[:]
29+ for tag in tags:
30+ if tag in commit_text:
31+ commit_tags.remove(tag)
32+
33+ if commit_tags:
34+ return '%s %s' % (''.join(commit_tags), commit_text)
35+ else:
36+ return commit_text
37+
38+ def set_commit_message(self, commit_message):
39+ """Set the Launchpad-style commit message for a merge proposal."""
40+ self._mp.commit_message = commit_message
41+ self._mp.lp_save()
42
43
44 def get_testfix_clause(testfix=False):
45
46=== modified file 'lib/devscripts/ec2test/builtins.py'
47--- lib/devscripts/ec2test/builtins.py 2010-10-29 14:52:10 +0000
48+++ lib/devscripts/ec2test/builtins.py 2010-11-05 20:24:17 +0000
49@@ -411,7 +411,7 @@
50 if rollback and (no_qa or incremental):
51 print "--rollback option used. Ignoring --no-qa and --incremental."
52 try:
53- commit_message = mp.get_commit_message(
54+ commit_message = mp.build_commit_message(
55 commit_text, testfix, no_qa, incremental, rollback=rollback)
56 except MissingReviewError:
57 raise BzrCommandError(
58@@ -428,6 +428,15 @@
59 "--incremental option requires bugs linked to the branch. "
60 "Link the bugs or remove the --incremental option.")
61
62+ # Override the commit message in the MP with the commit message built
63+ # with the proper tags.
64+ try:
65+ mp.set_commit_message(commit_message)
66+ except Exception, e:
67+ raise BzrCommandError(
68+ "Unable to set the commit message in the merge proposal.\n"
69+ "Got: %s" % e)
70+
71 if print_commit:
72 print commit_message
73 return
74
75=== modified file 'lib/devscripts/tests/test_autoland.py'
76--- lib/devscripts/tests/test_autoland.py 2010-09-03 15:13:01 +0000
77+++ lib/devscripts/tests/test_autoland.py 2010-11-05 20:24:17 +0000
78@@ -59,6 +59,10 @@
79
80 def __init__(self, root=None):
81 self._root = root
82+ self.commit_message = None
83+
84+ def lp_save(self):
85+ pass
86
87
88 class TestPQMRegexAcceptance(unittest.TestCase):
89@@ -91,7 +95,7 @@
90 raise self.failureException(msg)
91
92 def _test_commit_message_match(self, incr, no_qa, testfix):
93- commit_message = self.mp.get_commit_message("Foobaring the sbrubble.",
94+ commit_message = self.mp.build_commit_message("Foobaring the sbrubble.",
95 testfix, no_qa, incr)
96 self.assertRegexpMatches(commit_message, self.devel_open_re)
97 self.assertRegexpMatches(commit_message, self.dbdevel_normal_re)
98@@ -150,7 +154,7 @@
99 self.mp.get_reviews = FakeMethod({None : [self.fake_person]})
100
101 self.assertEqual("[r=foo][ui=none][bug=20] Foobaring the sbrubble.",
102- self.mp.get_commit_message("Foobaring the sbrubble.",
103+ self.mp.build_commit_message("Foobaring the sbrubble.",
104 testfix, no_qa, incr))
105
106 def test_commit_no_bugs_no_noqa(self):
107@@ -161,7 +165,7 @@
108 self.mp.get_bugs = FakeMethod([])
109 self.mp.get_reviews = FakeMethod({None : [self.fake_person]})
110
111- self.assertRaises(MissingBugsError, self.mp.get_commit_message,
112+ self.assertRaises(MissingBugsError, self.mp.build_commit_message,
113 testfix, no_qa, incr)
114
115 def test_commit_no_bugs_with_noqa(self):
116@@ -173,7 +177,7 @@
117 self.mp.get_reviews = FakeMethod({None : [self.fake_person]})
118
119 self.assertEqual("[r=foo][ui=none][no-qa] Foobaring the sbrubble.",
120- self.mp.get_commit_message("Foobaring the sbrubble.",
121+ self.mp.build_commit_message("Foobaring the sbrubble.",
122 testfix, no_qa, incr))
123
124 def test_commit_bugs_with_noqa(self):
125@@ -186,7 +190,7 @@
126
127 self.assertEqual(
128 "[r=foo][ui=none][bug=20][no-qa] Foobaring the sbrubble.",
129- self.mp.get_commit_message("Foobaring the sbrubble.",
130+ self.mp.build_commit_message("Foobaring the sbrubble.",
131 testfix, no_qa, incr))
132
133 def test_commit_bugs_with_incr(self):
134@@ -199,7 +203,7 @@
135
136 self.assertEqual(
137 "[r=foo][ui=none][bug=20][incr] Foobaring the sbrubble.",
138- self.mp.get_commit_message("Foobaring the sbrubble.",
139+ self.mp.build_commit_message("Foobaring the sbrubble.",
140 testfix, no_qa, incr))
141
142 def test_commit_no_bugs_with_incr(self):
143@@ -212,7 +216,7 @@
144
145 self.assertEqual(
146 "[r=foo][ui=none][bug=20][incr] Foobaring the sbrubble.",
147- self.mp.get_commit_message("Foobaring the sbrubble.",
148+ self.mp.build_commit_message("Foobaring the sbrubble.",
149 testfix, no_qa, incr))
150
151 def test_commit_with_noqa_and_incr(self):
152@@ -225,7 +229,7 @@
153
154 self.assertEqual(
155 "[r=foo][ui=none][bug=20][no-qa][incr] Foobaring the sbrubble.",
156- self.mp.get_commit_message("Foobaring the sbrubble.",
157+ self.mp.build_commit_message("Foobaring the sbrubble.",
158 testfix, no_qa, incr))
159
160 def test_commit_with_rollback(self):
161@@ -234,8 +238,29 @@
162
163 self.assertEqual(
164 "[r=foo][ui=none][bug=20][rollback=123] Foobaring the sbrubble.",
165- self.mp.get_commit_message("Foobaring the sbrubble.",
166- rollback=123))
167+ self.mp.build_commit_message("Foobaring the sbrubble.",
168+ rollback=123))
169+
170+ def test_takes_into_account_existing_tags_on_commit_text(self):
171+ self.mp.get_bugs = FakeMethod([self.fake_bug])
172+ self.mp.get_reviews = FakeMethod({None : [self.fake_person]})
173+
174+ self.assertEqual(
175+ "[r=foo][ui=none][bug=20][rollback=123] Foobaring the sbrubble.",
176+ self.mp.build_commit_message(
177+ "[r=foo][ui=none][bug=20][rollback=123] Foobaring the sbrubble.",
178+ rollback=123))
179+
180+
181+class TestSetCommitMessage(unittest.TestCase):
182+
183+ def setUp(self):
184+ self.mp = MergeProposal(FakeLPMergeProposal())
185+
186+ def test_set_commit_message(self):
187+ commit_message = "Foobaring the sbrubble."
188+ self.mp.set_commit_message(commit_message)
189+ self.assertEqual(self.mp._mp.commit_message, commit_message)
190
191
192 class TestGetTestfixClause(unittest.TestCase):