335
334
__doc__ = """Find the proposal to merge this revision.
337
336
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.
337
This works only if the if the merged_revno was recorded for the merge
338
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.
340
Only the revision specified is searched for. To find the mainline
341
revision that merged it into mainline, use the "mainline" revision spec.
345
343
So, to find the merge proposal that reviewed line 1 of README::
347
bzr lp-find-proposal -r annotate:README:1
345
bzr lp-find-proposal -r mainline:annotate:README:1
350
348
takes_options = ['revision']
357
355
pb = ui.ui_factory.nested_progress_bar()
360
revno = self._find_merged_revno(revision, b, pb)
361
merged = self._find_proposals(revno, b, pb)
359
revision_id = b.last_revision()
361
revision_id = revision[0].as_revision_id(b)
362
merged = self._find_proposals(revision_id, pb)
362
363
if len(merged) == 0:
363
364
raise BzrCommandError(gettext('No review found.'))
364
365
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):
372
def _find_proposals(self, revision_id, pb):
390
373
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)
374
# "devel" because branches.getMergeProposals is not part of 1.0 API.
375
launchpad = lp_api.login(lp_registration.LaunchpadService(),
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))