/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/launchpad/hoster.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-06-01 21:57:00 UTC
  • mfrom: (7490.39.3 move-launchpad)
  • Revision ID: breezy.the.bot@gmail.com-20200601215700-joxuzo6w172gq74v
Move launchpad hoster support to the launchpad plugin.

Merged from https://code.launchpad.net/~jelmer/brz/move-launchpad/+merge/384931

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
                self._mp.source_git_repository.git_identity,
118
118
                ref=self._mp.source_git_path.encode('utf-8'))
119
119
 
120
 
    def get_source_revision(self):
121
 
        if self._mp.source_branch:
122
 
            last_scanned_id = self._mp.source_branch.last_scanned_id
123
 
            if last_scanned_id:
124
 
                return last_scanned_id.encode('utf-8')
125
 
            else:
126
 
                return None
127
 
        else:
128
 
            from breezy.git.mapping import default_mapping
129
 
            git_repo = self._mp.source_git_repository
130
 
            git_ref = git_repo.getRefByPath(path=self._mp.source_git_path)
131
 
            sha = git_ref.commit_sha1
132
 
            if sha is None:
133
 
                return None
134
 
            return default_mapping.revision_id_foreign_to_bzr(
135
 
                sha.encode('ascii'))
136
 
 
137
120
    def get_target_branch_url(self):
138
121
        if self._mp.target_branch:
139
122
            return self._mp.target_branch.bzr_identity
204
187
        finally:
205
188
            shutil.rmtree(tmpdir)
206
189
 
207
 
    def post_comment(self, body):
208
 
        self._mp.createComment(content=body)
209
 
 
210
190
 
211
191
class Launchpad(Hoster):
212
192
    """The Launchpad hosting service."""
222
202
 
223
203
    merge_proposal_description_format = 'plain'
224
204
 
225
 
    def __init__(self, service_root):
226
 
        self._api_base_url = service_root
227
 
        self._launchpad = None
228
 
 
229
 
    @property
230
 
    def name(self):
231
 
        if self._api_base_url == uris.LPNET_SERVICE_ROOT:
232
 
            return 'Launchpad'
233
 
        return 'Launchpad at %s' % self.base_url
234
 
 
235
 
    @property
236
 
    def launchpad(self):
237
 
        if self._launchpad is None:
238
 
            self._launchpad = lp_api.connect_launchpad(self._api_base_url, version='devel')
239
 
        return self._launchpad
 
205
    def __init__(self, staging=False):
 
206
        self._staging = staging
 
207
        if staging:
 
208
            lp_base_url = uris.STAGING_SERVICE_ROOT
 
209
        else:
 
210
            lp_base_url = uris.LPNET_SERVICE_ROOT
 
211
        self.launchpad = lp_api.connect_launchpad(lp_base_url, version='devel')
240
212
 
241
213
    @property
242
214
    def base_url(self):
243
 
        return lp_api.uris.web_root_for_service_root(self._api_base_url)
 
215
        return lp_api.uris.web_root_for_service_root(
 
216
            str(self.launchpad._root_uri))
244
217
 
245
218
    def __repr__(self):
246
 
        return "Launchpad(service_root=%s)" % self._api_base_url
247
 
 
248
 
    def get_current_user(self):
249
 
        return self.launchpad.me.name
250
 
 
251
 
    def get_user_url(self, username):
252
 
        return self.launchpad.people[username].web_link
 
219
        return "Launchpad(staging=%s)" % self._staging
253
220
 
254
221
    def hosts(self, branch):
255
222
        # TODO(jelmer): staging vs non-staging?
258
225
    @classmethod
259
226
    def probe_from_url(cls, url, possible_transports=None):
260
227
        if plausible_launchpad_url(url):
261
 
            return Launchpad(uris.LPNET_SERVICE_ROOT)
 
228
            return Launchpad()
262
229
        raise UnsupportedHoster(url)
263
230
 
