コード例 #1
0
ファイル: test_analytics.py プロジェクト: wdnmd-RushB/gitem
    def test_get_user_information(self):
        return_value = (
            {
                'login': '******',
                'html_url': 'hu1',
                'name': 'name1',
                'company': 'co1',
                'blog': 'blog1',
                'location': 'loc1',
                'email': 'email1',
                'created_at': 'ca1',
                'updated_at': 'ua1',
            },
            requests.codes.OK,
        )

        ghapi = mock.MagicMock()
        ghapi.get_user = mock.MagicMock(return_value=return_value)

        result = analytics.get_user_information(ghapi, "unused")

        expected = collections.OrderedDict([
            ('Username', 'username1'),
            ('Github URL', 'hu1'),
            ('Name', 'name1'),
            ('Company', 'co1'),
            ('Blog', 'blog1'),
            ('Location', 'loc1'),
            ('Email Address', 'email1'),
            ('Created', 'ca1'),
            ('Updated', 'ua1'),
        ])

        assert result == expected
コード例 #2
0
def user(ghapi, *args, **kwargs):
    username = kwargs['name']
    verbose = kwargs['verbose']
    processes = kwargs['processes']

    user_info = analytics.get_user_information(
        ghapi,
        username
    )
    user_organizations = analytics.get_user_organizations(
        ghapi,
        username
    )
    user_repositories = analytics.get_user_repositories(
        ghapi,
        username
    )

    for human_readable_name, api_info in user_info.items():
        leftpad_print(
            "{}: {}".format(human_readable_name, api_info),
            leftpad_length=0
        )

    leftpad_print("Organizations:", leftpad_length=0)

    organization_count = len(user_organizations) if verbose else CONCISE_COUNT

    for organization in user_organizations[:organization_count]:
        for human_readable_name, api_info in organization.items():
            leftpad_print(
                "{}: {}".format(human_readable_name, api_info),
                leftpad_length=2
            )

    leftpad_print("Repositories:", leftpad_length=0)

    repository_count = len(user_repositories) if verbose else CONCISE_COUNT

    for repository in user_repositories[:repository_count]:
        for human_readable_name, api_info in repository.items():
            leftpad_print(
                "{}: {}".format(human_readable_name, api_info),
                leftpad_length=2
            )

    user_repository_names = [
        repository['Repository Name']
        for repository in user_repositories
    ]

    if processes:
        pool = multiprocessing.Pool(processes=processes)
        partial_email_fn = functools.partial(
            analytics.get_repository_commit_emails,
            ghapi,
            username,
            author=username
        )
        user_repository_emails = pool.map(partial_email_fn, user_repository_names)
    else:
        user_repository_emails = [
            analytics.get_repository_commit_emails(
                ghapi,
                username,
                repository,
                author=username
            )
            for repository in user_repository_names
        ]

    user_emails = functools.reduce(set.union, user_repository_emails, set())

    leftpad_print("Emails:", leftpad_length=0)

    for name, email in user_emails:
        leftpad_print("{}: {}".format(name, email), leftpad_length=2)