~jelmer/brz/prober-features

« back to all changes in this revision

Viewing changes to breezy/plugins/propose/github.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-11-01 01:21:08 UTC
  • mfrom: (7410.1.3 no-more-pygithub)
  • Revision ID: breezy.the.bot@gmail.com-20191101012108-p36127q2h4wz45zw
Remove last imports of the pygithub module.

Merged from https://code.launchpad.net/~jelmer/brz/no-more-pygithub/+merge/375000

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
        return self._list_paged(path, {'q': query}, per_page=DEFAULT_PER_PAGE)
334
334
 
335
335
    def _create_fork(self, repo, owner=None):
336
 
        (orig_owner, orig_repo) = repo.split('/')
337
 
        path = '/repos/:%s/:%s/forks' % (orig_owner, orig_repo)
338
 
        if owner:
 
336
        path = '/repos/%s/forks' % (repo, )
 
337
        if owner and owner != self._current_user['login']:
339
338
            path += '?organization=%s' % owner
340
339
        response = self._api_request('POST', path)
341
340
        if response.status != 202:
342
 
            raise InvalidHttpResponse(path, response.text)
 
341
            raise InvalidHttpResponse(path, 'status: %d, %r' % (response.status, response.text))
343
342
        return json.loads(response.text)
344
343
 
345
344
    @property
354
353
    def publish_derived(self, local_branch, base_branch, name, project=None,
355
354
                        owner=None, revision_id=None, overwrite=False,
356
355
                        allow_lossy=True):
357
 
        import github
358
356
        base_owner, base_project, base_branch_name = parse_github_branch_url(base_branch)
359
357
        base_repo = self._get_repo('%s/%s' % (base_owner, base_project))
360
358
        if owner is None:
363
361
            project = base_repo['name']
364
362
        try:
365
363
            remote_repo = self._get_repo('%s/%s' % (owner, project))
366
 
        except github.UnknownObjectException:
367
 
            base_repo = self._get_repo('%s/%s' % (base_owner, base_project))
368
 
            remote_repo = self._create_fork(base_repo, owner)
 
364
        except NoSuchProject:
 
365
            base_repo_path = '%s/%s' % (base_owner, base_project)
 
366
            base_repo = self._get_repo(base_repo_path)
 
367
            remote_repo = self._create_fork(base_repo_path, owner)
369
368
            note(gettext('Forking new repository %s from %s') %
370
369
                 (remote_repo['html_url'], base_repo['html_url']))
371
370
        else:
390
389
        return github_url_to_bzr_url(repo['ssh_url'], branch_name)
391
390
 
392
391
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
393
 
        import github
394
392
        base_owner, base_project, base_branch_name = parse_github_branch_url(base_branch)
395
393
        base_repo = self._get_repo('%s/%s' % (base_owner, base_project))
396
394
        if owner is None:
401
399
            remote_repo = self._get_repo('%s/%s' % (owner, project))
402
400
            full_url = github_url_to_bzr_url(remote_repo['ssh_url'], name)
403
401
            return _mod_branch.Branch.open(full_url)
404
 
        except github.UnknownObjectException:
 
402
        except NoSuchProject:
405
403
            raise errors.NotBranchError('%s/%s/%s' % (WEB_GITHUB_URL, owner, project))
406
404
 
407
405
    def get_proposer(self, source_branch, target_branch):
516
514
        if prerequisite_branch is not None:
517
515
            raise PrerequisiteBranchUnsupported(self)
518
516
        # Note that commit_message is ignored, since github doesn't support it.
519
 
        import github
520
517
        # TODO(jelmer): Probe for right repo name
521
518
        if self.target_repo_name.endswith('.git'):
522
519
            self.target_repo_name = self.target_repo_name[:-4]
531
528
                base=self.target_branch_name)
532
529
        except ValidationFailed:
533
530
            raise MergeProposalExists(self.source_branch.user_url)
 
531
        assignees = []
534
532
        if reviewers:
535
533
            for reviewer in reviewers:
536
534
                if '@' in reviewer:
537
535
                    user = self.gh._get_user_by_email(reviewer)
538
536
                else:
539
537
                    user = self.gh._get_user(reviewer)
540
 
                pull_request.assignees.append(user['login'])
541
 
        if labels:
542
 
            for label in labels:
543
 
                pull_request.issue.labels.append(label)
 
538
                assignees.append(user['login'])
 
539
        if labels or assignees:
 
540
            data = {}
 
541
            if labels:
 
542
                data['labels'] = labels
 
543
            if assignees:
 
544
                data['assignees'] = assignees
 
545
            response = self.gh._api_request(
 
546
                'PATCH', pull_request['issue_url'], body=json.dumps(data).encode('utf-8'))
 
547
            if response.status == 422:
 
548
                raise ValidationFailed(json.loads(response.text))
 
549
            if response.status != 200:
 
550
                raise InvalidHttpResponse(pull_request['issue_url'], response.text)
544
551
        return GitHubMergeProposal(self.gh, pull_request)