/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-07-28 23:23:29 UTC
  • mfrom: (7371.4.4 github-proposals-fix)
  • Revision ID: breezy.the.bot@gmail.com-20190728232329-6z8svq85fl1yjm4w
Fix iter_proposals for GitHub and GitLab.

Merged from https://code.launchpad.net/~jelmer/brz/github-proposals-fix/+merge/370033

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
    def base_url(self):
231
231
        return self.transport.base
232
232
 
233
 
    def _api_request(self, method, path):
 
233
    def _api_request(self, method, path, data=None):
234
234
        return self.transport.request(
235
235
            method, urlutils.join(self.base_url, 'api', 'v4', path),
236
 
            headers=self.headers)
 
236
            headers=self.headers, body=data)
237
237
 
238
238
    def __init__(self, transport, private_token):
239
239
        self.transport = transport
247
247
            raise NoSuchProject(project_name)
248
248
        if response.status == 200:
249
249
            return json.loads(response.data)
250
 
        raise InvalidHttpResponse(path, response.text)
 
250
        raise errors.InvalidHttpResponse(path, response.text)
251
251
 
252
252
    def _fork_project(self, project_name):
253
253
        path = 'projects/%s/fork' % urlutils.quote(str(project_name), '')
254
254
        response = self._api_request('POST', path)
255
255
        if response != 201:
256
 
            raise InvalidHttpResponse(path, response.text)
 
256
            raise errors.InvalidHttpResponse(path, response.text)
257
257
        return json.loads(response.data)
258
258
 
259
259
    def _get_logged_in_username(self):
261
261
 
262
262
    def _list_merge_requests(self, owner=None, project=None, state=None):
263
263
        if project is not None:
264
 
            path = 'projects/%s/merge_requests' % urlutils.quote(str(project_name), '')
 
264
            path = 'projects/%s/merge_requests' % urlutils.quote(str(project), '')
265
265
        else:
266
266
            path = 'merge_requests'
267
267
        parameters = {}
276
276
            raise errors.PermissionDenied(response.text)
277
277
        if response.status == 200:
278
278
            return json.loads(response.data)
279
 
        raise InvalidHttpResponse(path, response.text)
 
279
        raise errors.InvalidHttpResponse(path, response.text)
280
280
 
281
281
    def _create_mergerequest(
282
282
            self, title, source_project_id, target_project_id,
283
283
            source_branch_name, target_branch_name, description,
284
284
            labels=None):
285
285
        path = 'projects/%s/merge_requests' % source_project_id
 
286
        fields = {
 
287
            'title': title,
 
288
            'source_branch': source_branch_name,
 
289
            'target_branch': target_branch_name,
 
290
            'target_project_id': target_project_id,
 
291
            'description': description,
 
292
            }
 
293
        if labels:
 
294
            fields['labels'] = labels
286
295
        response = self._api_request(
287
 
            'POST', path, fields={
288
 
                'title': title,
289
 
                'source_branch': source_branch_name,
290
 
                'target_branch': target_branch_name,
291
 
                'target_project_id': target_project_id,
292
 
                'description': description,
293
 
                'labels': labels})
 
296
            'POST', path, data=json.dumps(fields).encode('utf-8'))
294
297
        if response.status == 403:
295
298
            raise errors.PermissionDenied(response.text)
296
299
        if response.status == 409:
297
300
            raise MergeProposalExists(self.source_branch.user_url)
298
 
        if response.status == 200:
299
 
            raise InvalidHttpResponse(path, response.text)
 
301
        if response.status != 201:
 
302
            raise errors.InvalidHttpResponse(path, response.text)
300
303
        return json.loads(response.data)
301
304
 
302
305
    def get_push_url(self, branch):
436
439
 
437
440
class GitlabMergeProposalBuilder(MergeProposalBuilder):
438
441
 
439
 
    def __init__(self, l, source_branch, target_branch):
 
442
    def __init__(self, gl, source_branch, target_branch):
440
443
        self.gl = gl
441
444
        self.source_branch = source_branch
442
445
        (self.source_host, self.source_project_name, self.source_branch_name) = (
481
484
            'title': title,
482
485
            'source_project_id': source_project['id'],
483
486
            'target_project_id': target_project['id'],
484
 
            'source_branch': self.source_branch_name,
485
 
            'target_branch': self.target_branch_name,
 
487
            'source_branch_name': self.source_branch_name,
 
488
            'target_branch_name': self.target_branch_name,
486
489
            'description': description}
487
490
        if labels:
488
491
            kwargs['labels'] = ','.join(labels)