Merge lp:~dobey/tarmac/unapproved-revisions-comment into lp:tarmac

Proposed by dobey
Status: Merged
Approved by: Paul Hummer
Approved revision: 330
Merged at revision: 329
Proposed branch: lp:~dobey/tarmac/unapproved-revisions-comment
Merge into: lp:tarmac
Diff against target: 177 lines (+59/-45)
3 files modified
tarmac/bin/commands.py (+53/-37)
tarmac/exceptions.py (+4/-0)
tarmac/plugins/command.py (+2/-8)
To merge this branch: bzr merge lp:~dobey/tarmac/unapproved-revisions-comment
Reviewer Review Type Date Requested Status
Paul Hummer Approve
Review via email: mp+31775@code.launchpad.net

Commit message

Unify error handling for merge failure or rejection
Add UnaprovedChanges exception for when tip is newer than approved revision

To post a comment you must log in.
330. By dobey

Fix a typo and missing import

Revision history for this message
Paul Hummer (rockstar) wrote :

I'm a little unsure about the open "except Exception" but the code indicates that you've thought about that. I'm happy to land this and see if it causes any problems.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tarmac/bin/commands.py'
2--- tarmac/bin/commands.py 2010-08-03 15:38:18 +0000
3+++ tarmac/bin/commands.py 2010-08-04 18:58:40 +0000
4@@ -5,7 +5,7 @@
5 import re
6
7 from bzrlib.commands import Command
8-from bzrlib.errors import PointlessMerge
9+from bzrlib.errors import PointlessMerge, TipChangeRejected
10 from bzrlib.help import help_commands
11 from launchpadlib.launchpad import (Credentials, Launchpad, EDGE_SERVICE_ROOT,
12 STAGING_SERVICE_ROOT)
13@@ -15,7 +15,8 @@
14 from tarmac.config import TarmacConfig
15 from tarmac.hooks import tarmac_hooks
16 from tarmac.log import set_up_debug_logging, set_up_logging
17-from tarmac.exceptions import BranchHasConflicts, TarmacCommandError
18+from tarmac.exceptions import (BranchHasConflicts, TarmacCommandError,
19+ UnapprovedChanges)
20 from tarmac.plugin import load_plugins
21
22
23@@ -146,27 +147,65 @@
24 proposal.source_branch, self.config)
25
26 try:
27+ approved = proposal.reviewed_revid
28+ tip = proposal.source_branch.revision_count
29+ if tip > approved:
30+ raise UnapprovedChanges(
31+ 'Unapproved changes to branch after approval.')
32+
33 self.logger.debug(
34 'Merging %(source)s at revision %(revision)s' % {
35 'source': proposal.source_branch.display_name,
36 'revision': proposal.reviewed_revid,})
37+
38 target.merge(
39 source,
40 str(proposal.reviewed_revid))
41
42- except BranchHasConflicts:
43- subject = (
44- u"Conflicts merging %(source)s into %(target)s" % {
45- "source": proposal.source_branch.display_name,
46- "target": proposal.target_branch.display_name})
47- comment = (
48- u'Attempt to merge %(source)s into %(target)s failed '
49- u'due to merge conflicts:\n\n%(output)s' % {
50- "source": proposal.source_branch.display_name,
51- "target": proposal.target_branch.display_name,
52- "output": target.conflicts})
53+ except Exception, failure:
54+ subject = u'Re: [Merge] %(source)s into %(target)s' % {
55+ "source": proposal.source_branch.display_name,
56+ "target": proposal.target_branch.display_name,}
57+ comment = None
58+ if isinstance(BranchHasConflicts, failure):
59+ self.logger.warn(
60+ u'Conflicts merging %(source)s into %(target)s' % {
61+ "source": proposal.source_branch.display_name,
62+ "target": proposal.target_branch.display_name})
63+ comment = (
64+ u'Attempt to merge %(source)s into %(target)s '
65+ u'failed due to merge conflicts:\n\n%(output)s' % {
66+ "source": proposal.source_branch.display_name,
67+ "target": proposal.target_branch.display_name,
68+ "output": target.conflicts})
69+ elif isinstance(PointlessMerge, failure):
70+ self.logger.warn(
71+ 'Merging %(source)s into %(target)s would be '
72+ 'pointless.' % {
73+ 'source': proposal.source_branch.display_name,
74+ 'target': proposal.target_branch.display_name,})
75+ comment = (
76+ u'There is no resulting diff between %(source)s '
77+ u'and %(target)s.' % {
78+ "source": proposal.source_branch.display_name,
79+ "target": proposal.target_branch.display_name,})
80+ elif isinstance(TipChangeRejected, failure):
81+ comment = failure.msg
82+ elif isinstance(UnapprovedChanges, failure):
83+ self.logger.warn(
84+ u'Unapproved chagnes to %(source) were made '
85+ u'after approval for merge into %(target).' % {
86+ "source": proposal.source_branch.display_name,
87+ "target": proposal.target_branch.display_name,})
88+ comment = (
89+ u'There are additional revisions which have not '
90+ u'been approved in review. Please seek review and '
91+ u'approval of these revisions as well.')
92+ else:
93+ raise failure
94+
95 proposal.createComment(subject=subject, content=comment)
96- proposal.setStatus(status=u"Needs review")
97+ proposal.setStatus(status=u'Needs review')
98 proposal.lp_save()
99 self.logger.warn(
100 'Conflicts found while merging %(source)s into '
101@@ -176,29 +215,6 @@
102 target.cleanup()
103 continue
104
105- except PointlessMerge:
106- self.logger.warn(
107- 'Merging %(source)s into %(target)s would be '
108- 'pointless.' % {
109- 'source': proposal.source_branch.display_name,
110- 'target': proposal.target_branch.display_name,})
111-
112- subject = (
113- u"Pointless merge" % {
114- "source": proposal.source_branch.display_name,
115- "target": proposal.target_branch.display_name})
116- comment = (
117- u'There is no resulting diff between %(source)s '
118- u'and %(target)s.' % {
119- "source": proposal.source_branch.display_name,
120- "target": proposal.target_branch.display_name,})
121- proposal.createComment(subject=subject, content=comment)
122- proposal.setStatus(status=u"Needs review")
123- proposal.lp_save()
124-
125- target.cleanup()
126- continue
127-
128 urlp = re.compile('http[s]?://api\.(.*)launchpad\.net/beta/')
129 merge_url = urlp.sub(
130 'http://launchpad.net/', proposal.self_link)
131
132=== modified file 'tarmac/exceptions.py'
133--- tarmac/exceptions.py 2010-02-12 23:04:28 +0000
134+++ tarmac/exceptions.py 2010-08-04 18:58:40 +0000
135@@ -29,3 +29,7 @@
136
137 class TarmacCommandError(BzrCommandError):
138 '''Exception for various command errors.'''
139+
140+
141+class UnapprovedChanges(Exception):
142+ '''Exception for when a branch has unapproved changes.'''
143
144=== modified file 'tarmac/plugins/command.py'
145--- tarmac/plugins/command.py 2010-07-26 00:06:01 +0000
146+++ tarmac/plugins/command.py 2010-08-04 18:58:40 +0000
147@@ -65,8 +65,6 @@
148
149 if return_code != 0:
150 self.do_failed(stdout_value, stderr_value)
151- raise TipChangeRejected(
152- 'Test command "%s" failed' % self.verify_command)
153
154 def do_failed(self, stdout_value, stderr_value):
155 '''Perform failure tests.
156@@ -76,6 +74,7 @@
157 doesn't attempt to merge it again without human interaction. An
158 exception is then raised to prevent the commit from happening.
159 '''
160+ self.logger.warn(u'Test command "%s" failed.' % self.verify_command)
161 comment = (u'The attempt to merge %(source)s into %(target)s failed.' +
162 u'Below is the output from the failed tests.\n\n' +
163 u'%(output)s') % {
164@@ -83,12 +82,7 @@
165 'target' : self.proposal.target_branch.display_name,
166 'output' : u'\n'.join([stdout_value, stderr_value]),
167 }
168- subject = u'Re: [Merge] %s into %s' % (
169- self.proposal.source_branch.display_name,
170- self.proposal.target_branch.display_name)
171- self.proposal.createComment(subject=subject, content=comment)
172- self.proposal.setStatus(status=u'Needs review')
173- self.proposal.lp_save()
174+ raise TipChangeRejected(comment)
175
176
177 tarmac_hooks['tarmac_pre_commit'].hook(Command(), 'Command plugin')

Subscribers

People subscribed via source and target branches