Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f276f13

Browse filesBrowse files
author
Gauvain Pocentek
committed
Default to API v4
1 parent b4f0317 commit f276f13
Copy full SHA for f276f13

File tree

Expand file treeCollapse file tree

8 files changed

+41
-42
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+41
-42
lines changed
Open diff view settings
Collapse file

‎docs/api-usage.rst‎

Copy file name to clipboardExpand all lines: docs/api-usage.rst
+5-7Lines changed: 5 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ python-gitlab supports both GitLab v3 and v4 APIs.
77
v3 being deprecated by GitLab, its support in python-gitlab will be minimal.
88
The development team will focus on v4.
99

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.
1111

1212

1313
``gitlab.Gitlab`` class
@@ -63,21 +63,19 @@ for a detailed discussion.
6363
API version
6464
===========
6565

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:
6868

6969
.. code-block:: python
7070
7171
import gitlab
7272
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)
7474
7575
.. warning::
7676

7777
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.
8179

8280
Managers
8381
========
Collapse file

‎docs/cli.rst‎

Copy file name to clipboardExpand all lines: docs/cli.rst
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ example:
4141
[somewhere]
4242
url = https://some.whe.re
4343
private_token = vTbFeqJYCY3sibBP7BZM
44-
api_version = 4
44+
api_version = 3
4545
4646
[elsewhere]
4747
url = http://else.whe.re:8080
@@ -92,8 +92,8 @@ limited permissions.
9292
- An Oauth token for authentication. The Gitlab server must be configured
9393
to support this authentication method.
9494
* - ``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.
9797
* - ``http_username``
9898
- Username for optional HTTP authentication
9999
* - ``http_password``
Collapse file

‎docs/switching-to-v4.rst‎

Copy file name to clipboardExpand all lines: docs/switching-to-v4.rst
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ http://gitlab.com.
1616
Using the v4 API
1717
================
1818

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:
2121

2222
.. code-block:: python
2323
24-
gl = gitlab.Gitlab(..., api_version=4)
24+
gl = gitlab.Gitlab(..., api_version=3)
2525
2626
2727
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:
3030
3131
[my_gitlab]
3232
...
33-
api_version = 4
33+
api_version = 3
3434
3535
3636
Changes between v3 and v4 API
Collapse file

‎gitlab/__init__.py‎

Copy file name to clipboardExpand all lines: gitlab/__init__.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Gitlab(object):
7373

7474
def __init__(self, url, private_token=None, oauth_token=None, email=None,
7575
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',
7777
session=None):
7878

7979
self._api_version = str(api_version)
Collapse file

‎gitlab/config.py‎

Copy file name to clipboardExpand all lines: gitlab/config.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self, gitlab_id=None, config_files=None):
128128
except Exception:
129129
pass
130130

131-
self.api_version = '3'
131+
self.api_version = '4'
132132
try:
133133
self.api_version = self._config.get('global', 'api_version')
134134
except Exception:
Collapse file

‎gitlab/tests/test_gitlab.py‎

Copy file name to clipboardExpand all lines: gitlab/tests/test_gitlab.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TestGitlabRawMethods(unittest.TestCase):
5353
def setUp(self):
5454
self.gl = Gitlab("http://localhost", private_token="private_token",
5555
email="testuser@test.com", password="testpassword",
56-
ssl_verify=True)
56+
ssl_verify=True, api_version=3)
5757

5858
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/known_path",
5959
method="get")
@@ -454,7 +454,7 @@ class TestGitlabMethods(unittest.TestCase):
454454
def setUp(self):
455455
self.gl = Gitlab("http://localhost", private_token="private_token",
456456
email="testuser@test.com", password="testpassword",
457-
ssl_verify=True)
457+
ssl_verify=True, api_version=3)
458458

459459
def test_list(self):
460460
@urlmatch(scheme="http", netloc="localhost",
@@ -938,7 +938,7 @@ class TestGitlab(unittest.TestCase):
938938
def setUp(self):
939939
self.gl = Gitlab("http://localhost", private_token="private_token",
940940
email="testuser@test.com", password="testpassword",
941-
ssl_verify=True)
941+
ssl_verify=True, api_version=3)
942942

943943
def test_pickability(self):
944944
original_gl_objects = self.gl._objects
Collapse file

‎gitlab/tests/test_gitlabobject.py‎

Copy file name to clipboardExpand all lines: gitlab/tests/test_gitlabobject.py
+22-22Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@
3434
from gitlab import * # noqa
3535

3636

37-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
37+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1",
3838
method="get")
3939
def resp_get_project(url, request):
4040
headers = {'content-type': 'application/json'}
4141
content = '{"name": "name", "id": 1}'.encode("utf-8")
4242
return response(200, content, headers, None, 5, request)
4343

4444

45-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects",
45+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
4646
method="get")
4747
def resp_list_project(url, request):
4848
headers = {'content-type': 'application/json'}
4949
content = '[{"name": "name", "id": 1}]'.encode("utf-8")
5050
return response(200, content, headers, None, 5, request)
5151

5252

53-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/issues/1",
53+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/issues/1",
5454
method="get")
5555
def resp_get_issue(url, request):
5656
headers = {'content-type': 'application/json'}
5757
content = '{"name": "name", "id": 1}'.encode("utf-8")
5858
return response(200, content, headers, None, 5, request)
5959

6060

61-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/users/1",
61+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1",
6262
method="put")
6363
def resp_update_user(url, request):
6464
headers = {'content-type': 'application/json'}
@@ -67,15 +67,15 @@ def resp_update_user(url, request):
6767
return response(200, content, headers, None, 5, request)
6868

6969

70-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects",
70+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
7171
method="post")
7272
def resp_create_project(url, request):
7373
headers = {'content-type': 'application/json'}
7474
content = '{"name": "testname", "id": 1}'.encode("utf-8")
7575
return response(201, content, headers, None, 5, request)
7676

7777

78-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/2/members",
78+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/2/members",
7979
method="post")
8080
def resp_create_groupmember(url, request):
8181
headers = {'content-type': 'application/json'}
@@ -84,14 +84,14 @@ def resp_create_groupmember(url, request):
8484

8585

8686
@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")
8888
def resp_get_projectsnippet(url, request):
8989
headers = {'content-type': 'application/json'}
9090
content = '{"title": "test", "id": 3}'.encode("utf-8")
9191
return response(200, content, headers, None, 5, request)
9292

9393

94-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/1",
94+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1",
9595
method="delete")
9696
def resp_delete_group(url, request):
9797
headers = {'content-type': 'application/json'}
@@ -100,7 +100,7 @@ def resp_delete_group(url, request):
100100

101101

102102
@urlmatch(scheme="http", netloc="localhost",
103-
path="/api/v3/groups/2/projects/3",
103+
path="/api/v4/groups/2/projects/3",
104104
method="post")
105105
def resp_transfer_project(url, request):
106106
headers = {'content-type': 'application/json'}
@@ -109,7 +109,7 @@ def resp_transfer_project(url, request):
109109

110110

111111
@urlmatch(scheme="http", netloc="localhost",
112-
path="/api/v3/groups/2/projects/3",
112+
path="/api/v4/groups/2/projects/3",
113113
method="post")
114114
def resp_transfer_project_fail(url, request):
115115
headers = {'content-type': 'application/json'}
@@ -118,7 +118,7 @@ def resp_transfer_project_fail(url, request):
118118

119119

120120
@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",
122122
method="put")
123123
def resp_protect_branch(url, request):
124124
headers = {'content-type': 'application/json'}
@@ -127,7 +127,7 @@ def resp_protect_branch(url, request):
127127

128128

129129
@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",
131131
method="put")
132132
def resp_unprotect_branch(url, request):
133133
headers = {'content-type': 'application/json'}
@@ -136,7 +136,7 @@ def resp_unprotect_branch(url, request):
136136

137137

