/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: Jelmer Vernooij
  • Date: 2019-07-07 17:22:07 UTC
  • mfrom: (7363 work)
  • mto: This revision was merged to the branch mainline in revision 7378.
  • Revision ID: jelmer@jelmer.uk-20190707172207-nnugeuwvxsxo62wa
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
        yield name, section
124
124
 
125
125
 
 
126
def get_credentials_by_url(url):
 
127
    for name, credentials in iter_tokens():
 
128
        if 'url' not in credentials:
 
129
            continue
 
130
        if credentials['url'].rstrip('/') == url.rstrip('/'):
 
131
            return credentials
 
132
    else:
 
133
        return None
 
134
 
 
135
 
126
136
def parse_gitlab_url(url):
127
137
    (scheme, user, password, host, port, path) = urlutils.parse_url(
128
138
        url)
231
241
        self.check()
232
242
 
233
243
    def _get_project(self, project_name):
234
 
        path = 'projects/:%s' % urlutils.quote(str(project_name), '')
 
244
        path = 'projects/%s' % urlutils.quote(str(project_name), '')
235
245
        response = self._api_request('GET', path)
236
246
        if response.status == 404:
237
247
            raise NoSuchProject(project_name)
240
250
        raise InvalidHttpResponse(path, response.text)
241
251
 
242
252
    def _fork_project(self, project_name):
243
 
        path = 'projects/:%s/fork' % urlutils.quote(str(project_name), '')
 
253
        path = 'projects/%s/fork' % urlutils.quote(str(project_name), '')
244
254
        response = self._api_request('POST', path)
245
255
        if response != 200:
246
256
            raise InvalidHttpResponse(path, response.text)
251
261
 
252
262
    def _list_merge_requests(self, owner=None, project=None, state=None):
253
263
        if project is not None:
254
 
            path = 'projects/:%s/merge_requests' % urlutils.quote(str(project_name), '')
 
264
            path = 'projects/%s/merge_requests' % urlutils.quote(str(project_name), '')
255
265
        else:
256
266
            path = 'merge_requests'
257
267
        parameters = {}
272
282
            self, title, source_project_id, target_project_id,
273
283
            source_branch_name, target_branch_name, description,
274
284
            labels=None):
275
 
        path = 'projects/:%s/merge_requests' % source_project_id
 
285
        path = 'projects/%s/merge_requests' % source_project_id
276
286
        response = self._api_request(
277
287
            'POST', path, fields={
278
288
                'title': title,
387
397
            raise UnsupportedHoster(url)
388
398
        transport = get_transport(
389
399
            'https://%s' % host, possible_transports=possible_transports)
390
 
        return cls(transport)
 
400
        credentials = get_credentials_by_url(transport.base)
 
401
        if credentials is not None:
 
402
            return cls(transport, credentials.get('private_token'))
 
403
        raise UnsupportedHoster(url)
391
404
 
392
405
    @classmethod
393
406
    def iter_instances(cls):