335
335
__doc__ = """Find the proposal to merge this revision.
337
337
Finds the merge proposal(s) that discussed landing the specified revision.
338
This works only if the selected branch was the merge proposal target, and
339
if the merged_revno is recorded for the merge proposal. The proposal(s)
340
are opened in a web browser.
338
This works only if the if the merged_revno was recorded for the merge
339
proposal. The proposal(s) are opened in a web browser.
342
Any revision involved in the merge may be specified-- the revision in
343
which the merge was performed, or one of the revisions that was merged.
341
Only the revision specified is searched for. To find the mainline
342
revision that merged it into mainline, use the "mainline" revision spec.
345
344
So, to find the merge proposal that reviewed line 1 of README::
347
bzr lp-find-proposal -r annotate:README:1
346
bzr lp-find-proposal -r mainline:annotate:README:1
350
349
takes_options = ['revision']
357
356
pb = ui.ui_factory.nested_progress_bar()
360
revno = self._find_merged_revno(revision, b, pb)
361
merged = self._find_proposals(revno, b, pb)
360
revision_id = b.last_revision()
362
revision_id = revision[0].as_revision_id(b)
363
merged = self._find_proposals(revision_id, pb)
362
364
if len(merged) == 0:
363
365
raise BzrCommandError(gettext('No review found.'))
364
366
trace.note(gettext('%d proposals(s) found.') % len(merged))
371
def _find_merged_revno(self, revision, b, pb):
374
pb.update(gettext('Finding revision-id'))
375
revision_id = revision[0].as_revision_id(b)
376
# a revno spec is necessarily on the mainline.
377
if self._is_revno_spec(revision[0]):
378
merging_revision = revision_id
380
graph = b.repository.get_graph()
381
pb.update(gettext('Finding merge'))
382
merging_revision = graph.find_lefthand_merger(
383
revision_id, b.last_revision())
384
if merging_revision is None:
385
raise InvalidRevisionSpec(revision[0].user_spec, b)
386
pb.update(gettext('Finding revno'))
387
return b.revision_id_to_revno(merging_revision)
389
def _find_proposals(self, revno, b, pb):
373
def _find_proposals(self, revision_id, pb):
390
374
from bzrlib.plugins.launchpad import (lp_api, lp_registration)
391
launchpad = lp_api.login(lp_registration.LaunchpadService())
392
pb.update(gettext('Finding Launchpad branch'))
393
lpb = lp_api.LaunchpadBranch.from_bzr(launchpad, b,
394
create_missing=False)
375
launchpad = lp_api.login(
376
lp_registration.LaunchpadService(), version='devel')
395
377
pb.update(gettext('Finding proposals'))
396
return list(lpb.lp.getMergeProposals(status=['Merged'],
397
merged_revnos=[revno]))
401
def _is_revno_spec(spec):
378
return list(launchpad.branches.getMergeProposals(
379
merged_revision=revision_id))