55
55
hooks = ProposeMergeHooks()
57
57
def __init__(self, tree, source_branch, target_branch, message, reviews,
58
staging=False, approve=False):
61
61
:param tree: The working tree for the source branch.
65
65
:param reviews: A list of tuples of reviewer, review type.
66
66
:param staging: If True, propose the merge against staging instead of
68
:param approve: If True, mark the new proposal as approved immediately.
69
This is useful when a project permits some things to be approved
70
by the submitter (e.g. merges between release and deployment
81
85
self.target_branch = lp_api.LaunchpadBranch.from_bzr(
82
86
self.launchpad, target_branch)
83
87
self.commit_message = message
88
# XXX: this is where bug lp:583638 could be tackled.
85
90
target_reviewer = self.target_branch.lp.reviewer
86
91
if target_reviewer is None:
90
95
self.reviews = [(self.launchpad.people[reviewer], review_type)
91
96
for reviewer, review_type in
98
self.approve = approve
94
100
def get_comment(self, prerequisite_branch):
95
101
"""Determine the initial comment for the merge proposal."""
160
166
'prerequisite_branch': prerequisite_branch})
161
167
return prerequisite_branch
169
def call_webservice(self, call, *args, **kwargs):
170
"""Make a call to the webservice, wrapping failures.
172
:param call: The call to make.
173
:param *args: *args for the call.
174
:param **kwargs: **kwargs for the call.
175
:return: The result of calling call(*args, *kwargs).
178
return call(*args, **kwargs)
179
except restful_errors.HTTPError, e:
181
for line in e.content.splitlines():
182
if line.startswith('Traceback (most recent call last):'):
184
error_lines.append(line)
185
raise Exception(''.join(error_lines))
163
187
def create_proposal(self):
164
188
"""Perform the submission."""
165
189
prerequisite_branch = self._get_prerequisite_branch()
175
199
review_types.append(review_type)
176
200
reviewers.append(reviewer.self_link)
177
201
initial_comment = self.get_comment(prerequisite_branch)
179
mp = self.source_branch.lp.createMergeProposal(
180
target_branch=self.target_branch.lp,
181
prerequisite_branch=prereq,
182
initial_comment=initial_comment,
183
commit_message=self.commit_message, reviewers=reviewers,
184
review_types=review_types)
185
except restful_errors.HTTPError, e:
187
for line in e.content.splitlines():
188
if line.startswith('Traceback (most recent call last):'):
190
error_lines.append(line)
191
raise Exception(''.join(error_lines))
193
webbrowser.open(canonical_url(mp))
202
mp = self.call_webservice(
203
self.source_branch.lp.createMergeProposal,
204
target_branch=self.target_branch.lp,
205
prerequisite_branch=prereq,
206
initial_comment=initial_comment,
207
commit_message=self.commit_message, reviewers=reviewers,
208
review_types=review_types)
210
self.call_webservice(mp.setStatus, status='Approved')
211
webbrowser.open(canonical_url(mp))
196
214
def modified_files(old_tree, new_tree):