How to use the perceval.backends.core.github.GitHub function in perceval

To help you get started, we’ve selected a few perceval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
def test_initialization(self):
        """Test whether attributes are initializated"""

        rate_limit = read_file('data/github/rate_limit')
        httpretty.register_uri(httpretty.GET,
                               GITHUB_RATE_LIMIT,
                               body=rate_limit,
                               status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        github = GitHub('zhquan_example', 'repo', 'aaa', tag='test')

        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'test')

        self.assertEqual(github.categories, [CATEGORY_ISSUE, CATEGORY_PULL_REQUEST])

        # When tag is empty or None it will be set to
        # the value in origin
        github = GitHub('zhquan_example', 'repo', 'aaa')
        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
httpretty.register_uri(httpretty.GET,
                               GITHUB_USER_URL,
                               body=login, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '5'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body=orgs, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '5'
                               })

        github = GitHub("zhquan_example", "repo", "aaa")
        to_date = datetime.datetime(2016, 3, 1)
        pulls = [pulls for pulls in github.fetch(category=CATEGORY_PULL_REQUEST, to_date=to_date)]

        self.assertEqual(len(pulls), 1)

        pull = pulls[0]
        self.assertEqual(pull['origin'], 'https://github.com/zhquan_example/repo')
        self.assertEqual(pull['uuid'], '58c073fd2a388c44043b9cc197c73c5c540270ac')
        self.assertEqual(pull['updated_on'], 1451929343.0)
        self.assertEqual(pull['category'], CATEGORY_PULL_REQUEST)
        self.assertEqual(pull['tag'], 'https://github.com/zhquan_example/repo')
        self.assertEqual(pull['data']['merged_by_data']['login'], 'zhquan_example')
        self.assertEqual(len(pull['data']['requested_reviewers_data']), 1)
        self.assertEqual(pull['data']['requested_reviewers_data'][0]['login'], 'zhquan_example')
        self.assertEqual(len(pull['data']['review_comments_data']), 2)
        self.assertEqual(len(pull['data']['review_comments_data'][0]['reactions_data']), 0)
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
GITHUB_USER_URL,
                               body=login, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body="[]", status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        from_date = datetime.datetime(2016, 1, 1)
        github = GitHub("zhquan_example", "repo", "aaa")

        issues = [issues for issues in github.fetch(from_date=from_date)]

        self.assertEqual(len(issues), 0)
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'test')

        self.assertEqual(github.categories, [CATEGORY_ISSUE, CATEGORY_PULL_REQUEST])

        # When tag is empty or None it will be set to
        # the value in origin
        github = GitHub('zhquan_example', 'repo', 'aaa')
        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')

        github = GitHub('zhquan_example', 'repo', 'aaa', tag='')
        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
httpretty.register_uri(httpretty.GET,
                               GITHUB_USER_URL,
                               body=login, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '5'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body=orgs, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '5'
                               })

        github = GitHub("zhquan_example", "repo", "aaa")
        issues = [issues for issues in github.fetch()]

        self.assertEqual(len(issues), 2)

        issue = issues[0]
        self.assertEqual(issue['origin'], 'https://github.com/zhquan_example/repo')
        self.assertEqual(issue['uuid'], '58c073fd2a388c44043b9cc197c73c5c540270ac')
        self.assertEqual(issue['updated_on'], 1458035782.0)
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], 'https://github.com/zhquan_example/repo')
        self.assertEqual(issue['data']['assignee_data']['login'], 'zhquan_example')
        self.assertEqual(len(issue['data']['assignees_data']), 1)
        self.assertEqual(len(issue['data']['comments_data']), 1)
        self.assertEqual(issue['data']['reactions']['total_count'], len(issue['data']['reactions_data']))
        self.assertEqual(issue['data']['comments_data'][0]['user_data']['login'], 'zhquan_example')
        self.assertEqual(issue['data']['comments_data'][0]['reactions']['total_count'],
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
httpretty.register_uri(httpretty.GET,
                               GITHUB_USER_URL,
                               body=login, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body=orgs, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        github = GitHub("zhquan_example", "repo", "aaa")
        issues = [issues for issues in github.fetch()]

        issue = issues[0]
        self.assertEqual(issue['data']['reactions']['total_count'], 0)
        self.assertEqual(issue['data']['reactions_data'], [])
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        github = GitHub('zhquan_example', 'repo', 'aaa', tag='test')

        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'test')

        self.assertEqual(github.categories, [CATEGORY_ISSUE, CATEGORY_PULL_REQUEST])

        # When tag is empty or None it will be set to
        # the value in origin
        github = GitHub('zhquan_example', 'repo', 'aaa')
        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')

        github = GitHub('zhquan_example', 'repo', 'aaa', tag='')
        self.assertEqual(github.owner, 'zhquan_example')
        self.assertEqual(github.repository, 'repo')
        self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo')
        self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')
github chaoss / grimoirelab-perceval / tests / test_github.py View on Github external
body=orgs, status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        # Check that 404 exception getting user orgs is managed
        GitHubClient._users_orgs.clear()  # clean cache to get orgs using the API
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body=orgs, status=404,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })
        github = GitHub("zhquan_example", "repo", "aaa")
        _ = [issues for issues in github.fetch()]

        # Check that a no 402 exception getting user orgs is raised
        GitHubClient._users_orgs.clear()
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body=orgs, status=402,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        github = GitHub("zhquan_example", "repo", "aaa")
        with self.assertRaises(requests.exceptions.HTTPError):
            _ = [issues for issues in github.fetch()]
github chaoss / prospector / wsgi / healthmeter / btinfo / importers / github_importer.py View on Github external
def __init__(self, bt_info):
        super().__init__(bt_info)

        url = bt_info.bug_tracker.baseurl

        if url.startswith('https://github.com/'):
            owner = url.replace('https://github.com/', '')
        elif url.startswith('http://github.com/'):
            owner = url.replace('http://github.com/', '')
        else:
            owner = url

        self.backend = GitHub(owner=owner,
                              repository=self.object.product,
                              api_token=bt_info.bug_tracker.api_token,
                              sleep_for_rate=True)