GeezerVison is showing github.com — feat(api): default to gitlab.com if no URL given · python-gitlab/python-gitlab@2edd69c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/api-usage.rst +11-8Lines changed: 11 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,13 +7,22 @@ python-gitlab only supports GitLab APIs v4. | 7 | 7 | ``gitlab.Gitlab`` class | 8 | 8 | ======================= | 9 | 9 |
| 10 | | -To connect to a GitLab server, create a ``gitlab.Gitlab`` object: | | 10 | +To connect to GitLab.com or another GitLab server, create a ``gitlab.Gitlab`` object: | 11 | 11 |
| 12 | 12 | .. code-block:: python | 13 | 13 |
| 14 | 14 | import gitlab | 15 | 15 |
| 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 (self-hosted 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 (self-hosted GitLab instance) | 17 | 26 | gl = gitlab.Gitlab('http://10.0.0.1', private_token='JVNSESs8EwWRx5yDxM5q') | 18 | 27 |
| 19 | 28 | # oauth token authentication | @@ -23,12 +32,6 @@ To connect to a GitLab server, create a ``gitlab.Gitlab`` object: | 23 | 32 | import os | 24 | 33 | gl = gitlab.Gitlab('http://10.0.0.1', job_token=os.environ['CI_JOB_TOKEN']) | 25 | 34 |
| 26 | | - # anonymous gitlab instance, read-only for public resources | 27 | | - gl = gitlab.Gitlab('http://10.0.0.1') | 28 | | -
| 29 | | - # Define your own custom user agent for requests | 30 | | - gl = gitlab.Gitlab('http://10.0.0.1', user_agent='my-package/1.0.0') | 31 | | -
| 32 | 35 | # make an API request to create the gl.user object. This is mandatory if you | 33 | 36 | # use the username/password authentication. | 34 | 37 | gl.auth() | |
Collapse file Copy file name to clipboardExpand all lines: gitlab/__init__.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,7 @@ class Gitlab(object): | 52 | 52 | """Represents a GitLab server connection. | 53 | 53 |
| 54 | 54 | Args: | 55 | | - url (str): The URL of the GitLab server. | | 55 | + url (str): The URL of the GitLab server (defaults to https://gitlab.com). | 56 | 56 | private_token (str): The user private token | 57 | 57 | oauth_token (str): An oauth token | 58 | 58 | job_token (str): A CI job token | @@ -70,7 +70,7 @@ class Gitlab(object): | 70 | 70 |
| 71 | 71 | def __init__( | 72 | 72 | self, | 73 | | - url, | | 73 | + url=DEFAULT_URL, | 74 | 74 | private_token=None, | 75 | 75 | oauth_token=None, | 76 | 76 | job_token=None, | |
Collapse file Copy file name to clipboardExpand all lines: gitlab/const.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | from gitlab.__version__ import __title__, __version__ | 19 | 19 |
| 20 | 20 |
| | 21 | +DEFAULT_URL = "https://gitlab.com" | | 22 | + | 21 | 23 | NO_ACCESS = 0 | 22 | 24 | MINIMAL_ACCESS = 5 | 23 | 25 | GUEST_ACCESS = 10 | |
Collapse file Copy file name to clipboardExpand all lines: gitlab/tests/test_gitlab.py +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | import pytest | 22 | 22 | from httmock import HTTMock, response, urlmatch, with_httmock # noqa | 23 | 23 |
| 24 | | -from gitlab import Gitlab, GitlabList, USER_AGENT | | 24 | +from gitlab import Gitlab, GitlabList, DEFAULT_URL, USER_AGENT | 25 | 25 | from gitlab.v4.objects import CurrentUser | 26 | 26 |
| 27 | 27 |
| @@ -128,6 +128,11 @@ def test_gitlab_token_auth(gl, callback=None): | 128 | 128 | assert isinstance(gl.user, CurrentUser) | 129 | 129 |
| 130 | 130 |
| | 131 | +def test_gitlab_default_url(): | | 132 | + gl = Gitlab() | | 133 | + assert gl.url == DEFAULT_URL | | 134 | + | | 135 | + | 131 | 136 | def test_gitlab_from_config(default_config): | 132 | 137 | config_path = default_config | 133 | 138 | Gitlab.from_config("one", [config_path]) | |
|