Esempio n. 1
0
 def test_make_github_organization(self):
     org_json = {
         "html_url": "",
         "name": "",
         "email": "",
         "login": "",
     }
     org = make_github_organization(self.user, org_json)
     self.assertIsInstance(org, GithubOrganization)
Esempio n. 2
0
 def test_make_github_organization(self):
     org_json = {
         "html_url": "",
         "name": "",
         "email": "",
         "login": "",
     }
     org = make_github_organization(self.user, org_json)
     self.assertIsInstance(org, GithubOrganization)
Esempio n. 3
0
def project_import_github(request, sync=False):
    """
    Integrate with GitHub to pull repos from there.

    """
    repo_type = getattr(settings, 'GITHUB_PRIVACY', 'public')
    tokens = SocialToken.objects.filter(
        account__user__username=request.user.username, app__provider='github')
    github_connected = False
    if tokens.exists():
        github_connected = True
        if sync:
            repos = []
            token = tokens[0]
            session = OAuth2Session(
                client_id=token.app.client_id,
                token={
                    'access_token': str(token.token),
                    'token_type': 'bearer'
                }
            )
            # Get user repos
            owner_resp = github_paginate(session, 'https://api.github.com/user/repos?per_page=100')
            for repo in owner_resp.json():
                log.info('Trying %s' % repo['full_name'])
                oauth_utils.make_github_project(user=request.user, org=None, privacy=repo_type, repo_json=repo)

            # Get org repos
            resp = session.get('https://api.github.com/user/orgs')
            for org_json in resp.json():
                org_resp = github_paginate(session, 'https://api.github.com/orgs/%s' % org_json['login'])
                org_obj = oauth_utils.make_github_organization(user=request.user, org_json=org_resp.json())
                # Add repos
                org_repos_resp = github_paginate(session, 'https://api.github.com/orgs/%s/repos?type=%s' % (org_json['login'], repo_type))
                for repo in org_repos_resp.json():
                    oauth_utils.make_github_project(user=request.user, org=org_obj, privacy=repo_type, repo_json=repo)

    repos = GithubProject.objects.filter(users__in=[request.user])
    for repo in repos:
        ghetto_repo = repo.git_url.replace('git://', '').replace('.git', '')
        projects = Project.objects.filter(repo__endswith=ghetto_repo) | Project.objects.filter(repo__endswith=ghetto_repo + '.git')
        if projects:
            repo.matches = [project.slug for project in projects]
        else:
            repo.matches = []

    return render_to_response(
        'projects/project_import_github.html',
        {
            'repos': repos,
            'github_connected': github_connected,
            'sync': sync,
        },
        context_instance=RequestContext(request)
    )
Esempio n. 4
0
def project_import_github(request, sync=False):
    """
    Integrate with GitHub to pull repos from there.

    """
    repo_type = getattr(settings, 'GITHUB_PRIVACY', 'public')
    tokens = SocialToken.objects.filter(
        account__user__username=request.user.username, app__provider='github')
    github_connected = False
    if tokens.exists():
        github_connected = True
        if sync:
            repos = []
            token = tokens[0]
            session = OAuth2Session(client_id=token.app.client_id,
                                    token={
                                        'access_token': str(token.token),
                                        'token_type': 'bearer'
                                    })
            # Get user repos
            owner_resp = github_paginate(
                session, 'https://api.github.com/user/repos?per_page=100')
            for repo in owner_resp.json():
                log.info('Trying %s' % repo['full_name'])
                oauth_utils.make_github_project(user=request.user,
                                                org=None,
                                                privacy=repo_type,
                                                repo_json=repo)

            # Get org repos
            resp = session.get('https://api.github.com/user/orgs')
            for org_json in resp.json():
                org_resp = github_paginate(
                    session,
                    'https://api.github.com/orgs/%s' % org_json['login'])
                org_obj = oauth_utils.make_github_organization(
                    user=request.user, org_json=org_resp.json())
                # Add repos
                org_repos_resp = github_paginate(
                    session, 'https://api.github.com/orgs/%s/repos?type=%s' %
                    (org_json['login'], repo_type))
                for repo in org_repos_resp.json():
                    oauth_utils.make_github_project(user=request.user,
                                                    org=org_obj,
                                                    privacy=repo_type,
                                                    repo_json=repo)

    repos = GithubProject.objects.filter(users__in=[request.user])
    for repo in repos:
        ghetto_repo = repo.git_url.replace('git://', '').replace('.git', '')
        projects = Project.objects.filter(
            repo__endswith=ghetto_repo) | Project.objects.filter(
                repo__endswith=ghetto_repo + '.git')
        if projects:
            repo.matches = [project.slug for project in projects]
        else:
            repo.matches = []

    return render_to_response('projects/project_import_github.html', {
        'repos': repos,
        'github_connected': github_connected,
        'sync': sync,
    },
                              context_instance=RequestContext(request))