/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: Gustav Hartvigsson
  • Date: 2021-01-11 20:19:38 UTC
  • mfrom: (7526.3.2 work)
  • Revision ID: gustav.hartvigsson@gmail.com-20210111201938-omr9wjz3qdgyxe8k
MergedĀ lp:brz

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
 
120
137
    def get_target_branch_url(self):
121
138
        if self._mp.target_branch:
122
139
            return self._mp.target_branch.bzr_identity
187
204
        finally:
188
205
            shutil.rmtree(tmpdir)
189
206
 
 
207
    def post_comment(self, body):
 
208
        self._mp.createComment(content=body)
 
209
 
190
210
 
191
211
class Launchpad(Hoster):
192
212
    """The Launchpad hosting service."""
202
222
 
203
223
    merge_proposal_description_format = 'plain'
204
224
 
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')
 
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
212
240
 
213
241
    @property
214
242
    def base_url(self):
215
 
        return lp_api.uris.web_root_for_service_root(
216
 
            str(self.launchpad._root_uri))
 
243
        return lp_api.uris.web_root_for_service_root(self._api_base_url)
217
244
 
218
245
    def __repr__(self):
219
 
        return "Launchpad(staging=%s)" % self._staging
 
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
220
253
 
221
254
    def hosts(self, branch):
222
255
        # TODO(jelmer): staging vs non-staging?
225
258
    @classmethod
226
259
    def probe_from_url(cls, url, possible_transports=None):
227
260
        if plausible_launchpad_url(url):
228
 
            return Launchpad()
 
261
            return Launchpad(uris.LPNET_SERVICE_ROOT)
229
262
        raise UnsupportedHoster(url)
230
263
 
231
264
    def _get_lp_git_ref_from_branch(self, branch):
436
469
 
437
470
    @classmethod
438
471
    def iter_instances(cls):
439
 
        yield 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)
440
478
 
441
 
    def iter_my_proposals(self, status='open'):
 
479
    def iter_my_proposals(self, status='open', author=None):
442
480
        statuses = status_to_lp_mp_statuses(status)
443
 
        for mp in self.launchpad.me.getMergeProposals(status=statuses):
 
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):
444
486
            yield LaunchpadMergeProposal(mp)
445
487
 
446
 
    def iter_my_forks(self):
 
488
    def iter_my_forks(self, owner=None):
447
489
        # Launchpad doesn't really have the concept of "forks"
448
490
        return iter([])
449
491
 
 
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
 
450
498
    def get_proposal_by_url(self, url):
451
499
        # Launchpad doesn't have a way to find a merge proposal by URL.
452
500
        (scheme, user, password, host, port, path) = urlutils.parse_url(
530
578
    def check_proposal(self):
531
579
        """Check that the submission is sensible."""
532
580
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
533
 
            raise errors.BzrCommandError(
 
581
            raise errors.CommandError(
534
582
                'Source and target branches must be different.')
535
583
        for mp in self.source_branch_lp.landing_targets:
536
584
            if mp.queue_status in ('Merged', 'Rejected'):
564
612
        else:
565
613
            reviewer_objs = []
566
614
            for reviewer in reviewers:
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)
 
615
                reviewer_objs.append(self.lp_host._getPerson(reviewer))
572
616
        try:
573
617
            mp = _call_webservice(
574
618
                self.source_branch_lp.createMergeProposal,
663
707
    def check_proposal(self):
664
708
        """Check that the submission is sensible."""
665
709
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
666
 
            raise errors.BzrCommandError(
 
710
            raise errors.CommandError(
667
711
                'Source and target branches must be different.')
668
712
        for mp in self.source_branch_lp.landing_targets:
669
713
            if mp.queue_status in ('Merged', 'Rejected'):
683
727
                revid=self.source_branch.last_revision())
684
728
 
685
729
    def create_proposal(self, description, reviewers=None, labels=None,
686
 
                        prerequisite_branch=None, commit_message=None):
 
730
                        prerequisite_branch=None, commit_message=None,
 
731
                        work_in_progress=False, allow_collaboration=False):
687
732
        """Perform the submission."""
688
733
        if labels:
689
734
            raise LabelsUnsupported(self)
701
746
                merge_prerequisite=prereq_branch_lp,
702
747
                initial_comment=description.strip(),
703
748
                commit_message=commit_message,
704
 
                needs_review=True,
 
749
                needs_review=(not work_in_progress),
705
750
                reviewers=[self.launchpad.people[reviewer].self_link
706
751
                           for reviewer in reviewers],
707
752
                review_types=[None for reviewer in reviewers])