Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit019c2d9

Browse files
committed
feat(api): default to gitlab.com if no URL given
1 parent071d699 commit019c2d9

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

‎docs/api-usage.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ python-gitlab only supports GitLab APIs v4.
77
``gitlab.Gitlab`` class
88
=======================
99

10-
To connect toa GitLab server, create a ``gitlab.Gitlab`` object:
10+
To connect toGitLab.com or another GitLab server, create a ``gitlab.Gitlab`` object:
1111

1212
..code-block::python
1313
1414
import gitlab
1515
16-
# private token or personal token authentication
16+
# anonymous read-only access for public resources (GitLab.com)
17+
gl= gitlab.Gitlab()
18+
19+
# anonymous read-only access for public resources (your own GitLab instance)
20+
gl= gitlab.Gitlab('http://10.0.0.1')
21+
22+
# private token or personal token authentication (GitLab.com)
23+
gl= gitlab.Gitlab(private_token='JVNSESs8EwWRx5yDxM5q')
24+
25+
# private token or personal token authentication (your own GitLab instance)
1726
gl= gitlab.Gitlab('http://10.0.0.1',private_token='JVNSESs8EwWRx5yDxM5q')
1827
1928
# oauth token authentication
@@ -23,9 +32,6 @@ To connect to a GitLab server, create a ``gitlab.Gitlab`` object:
2332
import os
2433
gl= gitlab.Gitlab('http://10.0.0.1',job_token=os.environ['CI_JOB_TOKEN'])
2534
26-
# anonymous gitlab instance, read-only for public resources
27-
gl= gitlab.Gitlab('http://10.0.0.1')
28-
2935
# make an API request to create the gl.user object. This is mandatory if you
3036
# use the username/password authentication.
3137
gl.auth()

‎gitlab/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Gitlab(object):
5151
"""Represents a GitLab server connection.
5252
5353
Args:
54-
url (str): The URL of the GitLab server.
54+
url (str): The URL of the GitLab server (defaults to https://gitlab.com).
5555
private_token (str): The user private token
5656
oauth_token (str): An oauth token
5757
job_token (str): A CI job token
@@ -68,7 +68,7 @@ class Gitlab(object):
6868

6969
def__init__(
7070
self,
71-
url,
71+
url=DEFAULT_URL,
7272
private_token=None,
7373
oauth_token=None,
7474
job_token=None,

‎gitlab/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
DEFAULT_URL="https://gitlab.com"
19+
1820
NO_ACCESS=0
1921
MINIMAL_ACCESS=5
2022
GUEST_ACCESS=10

‎gitlab/tests/test_gitlab.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
fromhttmockimportHTTMock,response,urlmatch,with_httmock# noqa
2222

23-
fromgitlabimportGitlab,GitlabList
23+
fromgitlabimportGitlab,GitlabList,DEFAULT_URL
2424
fromgitlab.v4.objectsimportCurrentUser
2525

2626

@@ -127,6 +127,11 @@ def test_gitlab_token_auth(gl, callback=None):
127127
assertisinstance(gl.user,CurrentUser)
128128

129129

130+
deftest_gitlab_default_url():
131+
gl=Gitlab()
132+
assertgl.url==DEFAULT_URL
133+
134+
130135
deftest_gitlab_from_config(default_config):
131136
config_path=default_config
132137
Gitlab.from_config("one", [config_path])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp