/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): Gustav Hartvigsson
  • Date: 2021-01-10 18:46:30 UTC
  • mfrom: (7526.1.1 brz-removed-api-doc)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110184630-dxu0g9dqq020uiw6
Drop documentation for removed API API.

Merged from https://code.launchpad.net/~gustav-hartvigsson/brz/removed-api-doc/+merge/396033

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."""
198
218
 
199
219
    supports_merge_proposal_commit_message = True
200
220
 
 
221
    supports_allow_collaboration = False
 
222
 
201
223
    merge_proposal_description_format = 'plain'
202
224
 
203
 
    def __init__(self, staging=False):
204
 
        self._staging = staging
205
 
        if staging:
206
 
            lp_base_url = uris.STAGING_SERVICE_ROOT
207
 
        else:
208
 
            lp_base_url = uris.LPNET_SERVICE_ROOT
209
 
        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
210
240
 
211
241
    @property
212
242
    def base_url(self):
213
 
        return lp_api.uris.web_root_for_service_root(
214
 
            str(self.launchpad._root_uri))
 
243
        return lp_api.uris.web_root_for_service_root(self._api_base_url)
215
244
 
216
245
    def __repr__(self):
217
 
        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
218
253
 
219
254
    def hosts(self, branch):
220
255
        # TODO(jelmer): staging vs non-staging?
223
258
    @classmethod
224
259
    def probe_from_url(cls, url, possible_transports=None):
225
260
        if plausible_launchpad_url(url):
226
 
            return Launchpad()
 
261
            return Launchpad(uris.LPNET_SERVICE_ROOT)
227
262
        raise UnsupportedHoster(url)
228
263
 
229
264
    def _get_lp_git_ref_from_branch(self, branch):
258
293
        return "~%s/%s" % (owner, project)
259
294
 
260
295
    def _publish_git(self, local_branch, base_path, name, owner, project=None,
261
 
                     revision_id=None, overwrite=False, allow_lossy=True):
 
296
                     revision_id=None, overwrite=False, allow_lossy=True,
 
297
                     tag_selector=None):
262
298
        to_path = self._get_derived_git_path(base_path, owner, project)
263
299
        to_transport = get_transport("git+ssh://git.launchpad.net/" + to_path)
264
300
        try:
270
306
        if dir_to is None:
271
307
            try:
272
308
                br_to = local_branch.create_clone_on_transport(
273
 
                    to_transport, revision_id=revision_id, name=name)
 
309
                    to_transport, revision_id=revision_id, name=name,
 
310
                    tag_selector=tag_selector)
274
311
            except errors.NoRoundtrippingSupport:
275
312
                br_to = local_branch.create_clone_on_transport(
276
313
                    to_transport, revision_id=revision_id, name=name,
277
 
                    lossy=True)
 
314
                    lossy=True, tag_selector=tag_selector)
278
315
        else:
279
316
            try:
280
317
                dir_to = dir_to.push_branch(
281
 
                    local_branch, revision_id, overwrite=overwrite, name=name)
 
318
                    local_branch, revision_id, overwrite=overwrite, name=name,
 
319
                    tag_selector=tag_selector)
282
320
            except errors.NoRoundtrippingSupport:
283
321
                if not allow_lossy:
284
322
                    raise
285
323
                dir_to = dir_to.push_branch(
286
324
                    local_branch, revision_id, overwrite=overwrite, name=name,
287
 
                    lossy=True)
 
325
                    lossy=True, tag_selector=tag_selector)
288
326
            br_to = dir_to.target_branch
289
327
        return br_to, (
290
328
            "https://git.launchpad.net/%s/+ref/%s" % (to_path, name))
310
348
 
311
349
    def _publish_bzr(self, local_branch, base_branch, name, owner,
312
350
                     project=None, revision_id=None, overwrite=False,
313
 
                     allow_lossy=True):
 
351
                     allow_lossy=True, tag_selector=None):
314
352
        to_path = self._get_derived_bzr_path(base_branch, name, owner, project)
315
353
        to_transport = get_transport("lp:" + to_path)
316
354
        try:
321
359
 
322
360
        if dir_to is None:
323
361
            br_to = local_branch.create_clone_on_transport(
324
 
                to_transport, revision_id=revision_id)
 
362
                to_transport, revision_id=revision_id, tag_selector=tag_selector)
325
363
        else:
326
364
            br_to = dir_to.push_branch(
327
 
                local_branch, revision_id, overwrite=overwrite).target_branch
 
365
                local_branch, revision_id, overwrite=overwrite,
 
366
                tag_selector=tag_selector).target_branch
328
367
        return br_to, ("https://code.launchpad.net/" + to_path)
329
368
 
330
369
    def _split_url(self, url):
341
380
 
342
381
    def publish_derived(self, local_branch, base_branch, name, project=None,
343
382
                        owner=None, revision_id=None, overwrite=False,
344
 
                        allow_lossy=True):
 
383
                        allow_lossy=True, tag_selector=None):
345
384
        """Publish a branch to the site, derived from base_branch.
