/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: 2018-01-24 07:51:44 UTC
  • mfrom: (7251 work)
  • mto: This revision was merged to the branch mainline in revision 7252.
  • Revision ID: jelmer@jelmer.uk-20180124075144-byhp1hgdjt2jurfo
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
134
133
    def is_merged(self):
135
134
        return (self._mp.queue_status == 'Merged')
136
135
 
 
136
    def get_description(self):
 
137
        return self._mp.description
 
138
 
 
139
    def set_description(self, description):
 
140
        self._mp.description = description
 
141
 
137
142
 
138
143
class Launchpad(Hoster):
139
144
    """The Launchpad hosting service."""
143
148
    # https://bugs.launchpad.net/launchpad/+bug/397676
144
149
    supports_merge_proposal_labels = False
145
150
 
146
 
    def __init__(self, staging=False):
 
151
    def __init__(self):
147
152
        self._staging = staging
148
153
        if staging:
149
 
            lp_instance = 'staging'
 
154
            lp_base_url = lp_api.STAGING_SERVICE_ROOT
150
155
        else:
151
 
            lp_instance = 'production'
152
 
        self.launchpad = connect_launchpad(lp_instance)
 
156
            lp_base_url = None
 
157
        self.launchpad = lp_api.connect_launchpad(lp_base_url)
153
158
 
154
159
    def __repr__(self):
155
160
        return "Launchpad(staging=%s)" % self._staging
188
193
    def _get_derived_git_path(self, base_path, owner, project):
189
194
        base_repo = self.launchpad.git_repositories.getByPath(path=base_path)
190
195
        if project is None:
191
 
            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:])
192
199
        # TODO(jelmer): Surely there is a better way of creating one of these
193
200
        # URLs?
194
201
        return "~%s/%s" % (owner, project)
317
324
        elif base_vcs == 'git':
318
325
            to_path = self._get_derived_git_path(
319
326
                base_path.strip('/'), owner, project)
320
 
            return _mod_branch.Branch.open(
321
 
                "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)
322
331
        else:
323
332
            raise AssertionError('not a valid Launchpad URL')
324
333
 
337
346
                yield LaunchpadMergeProposal(mp)
338
347
        elif base_vcs == 'git':
339
348
            (source_repo_lp, source_branch_lp) = (
340
 
                self.lp_host._get_lp_git_ref_from_branch(source_branch))
 
349
                self._get_lp_git_ref_from_branch(source_branch))
341
350
            (target_repo_lp, target_branch_lp) = (
342
 
                self.lp_host._get_lp_git_ref_from_branch(target_branch))
 
351
                self._get_lp_git_ref_from_branch(target_branch))
343
352
            for mp in target_branch_lp.getMergeProposals(status=statuses):
344
353
                if (target_branch_lp.path != mp.target_git_path or
345
354
                        target_repo_lp != mp.target_git_repository or
372
381
            yield LaunchpadMergeProposal(mp)
373
382
 
374
383
 
375
 
def connect_launchpad(lp_instance='production'):
376
 
    service = lp_registration.LaunchpadService(lp_instance=lp_instance)
377
 
    return lp_api.login(service, version='devel')
378
 
 
379
 
 
380
384
class LaunchpadBazaarMergeProposalBuilder(MergeProposalBuilder):
381
385
 
382
386
    def __init__(self, lp_host, source_branch, target_branch, message=None,
610
614
                self.source_branch_lp.createMergeProposal,
611
615
                merge_target=self.target_branch_lp,
612
616
                merge_prerequisite=prereq_branch_lp,
613
 
                initial_comment=description.strip().encode('utf-8'),
 
617
                initial_comment=description.strip(),
614
618
                commit_message=self.commit_message,
615
619
                needs_review=True,
616
620
                reviewers=[self.launchpad.people[reviewer].self_link