Пример #1
0
 def test_organisation(self):
     org = organisation('yola')
     assert isinstance(org, dict)
     assert_equals(len(org.keys()), 23)
Пример #2
0
 def test_organisation(self):
     org = organisation('yola')
     assert isinstance(org, dict)
     assert_equals(len(org.keys()), 23)
Пример #3
0
def load_data(organisation_name, update=False):
    data = {}
    path = '%s/%s.json' % (config.STORE, organisation_name)
    if os.path.exists(path) and not update:
        with open(path, 'rb') as f:
            data = json.loads(f.read())
    else:
        organisation = github.organisation(organisation_name)
        projects = [
            repository['name'] for repository in
            github.organisation_repositories(organisation_name)
        ]
        pull_request_map = {}
        pull_request_comments_map = {}
        pull_requests = []
        pull_request_comments = []
        projects_with_pulls = []
        user_data = {}
        project_data = {}

        for project in projects:
            pulls, comments = github.pull_requests_with_comments(
                organisation_name, project, state='closed')
            print '[load_data] %s: got %d pull requests with %d comments' % (
                project, len(pulls), len(comments))
            open_pulls, open_comments = github.pull_requests_with_comments(
                organisation_name, project, state='open')
            print '[load_data] %s: got %d open pull requests with %d comments' % (
                project, len(open_pulls), len(open_comments))

            for user in [
                    x['user']['login'] for x in pulls + open_pulls if x['user']
            ]:
                if user not in user_data:
                    print '[load_data] %s: caching user %s' % (project, user)
                    user_data[user] = github.user(user)

            if project not in project_data and (pulls + open_pulls):
                print '[load_data] caching project %s data' % project
                project_data[project] = (pulls
                                         or open_pulls)[0]['base']['repo']

            pulls += open_pulls
            comments += open_comments

            pull_request_map[project] = pulls
            pull_request_comments_map[project] = comments

            pull_requests += pulls
            pull_request_comments += comments

            if pulls:
                projects_with_pulls.append(project)

        data = {
            'pull_requests': pull_requests,
            'pull_requests_per_project': pull_request_map,
            'pull_request_comments': pull_request_comments,
            'pull_request_comments_per_project': pull_request_comments_map,
            'projects': projects,
            'projects_with_pulls': projects_with_pulls,
            'organisation': organisation,
            'user_data': user_data,
            'project_data': project_data,
        }
        with PersistentDict(path, 'c', format='json') as d:
            d.update(data)

    return data
Пример #4
0
def load_data(organisation_name, update=False):
    data = {}
    path = '%s/%s.json' % (config.STORE, organisation_name)
    if os.path.exists(path) and not update:
        with open(path, 'rb') as f:
            data = json.loads(f.read())
    else:
        organisation = github.organisation(organisation_name)
        projects = [repository['name'] for repository in github.organisation_repositories(organisation_name)]
        pull_request_map = {}
        pull_request_comments_map = {}
        pull_requests = []
        pull_request_comments = []
        projects_with_pulls = []
        user_data = {}
        project_data = {}

        for project in projects:
            pulls, comments = github.pull_requests_with_comments(organisation_name, project, state='closed')
            print '[load_data] %s: got %d pull requests with %d comments' % (project, len(pulls), len(comments))
            open_pulls, open_comments = github.pull_requests_with_comments(organisation_name, project, state='open')
            print '[load_data] %s: got %d open pull requests with %d comments' % (project, len(open_pulls), len(open_comments))

            for user in [x['user']['login'] for x in pulls+open_pulls if x['user']]:
                if user not in user_data:
                    print '[load_data] %s: caching user %s' % (project, user)
                    user_data[user] = github.user(user)

            if project not in project_data and (pulls+open_pulls):
                print '[load_data] caching project %s data' % project
                project_data[project] = (pulls or open_pulls)[0]['base']['repo'] 

            pulls += open_pulls
            comments += open_comments

            pull_request_map[project] = pulls
            pull_request_comments_map[project] = comments

            pull_requests += pulls
            pull_request_comments += comments

            if pulls:
                projects_with_pulls.append(project)

        data = {
            'pull_requests'                    : pull_requests,
            'pull_requests_per_project'        : pull_request_map,

            'pull_request_comments'            : pull_request_comments,
            'pull_request_comments_per_project': pull_request_comments_map,

            'projects'                         : projects,
            'projects_with_pulls'              : projects_with_pulls,
            'organisation'                     : organisation,

            'user_data'                        : user_data,
            'project_data'                     : project_data,
        }
        with PersistentDict(path, 'c', format='json') as d:
            d.update(data)

    return data