How to use the perceval.backends.core.gitlab.GitLab 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_gitlab.py View on Github external
def test_fetch_issues_enterprise(self):
        """Test whether issues are properly fetched from GitLab Enterprise server"""

        setup_http_server(GITLAB_ENTERPRISE_URL_PROJECT,
                          GITLAB_ENTERPRISE_ISSUES_URL,
                          GITLAB_ENTERPRISE_MERGES_URL)

        gitlab = GitLab('am', 'test', base_url=GITLAB_ENTERPRISE_URL)

        issues = [issues for issues in gitlab.fetch()]

        self.assertEqual(len(issues), 4)

        issue = issues[0]
        self.assertEqual(issue['origin'], GITLAB_ENTERPRISE_URL + '/am/test')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_ENTERPRISE_URL + '/am/test')
        self.assertEqual(issue['data']['author']['id'], 1)
        self.assertEqual(issue['data']['author']['username'], 'redfish64')

        issue = issues[1]
        self.assertEqual(issue['origin'], GITLAB_ENTERPRISE_URL + '/am/test')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_ENTERPRISE_URL + '/am/test')
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_initialization_oauth_token(self):
        """Test whether attributes are initialized with an Oauth Token"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL,
                          rate_limit_headers={'RateLimit-Remaining': '20'})

        gitlab = GitLab('fdroid', 'fdroiddata', api_token='aaa', is_oauth_token=True, tag='test')

        self.assertEqual(gitlab.owner, 'fdroid')
        self.assertEqual(gitlab.repository, 'fdroiddata')
        self.assertEqual(gitlab.origin, GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(gitlab.tag, 'test')
        self.assertIsNone(gitlab.client)
        self.assertIsNone(gitlab.blacklist_ids)
        self.assertEqual(gitlab.max_retries, MAX_RETRIES)
        self.assertEqual(gitlab.sleep_time, DEFAULT_SLEEP_TIME)
        self.assertEqual(gitlab.is_oauth_token, True)

        with self.assertRaises(BackendError):
            _ = GitLab('fdroid', 'fdroiddata', is_oauth_token=True, tag='test')
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def setUp(self):
        super().setUp()
        self.backend_write_archive = GitLab("fdroid", "fdroiddata", api_token="your-token", archive=self.archive)
        self.backend_read_archive = GitLab("fdroid", "fdroiddata", api_token="your-token", archive=self.archive)
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_fetch_issues_blacklisted(self):
        """Test whether blacklist issues are not fetched from GitLab"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL)

        gitlab = GitLab("fdroid", "fdroiddata", "your-token", blacklist_ids=[1, 2, 3])

        with self.assertLogs(level='WARNING') as cm:
            issues = [issues for issues in gitlab.fetch()]
            self.assertEqual(cm.output[0], 'WARNING:perceval.backend:Skipping blacklisted item iid 1')
            self.assertEqual(cm.output[1], 'WARNING:perceval.backend:Skipping blacklisted item iid 2')
            self.assertEqual(cm.output[2], 'WARNING:perceval.backend:Skipping blacklisted item iid 3')

        self.assertEqual(len(issues), 1)

        issue = issues[0]
        self.assertEqual(issue['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['data']['author']['id'], 2)
        self.assertEqual(issue['data']['author']['username'], 'YoeriNijs')
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_fetch_merges_empty(self):
        """Test when return empty"""

        page_1 = ''

        httpretty.register_uri(httpretty.GET,
                               GITLAB_URL_PROJECT,
                               body='',
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               GITLAB_MERGES_URL,
                               body=page_1,
                               status=200)

        gitlab = GitLab("fdroid", "fdroiddata", api_token="your-token")

        merges = [merges for merges in gitlab.fetch(category=CATEGORY_MERGE_REQUEST)]

        self.assertEqual(len(merges), 0)
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_fetch_issues(self):
        """Test whether issues are properly fetched from GitLab"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL)

        gitlab = GitLab("fdroid", "fdroiddata", "your-token")

        issues = [issues for issues in gitlab.fetch()]

        self.assertEqual(len(issues), 4)

        issue = issues[0]
        self.assertEqual(issue['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['data']['author']['id'], 1)
        self.assertEqual(issue['data']['author']['username'], 'redfish64')

        issue = issues[1]
        self.assertEqual(issue['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_URL + '/fdroid/fdroiddata')
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_fetch_issues_from_date(self):
        """Test whether issues from a given date are properly fetched from GitLab"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL)

        gitlab = GitLab("fdroid", "fdroiddata", "your-token")
        from_date = datetime.datetime(2017, 3, 18)
        issues = [issues for issues in gitlab.fetch(from_date=from_date)]

        self.assertEqual(len(issues), 4)

        issue = issues[0]
        self.assertEqual(issue['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['data']['author']['id'], 1)
        self.assertEqual(issue['data']['author']['username'], 'redfish64')

        issue = issues[1]
        self.assertEqual(issue['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(issue['category'], CATEGORY_ISSUE)
        self.assertEqual(issue['tag'], GITLAB_URL + '/fdroid/fdroiddata')
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_fetch_merges_from_date(self):
        """Test whether merge requests from a given date are properly fetched from GitLab"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL)

        gitlab = GitLab("fdroid", "fdroiddata", "your-token")
        from_date = datetime.datetime(2017, 3, 18)
        merges = [merges for merges in gitlab.fetch(from_date=from_date, category=CATEGORY_MERGE_REQUEST)]

        self.assertEqual(len(merges), 3)

        merge = merges[0]
        self.assertEqual(merge['origin'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(merge['category'], CATEGORY_MERGE_REQUEST)
        self.assertEqual(merge['tag'], GITLAB_URL + '/fdroid/fdroiddata')
        self.assertEqual(merge['data']['author']['id'], 1)
        self.assertEqual(merge['data']['author']['username'], 'redfish64')
        self.assertEqual(len(merge['data']['versions_data']), 2)
        self.assertTrue('diffs' not in merge['data']['versions_data'][0])
        self.assertTrue('diffs' not in merge['data']['versions_data'][1])

        merge = merges[1]
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def test_search_fields_merges(self):
        """Test whether the search_fields is properly set"""

        setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL, GITLAB_MERGES_URL)

        gitlab = GitLab("fdroid", "fdroiddata", "your-token")

        merges = [merges for merges in gitlab.fetch(category=CATEGORY_MERGE_REQUEST)]

        self.assertEqual(len(merges), 3)

        merge = merges[0]
        self.assertEqual(gitlab.metadata_id(merge['data']), merge['search_fields']['item_id'])
        self.assertEqual(merge['data']['iid'], 1)
        self.assertEqual(merge['data']['iid'], merge['search_fields']['iid'])
        self.assertEqual(gitlab.owner, merge['search_fields']['owner'])
        self.assertEqual(gitlab.repository, merge['search_fields']['project'])
        self.assertIsNone(merge['search_fields']['groups'])

        merge = merges[1]
        self.assertEqual(gitlab.metadata_id(merge['data']), merge['search_fields']['item_id'])
        self.assertEqual(merge['data']['iid'], 2)
github chaoss / grimoirelab-perceval / tests / test_gitlab.py View on Github external
def setUp(self):
        super().setUp()
        self.backend_write_archive = GitLab("fdroid", "fdroiddata", api_token="your-token", archive=self.archive)
        self.backend_read_archive = GitLab("fdroid", "fdroiddata", api_token="your-token", archive=self.archive)