| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b4f0317 commit f276f13
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ python-gitlab supports both GitLab v3 and v4 APIs. | |||
| 7 | 7 | v3 being deprecated by GitLab, its support in python-gitlab will be minimal. | |
| 8 | 8 | The development team will focus on v4. | |
| 9 | 9 | ||
| 10 | - v3 is still the default API used by python-gitlab, for compatibility reasons. | ||
| 10 | + v4 is the default API used by python-gitlab since version 1.3.0. | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ``gitlab.Gitlab`` class | |
@@ -63,21 +63,19 @@ for a detailed discussion. | |||
| 63 | 63 | API version | |
| 64 | 64 | =========== | |
| 65 | 65 | ||
| 66 | - ``python-gitlab`` uses the v3 GitLab API by default. Use the ``api_version`` | ||
| 67 | - parameter to switch to v4: | ||
| 66 | + ``python-gitlab`` uses the v4 GitLab API by default. Use the ``api_version`` | ||
| 67 | + parameter to switch to v3: | ||
| 68 | 68 | ||
| 69 | 69 | .. code-block:: python | |
| 70 | 70 | ||
| 71 | 71 | import gitlab | |
| 72 | 72 | ||
| 73 | - gl = gitlab.Gitlab('http://10.0.0.1', 'JVNSESs8EwWRx5yDxM5q', api_version=4) | ||
| 73 | + gl = gitlab.Gitlab('http://10.0.0.1', 'JVNSESs8EwWRx5yDxM5q', api_version=3) | ||
| 74 | 74 | ||
| 75 | 75 | .. warning:: | |
| 76 | 76 | ||
| 77 | 77 | The python-gitlab API is not the same for v3 and v4. Make sure to read | |
| 78 | - :ref:`switching_to_v4` before upgrading. | ||
| 79 | - | ||
| 80 | - v4 will become the default in python-gitlab. | ||
| 78 | + :ref:`switching_to_v4` if you are upgrading from v3. | ||
| 81 | 79 | ||
| 82 | 80 | Managers | |
| 83 | 81 | ======== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ example: | |||
| 41 | 41 | [somewhere] | |
| 42 | 42 | url = https://some.whe.re | |
| 43 | 43 | private_token = vTbFeqJYCY3sibBP7BZM | |
| 44 | - api_version = 4 | ||
| 44 | + api_version = 3 | ||
| 45 | 45 | ||
| 46 | 46 | [elsewhere] | |
| 47 | 47 | url = http://else.whe.re:8080 | |
@@ -92,8 +92,8 @@ limited permissions. | |||
| 92 | 92 | - An Oauth token for authentication. The Gitlab server must be configured | |
| 93 | 93 | to support this authentication method. | |
| 94 | 94 | * - ``api_version`` | |
| 95 | - - GitLab API version to use (``3`` or ``4``). Defaults to ``3`` for now, | ||
| 96 | - but will switch to ``4`` eventually. | ||
| 95 | + - GitLab API version to use (``3`` or ``4``). Defaults to ``4`` since | ||
| 96 | + version 1.3.0. | ||
| 97 | 97 | * - ``http_username`` | |
| 98 | 98 | - Username for optional HTTP authentication | |
| 99 | 99 | * - ``http_password`` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,12 +16,12 @@ http://gitlab.com. | |||
| 16 | 16 | Using the v4 API | |
| 17 | 17 | ================ | |
| 18 | 18 | ||
| 19 | - To use the new v4 API, explicitly define ``api_version` `in the ``Gitlab`` | ||
| 20 | - constructor: | ||
| 19 | + python-gitlab uses the v4 API by default since the 1.3.0 release. To use the | ||
| 20 | + old v3 API, explicitly define ``api_version`` in the ``Gitlab`` constructor: | ||
| 21 | 21 | ||
| 22 | 22 | .. code-block:: python | |
| 23 | 23 | ||
| 24 | - gl = gitlab.Gitlab(..., api_version=4) | ||
| 24 | + gl = gitlab.Gitlab(..., api_version=3) | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | If you use the configuration file, also explicitly define the version: | |
@@ -30,7 +30,7 @@ If you use the configuration file, also explicitly define the version: | |||
| 30 | 30 | ||
| 31 | 31 | [my_gitlab] | |
| 32 | 32 | ... | |
| 33 | - api_version = 4 | ||
| 33 | + api_version = 3 | ||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | 36 | Changes between v3 and v4 API | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,7 +73,7 @@ class Gitlab(object): | |||
| 73 | 73 | ||
| 74 | 74 | def __init__(self, url, private_token=None, oauth_token=None, email=None, | |
| 75 | 75 | password=None, ssl_verify=True, http_username=None, | |
| 76 | - http_password=None, timeout=None, api_version='3', | ||
| 76 | + http_password=None, timeout=None, api_version='4', | ||
| 77 | 77 | session=None): | |
| 78 | 78 | ||
| 79 | 79 | self._api_version = str(api_version) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,7 +128,7 @@ def __init__(self, gitlab_id=None, config_files=None): | |||
| 128 | 128 | except Exception: | |
| 129 | 129 | pass | |
| 130 | 130 | ||
| 131 | - self.api_version = '3' | ||
| 131 | + self.api_version = '4' | ||
| 132 | 132 | try: | |
| 133 | 133 | self.api_version = self._config.get('global', 'api_version') | |
| 134 | 134 | except Exception: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,7 @@ class TestGitlabRawMethods(unittest.TestCase): | |||
| 53 | 53 | def setUp(self): | |
| 54 | 54 | self.gl = Gitlab("http://localhost", private_token="private_token", | |
| 55 | 55 | email="testuser@test.com", password="testpassword", | |
| 56 | - ssl_verify=True) | ||
| 56 | + ssl_verify=True, api_version=3) | ||
| 57 | 57 | ||
| 58 | 58 | @urlmatch(scheme="http", netloc="localhost", path="/api/v3/known_path", | |
| 59 | 59 | method="get") | |
@@ -454,7 +454,7 @@ class TestGitlabMethods(unittest.TestCase): | |||
| 454 | 454 | def setUp(self): | |
| 455 | 455 | self.gl = Gitlab("http://localhost", private_token="private_token", | |
| 456 | 456 | email="testuser@test.com", password="testpassword", | |
| 457 | - ssl_verify=True) | ||
| 457 | + ssl_verify=True, api_version=3) | ||
| 458 | 458 | ||
| 459 | 459 | def test_list(self): | |
| 460 | 460 | @urlmatch(scheme="http", netloc="localhost", | |
@@ -938,7 +938,7 @@ class TestGitlab(unittest.TestCase): | |||
| 938 | 938 | def setUp(self): | |
| 939 | 939 | self.gl = Gitlab("http://localhost", private_token="private_token", | |
| 940 | 940 | email="testuser@test.com", password="testpassword", | |
| 941 | - ssl_verify=True) | ||
| 941 | + ssl_verify=True, api_version=3) | ||
| 942 | 942 | ||
| 943 | 943 | def test_pickability(self): | |
| 944 | 944 | original_gl_objects = self.gl._objects | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,31 +34,31 @@ | |||
| 34 | 34 | from gitlab import * # noqa | |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1", | ||
| 37 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", | ||
| 38 | 38 | method="get") | |
| 39 | 39 | def resp_get_project(url, request): | |
| 40 | 40 | headers = {'content-type': 'application/json'} | |
| 41 | 41 | content = '{"name": "name", "id": 1}'.encode("utf-8") | |
| 42 | 42 | return response(200, content, headers, None, 5, request) | |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects", | ||
| 45 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", | ||
| 46 | 46 | method="get") | |
| 47 | 47 | def resp_list_project(url, request): | |
| 48 | 48 | headers = {'content-type': 'application/json'} | |
| 49 | 49 | content = '[{"name": "name", "id": 1}]'.encode("utf-8") | |
| 50 | 50 | return response(200, content, headers, None, 5, request) | |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/issues/1", | ||
| 53 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/issues/1", | ||
| 54 | 54 | method="get") | |
| 55 | 55 | def resp_get_issue(url, request): | |
| 56 | 56 | headers = {'content-type': 'application/json'} | |
| 57 | 57 | content = '{"name": "name", "id": 1}'.encode("utf-8") | |
| 58 | 58 | return response(200, content, headers, None, 5, request) | |
| 59 | 59 | ||
| 60 | 60 | ||
| 61 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/users/1", | ||
| 61 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", | ||
| 62 | 62 | method="put") | |
| 63 | 63 | def resp_update_user(url, request): | |
| 64 | 64 | headers = {'content-type': 'application/json'} | |
@@ -67,15 +67,15 @@ def resp_update_user(url, request): | |||
| 67 | 67 | return response(200, content, headers, None, 5, request) | |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects", | ||
| 70 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", | ||
| 71 | 71 | method="post") | |
| 72 | 72 | def resp_create_project(url, request): | |
| 73 | 73 | headers = {'content-type': 'application/json'} | |
| 74 | 74 | content = '{"name": "testname", "id": 1}'.encode("utf-8") | |
| 75 | 75 | return response(201, content, headers, None, 5, request) | |
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/2/members", | ||
| 78 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/2/members", | ||
| 79 | 79 | method="post") | |
| 80 | 80 | def resp_create_groupmember(url, request): | |
| 81 | 81 | headers = {'content-type': 'application/json'} | |
@@ -84,14 +84,14 @@ def resp_create_groupmember(url, request): | |||
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | 86 | @urlmatch(scheme="http", netloc="localhost", | |
| 87 | - path="/api/v3/projects/2/snippets/3", method="get") | ||
| 87 | + path="/api/v4/projects/2/snippets/3", method="get") | ||
| 88 | 88 | def resp_get_projectsnippet(url, request): | |
| 89 | 89 | headers = {'content-type': 'application/json'} | |
| 90 | 90 | content = '{"title": "test", "id": 3}'.encode("utf-8") | |
| 91 | 91 | return response(200, content, headers, None, 5, request) | |
| 92 | 92 | ||
| 93 | 93 | ||
| 94 | - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/1", | ||
| 94 | + @urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1", | ||
| 95 | 95 | method="delete") | |
| 96 | 96 | def resp_delete_group(url, request): | |
| 97 | 97 | headers = {'content-type': 'application/json'} | |
@@ -100,7 +100,7 @@ def resp_delete_group(url, request): | |||
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | 102 | @urlmatch(scheme="http", netloc="localhost", | |
| 103 | - path="/api/v3/groups/2/projects/3", | ||
| 103 | + path="/api/v4/groups/2/projects/3", | ||
| 104 | 104 | method="post") | |
| 105 | 105 | def resp_transfer_project(url, request): | |
| 106 | 106 | headers = {'content-type': 'application/json'} | |
@@ -109,7 +109,7 @@ def resp_transfer_project(url, request): | |||
| 109 | 109 | ||
| 110 | 110 | ||
| 111 | 111 | @urlmatch(scheme="http", netloc="localhost", | |
| 112 | - path="/api/v3/groups/2/projects/3", | ||
| 112 | + path="/api/v4/groups/2/projects/3", | ||
| 113 | 113 | method="post") | |
| 114 | 114 | def resp_transfer_project_fail(url, request): | |
| 115 | 115 | headers = {'content-type': 'application/json'} | |
@@ -118,7 +118,7 @@ def resp_transfer_project_fail(url, request): | |||
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | 120 | @urlmatch(scheme="http", netloc="localhost", | |
| 121 | - path="/api/v3/projects/2/repository/branches/branchname/protect", | ||
| 121 | + path="/api/v4/projects/2/repository/branches/branchname/protect", | ||
| 122 | 122 | method="put") | |
| 123 | 123 | def resp_protect_branch(url, request): | |
| 124 | 124 | headers = {'content-type': 'application/json'} | |
@@ -127,7 +127,7 @@ def resp_protect_branch(url, request): | |||
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | 129 | @urlmatch(scheme="http", netloc="localhost", | |
| 130 | - path="/api/v3/projects/2/repository/branches/branchname/unprotect", | ||
| 130 | + path="/api/v4/projects/2/repository/branches/branchname/unprotect", | ||
| 131 | 131 | method="put") | |
| 132 | 132 | def resp_unprotect_branch(url, request): | |
| 133 | 133 | headers = {'content-type': 'application/json'} | |
@@ -136,7 +136,7 @@ def resp_unprotect_branch(url, request): | |||
| 136 | 136 | ||
| 137 | 137 | ||
| 138 | 138 | @urlmatch(scheme="http", netloc="localhost", | |
| 139 | - path="/api/v3/projects/2/repository/branches/branchname/protect", | ||
| 139 | + path="/api/v4/projects/2/repository/branches/branchname/protect", | ||
| 140 | 140 | method="put") | |
| 141 | 141 | def resp_protect_branch_fail(url, request): | |
| 142 | 142 | headers = {'content-type': 'application/json'} | |
@@ -157,7 +157,7 @@ def test_json(self): | |||
| 157 | 157 | data = json.loads(json_str) | |
| 158 | 158 | self.assertIn("id", data) | |
| 159 | 159 | self.assertEqual(data["username"], "testname") | |
| 160 | - self.assertEqual(data["gitlab"]["url"], "http://localhost/api/v3") | ||
| 160 | + self.assertEqual(data["gitlab"]["url"], "http://localhost/api/v4") | ||
| 161 | 161 | ||
| 162 | 162 | def test_pickability(self): | |
| 163 | 163 | gl_object = CurrentUser(self.gl, data={"username": "testname"}) | |
@@ -381,31 +381,31 @@ def setUp(self): | |||
| 381 | 381 | self.obj = ProjectCommit(self.gl, data={"id": 3, "project_id": 2}) | |
| 382 | 382 | ||
| 383 | 383 | @urlmatch(scheme="http", netloc="localhost", | |
| 384 | - path="/api/v3/projects/2/repository/commits/3/diff", | ||
| 384 | + path="/api/v4/projects/2/repository/commits/3/diff", | ||
| 385 | 385 | method="get") | |
| 386 | 386 | def resp_diff(self, url, request): | |
| 387 | 387 | headers = {'content-type': 'application/json'} | |
| 388 | 388 | content = '{"json": 2 }'.encode("utf-8") | |
| 389 | 389 | return response(200, content, headers, None, 5, request) | |
| 390 | 390 | ||
| 391 | 391 | @urlmatch(scheme="http", netloc="localhost", | |
| 392 | - path="/api/v3/projects/2/repository/commits/3/diff", | ||
| 392 | + path="/api/v4/projects/2/repository/commits/3/diff", | ||
| 393 | 393 | method="get") | |
| 394 | 394 | def resp_diff_fail(self, url, request): | |
| 395 | 395 | headers = {'content-type': 'application/json'} | |
| 396 | 396 | content = '{"message": "messagecontent" }'.encode("utf-8") | |
| 397 | 397 | return response(400, content, headers, None, 5, request) | |
| 398 | 398 | ||
| 399 | 399 | @urlmatch(scheme="http", netloc="localhost", | |
| 400 | - path="/api/v3/projects/2/repository/blobs/3", | ||
| 400 | + path="/api/v4/projects/2/repository/blobs/3", | ||
| 401 | 401 | method="get") | |
| 402 | 402 | def resp_blob(self, url, request): | |
| 403 | 403 | headers = {'content-type': 'application/json'} | |
| 404 | 404 | content = 'blob'.encode("utf-8") | |
| 405 | 405 | return response(200, content, headers, None, 5, request) | |
| 406 | 406 | ||
| 407 | 407 | @urlmatch(scheme="http", netloc="localhost", | |
| 408 | - path="/api/v3/projects/2/repository/blobs/3", | ||
| 408 | + path="/api/v4/projects/2/repository/blobs/3", | ||
| 409 | 409 | method="get") | |
| 410 | 410 | def resp_blob_fail(self, url, request): | |
| 411 | 411 | headers = {'content-type': 'application/json'} | |
@@ -440,15 +440,15 @@ def setUp(self): | |||
| 440 | 440 | self.obj = ProjectSnippet(self.gl, data={"id": 3, "project_id": 2}) | |
| 441 | 441 | ||
| 442 | 442 | @urlmatch(scheme="http", netloc="localhost", | |
| 443 | - path="/api/v3/projects/2/snippets/3/raw", | ||
| 443 | + path="/api/v4/projects/2/snippets/3/raw", | ||
| 444 | 444 | method="get") | |
| 445 | 445 | def resp_content(self, url, request): | |
| 446 | 446 | headers = {'content-type': 'application/json'} | |
| 447 | 447 | content = 'content'.encode("utf-8") | |
| 448 | 448 | return response(200, content, headers, None, 5, request) | |
| 449 | 449 | ||
| 450 | 450 | @urlmatch(scheme="http", netloc="localhost", | |
| 451 | - path="/api/v3/projects/2/snippets/3/raw", | ||
| 451 | + path="/api/v4/projects/2/snippets/3/raw", | ||
| 452 | 452 | method="get") | |
| 453 | 453 | def resp_content_fail(self, url, request): | |
| 454 | 454 | headers = {'content-type': 'application/json'} | |
@@ -474,15 +474,15 @@ def setUp(self): | |||
| 474 | 474 | self.obj = Snippet(self.gl, data={"id": 3}) | |
| 475 | 475 | ||
| 476 | 476 | @urlmatch(scheme="http", netloc="localhost", | |
| 477 | - path="/api/v3/snippets/3/raw", | ||
| 477 | + path="/api/v4/snippets/3/raw", | ||
| 478 | 478 | method="get") | |
| 479 | 479 | def resp_content(self, url, request): | |
| 480 | 480 | headers = {'content-type': 'application/json'} | |
| 481 | 481 | content = 'content'.encode("utf-8") | |
| 482 | 482 | return response(200, content, headers, None, 5, request) | |
| 483 | 483 | ||
| 484 | 484 | @urlmatch(scheme="http", netloc="localhost", | |
| 485 | - path="/api/v3/snippets/3/raw", | ||
| 485 | + path="/api/v4/snippets/3/raw", | ||
| 486 | 486 | method="get") | |
| 487 | 487 | def resp_content_fail(self, url, request): | |
| 488 | 488 | headers = {'content-type': 'application/json'} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,8 @@ class TestGitlabManager(unittest.TestCase): | |||
| 52 | 52 | def setUp(self): | |
| 53 | 53 | self.gitlab = Gitlab("http://localhost", private_token="private_token", | |
| 54 | 54 | email="testuser@test.com", | |
| 55 | - password="testpassword", ssl_verify=True) | ||
| 55 | + password="testpassword", ssl_verify=True, | ||
| 56 | + api_version=3) | ||
| 56 | 57 | ||
| 57 | 58 | def test_set_parent_args(self): | |
| 58 | 59 | @urlmatch(scheme="http", netloc="localhost", path="/api/v3/fake", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments