Commit 893d6206 authored by xarx00's avatar xarx00
Browse files

Merge remote-tracking branch 'upstream/master' into PR-bugfix-718

parents 965b3e04 6bd19027
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -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:
@@ -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,
+4 −4
Original line number Diff line number Diff line
@@ -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
@@ -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)

+32 −0
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@

from __future__ import print_function

import os
import pickle
import tempfile
try:
    import unittest
except ImportError:
@@ -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))
@@ -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)
+10 −10
Original line number Diff line number Diff line
@@ -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'))
@@ -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'))
@@ -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)

@@ -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
@@ -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)


@@ -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)
@@ -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)
@@ -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')
@@ -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', ))
@@ -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)