/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-11 12:46:45 UTC
  • mfrom: (7511.1.1 actions-no-fork)
  • Revision ID: breezy.the.bot@gmail.com-20200611124645-4lx66gps99i0hmzh
Avoid using fork when running the testsuite in github actions.

Merged from https://code.launchpad.net/~jelmer/brz/actions-no-fork/+merge/385565

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
441
    def iter_my_proposals(self, status='open'):
480
442
        statuses = status_to_lp_mp_statuses(status)
568
530
    def check_proposal(self):
569
531
        """Check that the submission is sensible."""
570
532
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
571
 
            raise errors.CommandError(
 
533
            raise errors.BzrCommandError(
572
534
                'Source and target branches must be different.')
573
535
        for mp in self.source_branch_lp.landing_targets:
574
536
            if mp.queue_status in ('Merged', 'Rejected'):
701
663
    def check_proposal(self):
702
664
        """Check that the submission is sensible."""
703
665
        if self.source_branch_lp.self_link == self.target_branch_lp.self_link:
704
 
            raise errors.CommandError(
 
666
            raise errors.BzrCommandError(
705
667
                'Source and target branches must be different.')
706
668
        for mp in self.source_branch_lp.landing_targets:
707
669
            if mp.queue_status in ('Merged', 'Rejected'):