~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/cmds.py

  • Committer: Aaron Bentley
  • Date: 2012-07-19 22:15:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6541.
  • Revision ID: aaron@aaronbentley.com-20120719221557-y2y1vqt9p92ya7uc
Look up merge proposals by exact revision-id.

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
    __doc__ = """Find the proposal to merge this revision.
336
336
 
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.
341
340
 
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.
344
343
 
345
344
    So, to find the merge proposal that reviewed line 1 of README::
346
345
 
347
 
      bzr lp-find-proposal -r annotate:README:1
 
346
      bzr lp-find-proposal -r mainline:annotate:README:1
348
347
    """
349
348
 
350
349
    takes_options = ['revision']
357
356
        pb = ui.ui_factory.nested_progress_bar()
358
357
        b.lock_read()
359
358
        try:
360
 
            revno = self._find_merged_revno(revision, b, pb)
361
 
            merged = self._find_proposals(revno, b, pb)
 
359
            if revision is None:
 
360
                revision_id = b.last_revision()
 
361
            else:
 
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))
368
370
            b.unlock()
369
371
            pb.finished()
370
372
 
371
 
    def _find_merged_revno(self, revision, b, pb):
372
 
        if revision is None:
373
 
            return b.revno()
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
379
 
        else:
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)
388
 
 
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]))
398
 
 
399
 
 
400
 
    @staticmethod
401
 
    def _is_revno_spec(spec):
402
 
        try:
403
 
            int(spec.user_spec)
404
 
        except ValueError:
405
 
            return False
406
 
        else:
407
 
            return True
408
 
 
409
 
 
410
 
 
 
378
        return list(launchpad.branches.getMergeProposals(
 
379
            merged_revision=revision_id))