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
75
71
lp_instance = 'staging'
73
lp_instance = 'production'
78
74
service = lp_registration.LaunchpadService(lp_instance=lp_instance)
79
75
self.launchpad = lp_api.login(service)
80
76
self.source_branch = lp_api.LaunchpadBranch.from_bzr(
85
81
self.target_branch = lp_api.LaunchpadBranch.from_bzr(
86
82
self.launchpad, target_branch)
87
83
self.commit_message = message
88
# XXX: this is where bug lp:583638 could be tackled.
90
85
target_reviewer = self.target_branch.lp.reviewer
91
86
if target_reviewer is None:
95
90
self.reviews = [(self.launchpad.people[reviewer], review_type)
96
91
for reviewer, review_type in
98
self.approve = approve
100
94
def get_comment(self, prerequisite_branch):
101
95
"""Determine the initial comment for the merge proposal."""
166
160
'prerequisite_branch': prerequisite_branch})
167
161
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))
187
163
def create_proposal(self):
188
164
"""Perform the submission."""
189
165
prerequisite_branch = self._get_prerequisite_branch()
199
175
review_types.append(review_type)
200
176
reviewers.append(reviewer.self_link)
201
177
initial_comment = self.get_comment(prerequisite_branch)
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))
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))
214
196
def modified_files(old_tree, new_tree):