~dylanmccall/bzr/bug-1107464

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2012-07-23 19:46:45 UTC
  • mfrom: (6538.2.5 find-proposal-revid)
  • Revision ID: pqm@pqm.ubuntu.com-20120723194645-5a57w8fw122aei34
(abentley) lp-find-proposal now ignores branch. (Aaron Bentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    )
29
29
from bzrlib.errors import (
30
30
    BzrCommandError,
31
 
    InvalidRevisionSpec,
32
31
    InvalidURL,
33
32
    NoPublicBranch,
34
33
    NotBranchError,
335
334
    __doc__ = """Find the proposal to merge this revision.
336
335
 
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.
341
339
 
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.
344
342
 
345
343
    So, to find the merge proposal that reviewed line 1 of README::
346
344
 
347
 
      bzr lp-find-proposal -r annotate:README:1
 
345
      bzr lp-find-proposal -r mainline:annotate:README:1
348
346
    """
349
347
 
350
348
    takes_options = ['revision']
357
355
        pb = ui.ui_factory.nested_progress_bar()
358
356
        b.lock_read()
359
357
        try:
360
 
            revno = self._find_merged_revno(revision, b, pb)
361
 
            merged = self._find_proposals(revno, b, pb)
 
358
            if revision is None:
 
359
                revision_id = b.last_revision()
 
360
            else:
 
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))
368
369
            b.unlock()
369
370
            pb.finished()
370
371
 
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):
 
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(),
 
376
                                 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))