346
385
 
347
386
        :param base_branch: branch to derive the new branch from
360
399
            return self._publish_bzr(
361
400
                local_branch, base_branch, name, project=project, owner=owner,
362
401
                revision_id=revision_id, overwrite=overwrite,
363
 
                allow_lossy=allow_lossy)
 
402
                allow_lossy=allow_lossy, tag_selector=tag_selector)
364
403
        elif base_vcs == 'git':
365
404
            return self._publish_git(
366
405
                local_branch, base_path, name, project=project, owner=owner,
367
406
                revision_id=revision_id, overwrite=overwrite,
368
 
                allow_lossy=allow_lossy)
 
407
                allow_lossy=allow_lossy, tag_selector=tag_selector)
369
408
        else:
370
409
            raise AssertionError('not a valid Launchpad URL')
371
410
 
430
469
 
431
470
    @classmethod
432
471
    def iter_instances(cls):
433
 
        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)
434
478
 
435
 
    def iter_my_proposals(self, status='open'):
 
479
    def iter_my_proposals(self, status='open', author=None):
436
480
        statuses = status_to_lp_mp_statuses(status)
437
 
        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):
438
486
            yield LaunchpadMergeProposal(mp)
439
487
 
440
 
    def iter_my_forks(self):
 
488
    def iter_my_forks(self, owner=None):
441
489
        # Launchpad doesn't really have the concept of "forks"
442
490
        return iter([])
443
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
 
444
498
    def get_proposal_by_url(self, url):
445
499
        # Launchpad doesn't have a way to find a merge proposal by URL.
446
500
        (scheme, user, password, host, port, path) = urlutils.parse_url(
524
578
    def check_proposal(self):
525
579
        """Check that the submission is sensible."""
526
580
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
527
 
            raise errors.BzrCommandError(
 
581
            raise errors.CommandError(
528
582
                'Source and target branches must be different.')
529
583
        for mp in self.source_branch_lp.landing_targets:
530
584
            if mp.queue_status in ('Merged', 'Rejected'):
544
598
 
545
599
    def create_proposal(self, description, reviewers=None, labels=None,
546
600
                        prerequisite_branch=None, commit_message=None,
547
 
                        work_in_progress=False):
 
601
                        work_in_progress=False, allow_collaboration=False):
548
602
        """Perform the submission."""
549
603
        if labels:
550
604
            raise LabelsUnsupported(self)
558
612
        else:
559
613
            reviewer_objs = []
560
614
            for reviewer in reviewers:
561
 
                if '@' in reviewer:
562
 
                    reviewer_obj = self.launchpad.people.getByEmail(email=reviewer)
563
 
                else:
564
 
                    reviewer_obj = self.launchpad.people[reviewer]
565
 
                reviewer_objs.append(reviewer_obj)
 
615
                reviewer_objs.append(self.lp_host._getPerson(reviewer))
566
616
        try:
567
617
            mp = _call_webservice(
568
618
                self.source_branch_lp.createMergeProposal,
657
707
    def check_proposal(self):
658
708
        """Check that the submission is sensible."""
659
709
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
660
 
            raise errors.BzrCommandError(
 
710
            raise errors.CommandError(
661
711
                'Source and target branches must be different.')
662
712
        for mp in self.source_branch_lp.landing_targets:
663
713
            if mp.queue_status in ('Merged', 'Rejected'):
677
727
                revid=self.source_branch.last_revision())
678
728
 
679
729
    def create_proposal(self, description, reviewers=None, labels=None,
680
 
                        prerequisite_branch=None, commit_message=None):
 
730
                        prerequisite_branch=None, commit_message=None,
 
731
                        work_in_progress=False, allow_collaboration=False):
681
732
        """Perform the submission."""
682
733
        if labels:
683
734
            raise LabelsUnsupported(self)
695
746
                merge_prerequisite=prereq_branch_lp,
696
747
                initial_comment=description.strip(),
697
748
                commit_message=commit_message,
698
 
                needs_review=True,
 
749
                needs_review=(not work_in_progress),
699
750
                reviewers=[self.launchpad.people[reviewer].self_link
700
751
                           for reviewer in reviewers],
701
752
                review_types=[None for reviewer in reviewers])