Loading gitlab/__init__.py +9 −9 Original line number Diff line number Diff line Loading @@ -165,8 +165,8 @@ class Gitlab(object): """The API version used (4 only).""" return self._api_version @staticmethod def from_config(gitlab_id=None, config_files=None): @classmethod def from_config(cls, gitlab_id=None, config_files=None): """Create a Gitlab connection from configuration files. Args: Loading @@ -181,7 +181,7 @@ class Gitlab(object): """ config = gitlab.config.GitlabConfigParser(gitlab_id=gitlab_id, config_files=config_files) return Gitlab(config.url, private_token=config.private_token, return cls(config.url, private_token=config.private_token, oauth_token=config.oauth_token, ssl_verify=config.ssl_verify, timeout=config.timeout, http_username=config.http_username, Loading gitlab/cli.py +4 −4 Original line number Diff line number Diff line Loading @@ -133,12 +133,9 @@ def _parse_value(v): def main(): if "--version" in sys.argv: print(gitlab.__version__) exit(0) sys.exit(0) parser = _get_base_parser(add_help=False) if "--help" in sys.argv or "-h" in sys.argv: parser.print_help() exit(0) # This first parsing step is used to find the gitlab config to use, and # load the propermodule (v3 or v4) accordingly. At that point we don't have Loading @@ -150,6 +147,9 @@ def main(): options.config_file ) except gitlab.config.ConfigError as e: if "--help" in sys.argv or "-h" in sys.argv: parser.print_help() sys.exit(0) sys.exit(e) cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version) Loading gitlab/tests/test_gitlab.py +32 −0 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ from __future__ import print_function import os import pickle import tempfile try: import unittest except ImportError: Loading @@ -34,6 +36,17 @@ from gitlab import * # noqa from gitlab.v4.objects import * # noqa valid_config = b"""[global] default = one ssl_verify = true timeout = 2 [one] url = http://one.url private_token = ABCDEF """ class TestSanitize(unittest.TestCase): def test_do_nothing(self): self.assertEqual(1, gitlab._sanitize(1)) Loading Loading @@ -536,3 +549,22 @@ class TestGitlab(unittest.TestCase): self.assertEqual(type(user), User) self.assertEqual(user.name, "name") self.assertEqual(user.id, 1) def _default_config(self): fd, temp_path = tempfile.mkstemp() os.write(fd, valid_config) os.close(fd) return temp_path def test_from_config(self): config_path = self._default_config() gitlab.Gitlab.from_config('one', [config_path]) os.unlink(config_path) def test_subclass_from_config(self): class MyGitlab(gitlab.Gitlab): pass config_path = self._default_config() gl = MyGitlab.from_config('one', [config_path]) self.assertEqual(type(gl).__name__, 'MyGitlab') os.unlink(config_path) gitlab/v4/objects.py +10 −10 Original line number Diff line number Diff line Loading @@ -909,7 +909,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ path = '/groups/%d/projects/%d' % (self.id, to_project_id) path = '/groups/%s/projects/%s' % (self.id, to_project_id) self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Group', ('scope', 'search')) Loading @@ -930,7 +930,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} path = '/groups/%d/search' % self.get_id() path = '/groups/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Group', ('cn', 'group_access', 'provider')) Loading @@ -949,7 +949,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ path = '/groups/%d/ldap_group_links' % self.get_id() path = '/groups/%s/ldap_group_links' % self.get_id() data = {'cn': cn, 'group_access': group_access, 'provider': provider} self.manager.gitlab.http_post(path, post_data=data, **kwargs) Loading @@ -967,7 +967,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ path = '/groups/%d/ldap_group_links' % self.get_id() path = '/groups/%s/ldap_group_links' % self.get_id() if provider is not None: path += '/%s' % provider path += '/%s' % cn Loading @@ -985,7 +985,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ path = '/groups/%d/ldap_sync' % self.get_id() path = '/groups/%s/ldap_sync' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) Loading Loading @@ -3216,7 +3216,7 @@ class ProjectExport(RefreshMixin, RESTObject): Returns: str: The blob content if streamed is False, None otherwise """ path = '/projects/%d/export/download' % self.project_id path = '/projects/%s/export/download' % self.project_id result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) Loading Loading @@ -3718,7 +3718,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): Returns: str: The uncompressed tar archive of the repository """ path = '/projects/%d/snapshot' % self.get_id() path = '/projects/%s/snapshot' % self.get_id() result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) Loading @@ -3741,7 +3741,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} path = '/projects/%d/search' % self.get_id() path = '/projects/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Project') Loading @@ -3756,7 +3756,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ path = '/projects/%d/mirror/pull' % self.get_id() path = '/projects/%s/mirror/pull' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Project', ('to_namespace', )) Loading @@ -3773,7 +3773,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ path = '/projects/%d/transfer' % (self.id,) path = '/projects/%s/transfer' % (self.id,) self.manager.gitlab.http_put(path, post_data={"namespace": to_namespace}, **kwargs) Loading Loading
gitlab/__init__.py +9 −9 Original line number Diff line number Diff line Loading @@ -165,8 +165,8 @@ class Gitlab(object): """The API version used (4 only).""" return self._api_version @staticmethod def from_config(gitlab_id=None, config_files=None): @classmethod def from_config(cls, gitlab_id=None, config_files=None): """Create a Gitlab connection from configuration files. Args: Loading @@ -181,7 +181,7 @@ class Gitlab(object): """ config = gitlab.config.GitlabConfigParser(gitlab_id=gitlab_id, config_files=config_files) return Gitlab(config.url, private_token=config.private_token, return cls(config.url, private_token=config.private_token, oauth_token=config.oauth_token, ssl_verify=config.ssl_verify, timeout=config.timeout, http_username=config.http_username, Loading
gitlab/cli.py +4 −4 Original line number Diff line number Diff line Loading @@ -133,12 +133,9 @@ def _parse_value(v): def main(): if "--version" in sys.argv: print(gitlab.__version__) exit(0) sys.exit(0) parser = _get_base_parser(add_help=False) if "--help" in sys.argv or "-h" in sys.argv: parser.print_help() exit(0) # This first parsing step is used to find the gitlab config to use, and # load the propermodule (v3 or v4) accordingly. At that point we don't have Loading @@ -150,6 +147,9 @@ def main(): options.config_file ) except gitlab.config.ConfigError as e: if "--help" in sys.argv or "-h" in sys.argv: parser.print_help() sys.exit(0) sys.exit(e) cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version) Loading
gitlab/tests/test_gitlab.py +32 −0 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ from __future__ import print_function import os import pickle import tempfile try: import unittest except ImportError: Loading @@ -34,6 +36,17 @@ from gitlab import * # noqa from gitlab.v4.objects import * # noqa valid_config = b"""[global] default = one ssl_verify = true timeout = 2 [one] url = http://one.url private_token = ABCDEF """ class TestSanitize(unittest.TestCase): def test_do_nothing(self): self.assertEqual(1, gitlab._sanitize(1)) Loading Loading @@ -536,3 +549,22 @@ class TestGitlab(unittest.TestCase): self.assertEqual(type(user), User) self.assertEqual(user.name, "name") self.assertEqual(user.id, 1) def _default_config(self): fd, temp_path = tempfile.mkstemp() os.write(fd, valid_config) os.close(fd) return temp_path def test_from_config(self): config_path = self._default_config() gitlab.Gitlab.from_config('one', [config_path]) os.unlink(config_path) def test_subclass_from_config(self): class MyGitlab(gitlab.Gitlab): pass config_path = self._default_config() gl = MyGitlab.from_config('one', [config_path]) self.assertEqual(type(gl).__name__, 'MyGitlab') os.unlink(config_path)
gitlab/v4/objects.py +10 −10 Original line number Diff line number Diff line Loading @@ -909,7 +909,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ path = '/groups/%d/projects/%d' % (self.id, to_project_id) path = '/groups/%s/projects/%s' % (self.id, to_project_id) self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Group', ('scope', 'search')) Loading @@ -930,7 +930,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} path = '/groups/%d/search' % self.get_id() path = '/groups/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Group', ('cn', 'group_access', 'provider')) Loading @@ -949,7 +949,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ path = '/groups/%d/ldap_group_links' % self.get_id() path = '/groups/%s/ldap_group_links' % self.get_id() data = {'cn': cn, 'group_access': group_access, 'provider': provider} self.manager.gitlab.http_post(path, post_data=data, **kwargs) Loading @@ -967,7 +967,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ path = '/groups/%d/ldap_group_links' % self.get_id() path = '/groups/%s/ldap_group_links' % self.get_id() if provider is not None: path += '/%s' % provider path += '/%s' % cn Loading @@ -985,7 +985,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ path = '/groups/%d/ldap_sync' % self.get_id() path = '/groups/%s/ldap_sync' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) Loading Loading @@ -3216,7 +3216,7 @@ class ProjectExport(RefreshMixin, RESTObject): Returns: str: The blob content if streamed is False, None otherwise """ path = '/projects/%d/export/download' % self.project_id path = '/projects/%s/export/download' % self.project_id result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) Loading Loading @@ -3718,7 +3718,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): Returns: str: The uncompressed tar archive of the repository """ path = '/projects/%d/snapshot' % self.get_id() path = '/projects/%s/snapshot' % self.get_id() result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) Loading @@ -3741,7 +3741,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} path = '/projects/%d/search' % self.get_id() path = '/projects/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Project') Loading @@ -3756,7 +3756,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ path = '/projects/%d/mirror/pull' % self.get_id() path = '/projects/%s/mirror/pull' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Project', ('to_namespace', )) Loading @@ -3773,7 +3773,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ path = '/projects/%d/transfer' % (self.id,) path = '/projects/%s/transfer' % (self.id,) self.manager.gitlab.http_put(path, post_data={"namespace": to_namespace}, **kwargs) Loading