/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/propose/launchpad.py

  • Committer: Jelmer Vernooij
  • Date: 2019-01-24 02:04:29 UTC
  • mfrom: (7245 work)
  • mto: This revision was merged to the branch mainline in revision 7247.
  • Revision ID: jelmer@jelmer.uk-20190124020429-3iu7zy9dz3zdxaoe
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
lazy_import(globals(), """
43
43
from breezy.plugins.launchpad import (
44
44
    lp_api,
45
 
    lp_registration,
46
45
    )
47
46
""")
48
47
from ...transport import get_transport
149
148
    # https://bugs.launchpad.net/launchpad/+bug/397676
150
149
    supports_merge_proposal_labels = False
151
150
 
152
 
    def __init__(self, staging=False):
 
151
    def __init__(self):
153
152
        self._staging = staging
154
153
        if staging:
155
 
            lp_instance = 'staging'
 
154
            lp_base_url = lp_api.STAGING_SERVICE_ROOT
156
155
        else:
157
 
            lp_instance = 'production'
158
 
        self.launchpad = connect_launchpad(lp_instance)
 
156
            lp_base_url = None
 
157
        self.launchpad = lp_api.connect_launchpad(lp_base_url)
159
158
 
160
159
    def __repr__(self):
161
160
        return "Launchpad(staging=%s)" % self._staging
194
193
    def _get_derived_git_path(self, base_path, owner, project):
195
194
        base_repo = self.launchpad.git_repositories.getByPath(path=base_path)
196
195
        if project is None:
197
 
            project = '/'.join(base_repo.unique_name.split('/')[1:])
 
196
            project = urlutils.parse_url(base_repo.git_ssh_url)[-1].strip('/')
 
197
        if project.startswith('~'):
 
198
            project = '/'.join(base_path.split('/')[1:])
198
199
        # TODO(jelmer): Surely there is a better way of creating one of these
199
200
        # URLs?
200
201
        return "~%s/%s" % (owner, project)
323
324
        elif base_vcs == 'git':
324
325
            to_path = self._get_derived_git_path(
325
326
                base_path.strip('/'), owner, project)
326
 
            return _mod_branch.Branch.open(
327
 
                "git+ssh://git.launchpad.net/" + to_path, name)
 
327
            to_url = urlutils.join_segment_parameters(
 
328
                "git+ssh://git.launchpad.net/" + to_path,
 
329
                {'branch': name})
 
330
            return _mod_branch.Branch.open(to_url)
328
331
        else:
329
332
            raise AssertionError('not a valid Launchpad URL')
330
333
 
343
346
                yield LaunchpadMergeProposal(mp)
344
347
        elif base_vcs == 'git':
345
348
            (source_repo_lp, source_branch_lp) = (
346
 
                self.lp_host._get_lp_git_ref_from_branch(source_branch))
 
349
                self._get_lp_git_ref_from_branch(source_branch))
347
350
            (target_repo_lp, target_branch_lp) = (
348
 
                self.lp_host._get_lp_git_ref_from_branch(target_branch))
 
351
                self._get_lp_git_ref_from_branch(target_branch))
349
352
            for mp in target_branch_lp.getMergeProposals(status=statuses):
350
353
                if (target_branch_lp.path != mp.target_git_path or
351
354
                        target_repo_lp != mp.target_git_repository or
378
381
            yield LaunchpadMergeProposal(mp)
379
382
 
380
383
 
381
 
def connect_launchpad(lp_instance='production'):
382
 
    service = lp_registration.LaunchpadService(lp_instance=lp_instance)
383
 
    return lp_api.login(service, version='devel')
384
 
 
385
 
 
386
384
class LaunchpadBazaarMergeProposalBuilder(MergeProposalBuilder):
387
385
 
388
386
    def __init__(self, lp_host, source_branch, target_branch, message=None,
616
614
                self.source_branch_lp.createMergeProposal,
617
615
                merge_target=self.target_branch_lp,
618
616
                merge_prerequisite=prereq_branch_lp,
619
 
                initial_comment=description.strip().encode('utf-8'),
 
617
                initial_comment=description.strip(),
620
618
                commit_message=self.commit_message,
621
619
                needs_review=True,
622
620
                reviewers=[self.launchpad.people[reviewer].self_link