264
231
    def _get_lp_git_ref_from_branch(self, branch):
469
436
 
470
437
    @classmethod
471
438
    def iter_instances(cls):
472
 
        credential_store = lp_api.get_credential_store()
473
 
        for service_root in set(uris.service_roots.values()):
474
 
            auth_engine = lp_api.get_auth_engine(service_root)
475
 
            creds = credential_store.load(auth_engine.unique_consumer_id)
476
 
            if creds is not None:
477
 
                yield cls(service_root)
 
439
        yield cls()
478
440
 
479
 
    def iter_my_proposals(self, status='open', author=None):
 
441
    def iter_my_proposals(self, status='open'):
480
442
        statuses = status_to_lp_mp_statuses(status)
481
 
        if author is None:
482
 
            author_obj = self.launchpad.me
483
 
        else:
484
 
            author_obj = self._getPerson(author)
485
 
        for mp in author_obj.getMergeProposals(status=statuses):
 
443
        for mp in self.launchpad.me.getMergeProposals(status=statuses):
486
444
            yield LaunchpadMergeProposal(mp)
487
445
 
488
 
    def iter_my_forks(self, owner=None):
 
446
    def iter_my_forks(self):
489
447
        # Launchpad doesn't really have the concept of "forks"
490
448
        return iter([])
491
449
 
492
 
    def _getPerson(self, person):
493
 
        if '@' in name:
494
 
            return self.launchpad.people.getByEmail(email=name)
495
 
        else:
496
 
            return self.launchpad.people[name]
497
 
 
498
450
    def get_proposal_by_url(self, url):
499
451
        # Launchpad doesn't have a way to find a merge proposal by URL.
500
452
        (scheme, user, password, host, port, path) = urlutils.parse_url(
578
530
    def check_proposal(self):
579
531
        """Check that the submission is sensible."""
580
532
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
581
 
            raise errors.CommandError(
 
533
            raise errors.BzrCommandError(
582
534
                'Source and target branches must be different.')
583
535
        for mp in self.source_branch_lp.landing_targets:
584
536
            if mp.queue_status in ('Merged', 'Rejected'):
612
564
        else:
613
565
            reviewer_objs = []
614
566
            for reviewer in reviewers:
615
 
                reviewer_objs.append(self.lp_host._getPerson(reviewer))
 
567
                if '@' in reviewer:
 
568
                    reviewer_obj = self.launchpad.people.getByEmail(email=reviewer)
 
569
                else:
 
570
                    reviewer_obj = self.launchpad.people[reviewer]
 
571
                reviewer_objs.append(reviewer_obj)
616
572
        try:
617
573
            mp = _call_webservice(
618
574
                self.source_branch_lp.createMergeProposal,
707
663
    def check_proposal(self):
708
664
        """Check that the submission is sensible."""
709
665
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
710
 
            raise errors.CommandError(
 
666
            raise errors.BzrCommandError(
711
667
                'Source and target branches must be different.')
712
668
        for mp in self.source_branch_lp.landing_targets:
713
669
            if mp.queue_status in ('Merged', 'Rejected'):
727
683
                revid=self.source_branch.last_revision())
728
684
 
729
685
    def create_proposal(self, description, reviewers=None, labels=None,
730
 
                        prerequisite_branch=None, commit_message=None,
731
 
                        work_in_progress=False, allow_collaboration=False):
 
686
                        prerequisite_branch=None, commit_message=None):
732
687
        """Perform the submission."""
733
688
        if labels:
734
689
            raise LabelsUnsupported(self)
746
701
                merge_prerequisite=prereq_branch_lp,
747
702
                initial_comment=description.strip(),
748
703
                commit_message=commit_message,
749
 
                needs_review=(not work_in_progress),
 
704
                needs_review=True,
750
705
                reviewers=[self.launchpad.people[reviewer].self_link
751
706
                           for reviewer in reviewers],
752
707
                review_types=[None for reviewer in reviewers])