138138
@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",
140140
method="put")
141141
def resp_protect_branch_fail(url, request):
142142
headers = {'content-type': 'application/json'}
@@ -157,7 +157,7 @@ def test_json(self):
157157
data = json.loads(json_str)
158158
self.assertIn("id", data)
159159
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")
161161

162162
def test_pickability(self):
163163
gl_object = CurrentUser(self.gl, data={"username": "testname"})
@@ -381,31 +381,31 @@ def setUp(self):
381381
self.obj = ProjectCommit(self.gl, data={"id": 3, "project_id": 2})
382382

383383
@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",
385385
method="get")
386386
def resp_diff(self, url, request):
387387
headers = {'content-type': 'application/json'}
388388
content = '{"json": 2 }'.encode("utf-8")
389389
return response(200, content, headers, None, 5, request)
390390

391391
@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",
393393
method="get")
394394
def resp_diff_fail(self, url, request):
395395
headers = {'content-type': 'application/json'}
396396
content = '{"message": "messagecontent" }'.encode("utf-8")
397397
return response(400, content, headers, None, 5, request)
398398

399399
@urlmatch(scheme="http", netloc="localhost",
400-
path="/api/v3/projects/2/repository/blobs/3",
400+
path="/api/v4/projects/2/repository/blobs/3",
401401
method="get")
402402
def resp_blob(self, url, request):
403403
headers = {'content-type': 'application/json'}
404404
content = 'blob'.encode("utf-8")
405405
return response(200, content, headers, None, 5, request)
406406

407407
@urlmatch(scheme="http", netloc="localhost",
408-
path="/api/v3/projects/2/repository/blobs/3",
408+
path="/api/v4/projects/2/repository/blobs/3",
409409
method="get")
410410
def resp_blob_fail(self, url, request):
411411
headers = {'content-type': 'application/json'}
@@ -440,15 +440,15 @@ def setUp(self):
440440
self.obj = ProjectSnippet(self.gl, data={"id": 3, "project_id": 2})
441441

442442
@urlmatch(scheme="http", netloc="localhost",
443-
path="/api/v3/projects/2/snippets/3/raw",
443+
path="/api/v4/projects/2/snippets/3/raw",
444444
method="get")
445445
def resp_content(self, url, request):
446446
headers = {'content-type': 'application/json'}
447447
content = 'content'.encode("utf-8")
448448
return response(200, content, headers, None, 5, request)
449449

450450
@urlmatch(scheme="http", netloc="localhost",
451-
path="/api/v3/projects/2/snippets/3/raw",
451+
path="/api/v4/projects/2/snippets/3/raw",
452452
method="get")
453453
def resp_content_fail(self, url, request):
454454
headers = {'content-type': 'application/json'}
@@ -474,15 +474,15 @@ def setUp(self):
474474
self.obj = Snippet(self.gl, data={"id": 3})
475475

476476
@urlmatch(scheme="http", netloc="localhost",
477-
path="/api/v3/snippets/3/raw",
477+
path="/api/v4/snippets/3/raw",
478478
method="get")
479479
def resp_content(self, url, request):
480480
headers = {'content-type': 'application/json'}
481481
content = 'content'.encode("utf-8")
482482
return response(200, content, headers, None, 5, request)
483483

484484
@urlmatch(scheme="http", netloc="localhost",
485-
path="/api/v3/snippets/3/raw",
485+
path="/api/v4/snippets/3/raw",
486486
method="get")
487487
def resp_content_fail(self, url, request):
488488
headers = {'content-type': 'application/json'}
Collapse file

‎gitlab/tests/test_manager.py‎

Copy file name to clipboardExpand all lines: gitlab/tests/test_manager.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class TestGitlabManager(unittest.TestCase):
5252
def setUp(self):
5353
self.gitlab = Gitlab("http://localhost", private_token="private_token",
5454
email="testuser@test.com",
55-
password="testpassword", ssl_verify=True)
55+
password="testpassword", ssl_verify=True,
56+
api_version=3)
5657

5758
def test_set_parent_args(self):
5859
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/fake",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.