170
# XXX: cmd_launchpad_mirror is untested
171
class cmd_launchpad_mirror(Command):
172
__doc__ = """Ask Launchpad to mirror a branch now."""
174
aliases = ['lp-mirror']
175
takes_args = ['location?']
177
def run(self, location='.'):
179
from .lp_registration import LaunchpadService
180
branch, _ = _mod_branch.Branch.open_containing(location)
181
service = LaunchpadService()
182
launchpad = lp_api.login(service)
183
lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch,
184
create_missing=False)
185
lp_branch.lp.requestMirror()
188
class cmd_lp_propose_merge(Command):
189
__doc__ = """Propose merging a branch on Launchpad.
191
This will open your usual editor to provide the initial comment. When it
192
has created the proposal, it will open it in your default web browser.
194
The branch will be proposed to merge into SUBMIT_BRANCH. If SUBMIT_BRANCH
195
is not supplied, the remembered submit branch will be used. If no submit
196
branch is remembered, the development focus will be used.
198
By default, the SUBMIT_BRANCH's review team will be requested to review
199
the merge proposal. This can be overriden by specifying --review (-R).
200
The parameter the launchpad account name of the desired reviewer. This
201
may optionally be followed by '=' and the review type. For example:
203
brz lp-propose-merge --review jrandom --review review-team=qa
205
This will propose a merge, request "jrandom" to perform a review of
206
unspecified type, and request "review-team" to perform a "qa" review.
209
takes_options = [Option('staging',
210
help='Propose the merge on staging.'),
211
Option('message', short_name='m', type=text_type,
212
help='Commit message.'),
214
help=('Mark the proposal as approved immediately, '
215
'setting the approved revision to tip.')),
216
Option('fixes', 'The bug this proposal fixes.', str),
217
ListOption('review', short_name='R', type=text_type,
218
help='Requested reviewer and optional type.')]
220
takes_args = ['submit_branch?']
222
aliases = ['lp-submit', 'lp-propose']
224
def run(self, submit_branch=None, review=None, staging=False,
225
message=None, approve=False, fixes=None):
226
from . import lp_propose
227
tree, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
233
for review in review:
235
reviews.append(review.split('=', 2))
237
reviews.append((review, ''))
238
if submit_branch is None:
239
submit_branch = branch.get_submit_branch()
240
if submit_branch is None:
243
target = _mod_branch.Branch.open(submit_branch)
244
proposer = lp_propose.Proposer(tree, branch, target, message,
245
reviews, staging, approve=approve,
247
proposer.check_proposal()
248
proposer.create_proposal()
251
165
class cmd_lp_find_proposal(Command):
253
167
__doc__ = """Find the proposal to merge this revision.
278
192
revision_id = revision[0].as_revision_id(b)
279
193
merged = self._find_proposals(revision_id, pb)
280
194
if len(merged) == 0:
281
raise BzrCommandError(gettext('No review found.'))
195
raise CommandError(gettext('No review found.'))
282
196
trace.note(gettext('%d proposals(s) found.') % len(merged))
283
197
for mp in merged:
284
198
webbrowser.open(lp_api.canonical_url(mp))
286
200
def _find_proposals(self, revision_id, pb):
287
from . import (lp_api, lp_registration)
201
from launchpadlib import uris
288
203
# "devel" because branches.getMergeProposals is not part of 1.0 API.
289
launchpad = lp_api.login(lp_registration.LaunchpadService(),
204
lp_base_url = uris.LPNET_SERVICE_ROOT
205
launchpad = lp_api.connect_launchpad(lp_base_url, version='devel')
291
206
pb.update(gettext('Finding proposals'))
292
207
return list(launchpad.branches.getMergeProposals(
293
merged_revision=revision_id))
208
merged_revision=revision_id.decode('utf-8')))