/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/gitlabs.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-03-02 21:51:19 UTC
  • mfrom: (7268.12.3 probe-url)
  • Revision ID: breezy.the.bot@gmail.com-20190302215119-7lhcqje0t7xvkbfj
Split out a 'probe_from_url' method on Hoster.

Merged from https://code.launchpad.net/~jelmer/brz/probe-url/+merge/362951

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
            raise GitLabLoginMissing()
111
111
 
112
112
 
113
 
def parse_gitlab_url(branch):
114
 
    url = urlutils.split_segment_parameters(branch.user_url)[0]
 
113
def parse_gitlab_url(url):
115
114
    (scheme, user, password, host, port, path) = urlutils.parse_url(
116
115
        url)
117
116
    if scheme not in ('git+ssh', 'https', 'http'):
118
 
        raise NotGitLabUrl(branch.user_url)
 
117
        raise NotGitLabUrl(url)
119
118
    if not host:
120
 
        raise NotGitLabUrl(branch.user_url)
 
119
        raise NotGitLabUrl(url)
121
120
    path = path.strip('/')
122
121
    if path.endswith('.git'):
123
122
        path = path[:-4]
 
123
    return host, path
 
124
 
 
125
 
 
126
def parse_gitlab_branch_url(branch):
 
127
    url = urlutils.split_segment_parameters(branch.user_url)[0]
 
128
    host, path = parse_gitlab_url(url)
124
129
    return host, path, branch.name
125
130
 
126
131
 
183
188
        self.gl = gl
184
189
 
185
190
    def get_push_url(self, branch):
186
 
        (host, project_name, branch_name) = parse_gitlab_url(branch)
 
191
        (host, project_name, branch_name) = parse_gitlab_branch_url(branch)
187
192
        project = self.gl.projects.get(project_name)
188
193
        return gitlab_url_to_bzr_url(
189
194
            project.ssh_url_to_repo, branch_name)
192
197
                        owner=None, revision_id=None, overwrite=False,
193
198
                        allow_lossy=True):
194
199
        import gitlab
195
 
        (host, base_project, base_branch_name) = parse_gitlab_url(base_branch)
 
200
        (host, base_project, base_branch_name) = parse_gitlab_branch_url(base_branch)
196
201
        self.gl.auth()
197
202
        try:
198
203
            base_project = self.gl.projects.get(base_project)
230
235
 
231
236
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
232
237
        import gitlab
233
 
        (host, base_project, base_branch_name) = parse_gitlab_url(base_branch)
 
238
        (host, base_project, base_branch_name) = parse_gitlab_branch_url(base_branch)
234
239
        self.gl.auth()
235
240
        try:
236
241
            base_project = self.gl.projects.get(base_project)
258
263
    def iter_proposals(self, source_branch, target_branch, status):
259
264
        import gitlab
260
265
        (source_host, source_project_name, source_branch_name) = (
261
 
            parse_gitlab_url(source_branch))
 
266
            parse_gitlab_branch_url(source_branch))
262
267
        (target_host, target_project_name, target_branch_name) = (
263
 
            parse_gitlab_url(target_branch))
 
268
            parse_gitlab_branch_url(target_branch))
264
269
        if source_host != target_host:
265
270
            raise DifferentGitLabInstances(source_host, target_host)
266
271
        self.gl.auth()
281
286
 
282
287
    def hosts(self, branch):
283
288
        try:
284
 
            (host, project, branch_name) = parse_gitlab_url(branch)
 
289
            (host, project, branch_name) = parse_gitlab_branch_url(branch)
285
290
        except NotGitLabUrl:
286
291
            return False
287
292
        return (self.gl.url == ('https://%s' % host))
288
293
 
289
294
    @classmethod
290
 
    def probe(cls, branch):
 
295
    def probe_from_url(cls, url):
291
296
        try:
292
 
            (host, project, branch_name) = parse_gitlab_url(branch)
 
297
            (host, project) = parse_gitlab_url(url)
293
298
        except NotGitLabUrl:
294
 
            raise UnsupportedHoster(branch)
 
299
            raise UnsupportedHoster(url)
295
300
        import gitlab
296
301
        import requests.exceptions
297
302
        try:
299
304
            gl.auth()
300
305
        except requests.exceptions.SSLError:
301
306
            # Well, I guess it could be..
302
 
            raise UnsupportedHoster(branch)
 
307
            raise UnsupportedHoster(url)
303
308
        except gitlab.GitlabGetError:
304
 
            raise UnsupportedHoster(branch)
 
309
            raise UnsupportedHoster(url)
305
310
        except gitlab.GitlabHttpError as e:
306
311
            if e.response_code in (404, 405, 503):
307
 
                raise UnsupportedHoster(branch)
 
312
                raise UnsupportedHoster(url)
308
313
            else:
309
314
                raise
310
315
        return cls(gl)
332
337
        self.gl = gl
333
338
        self.source_branch = source_branch
334
339
        (self.source_host, self.source_project_name, self.source_branch_name) = (
335
 
            parse_gitlab_url(source_branch))
 
340
            parse_gitlab_branch_url(source_branch))
336
341
        self.target_branch = target_branch
337
342
        (self.target_host, self.target_project_name, self.target_branch_name) = (
338
 
            parse_gitlab_url(target_branch))
 
343
            parse_gitlab_branch_url(target_branch))
339
344
        if self.source_host != self.target_host:
340
345
            raise DifferentGitLabInstances(self.source_host, self.target_host)
341
346