diff options
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/__version__.py | 2 | ||||
-rw-r--r-- | gitlab/base.py | 1 | ||||
-rw-r--r-- | gitlab/mixins.py | 1 | ||||
-rw-r--r-- | gitlab/tests/objects/test_repositories.py | 49 | ||||
-rw-r--r-- | gitlab/v4/cli.py | 13 | ||||
-rw-r--r-- | gitlab/v4/objects/audit_events.py | 18 | ||||
-rw-r--r-- | gitlab/v4/objects/files.py | 1 |
7 files changed, 57 insertions, 28 deletions
diff --git a/gitlab/__version__.py b/gitlab/__version__.py index 1708233..a28b9bc 100644 --- a/gitlab/__version__.py +++ b/gitlab/__version__.py @@ -3,4 +3,4 @@ __copyright__ = "Copyright 2013-2019 Gauvain Pocentek, 2019-2021 python-gitlab t __email__ = "gauvainpocentek@gmail.com" __license__ = "LGPL3" __title__ = "python-gitlab" -__version__ = "2.6.0" +__version__ = "2.7.1" diff --git a/gitlab/base.py b/gitlab/base.py index 8f4e49b..7121cb0 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -45,6 +45,7 @@ class RESTObject(object): _attrs: Dict[str, Any] _module: ModuleType _parent_attrs: Dict[str, Any] + _short_print_attr: Optional[str] = None _updated_attrs: Dict[str, Any] manager: "RESTManager" diff --git a/gitlab/mixins.py b/gitlab/mixins.py index d078a74..b9026c5 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -189,6 +189,7 @@ class RefreshMixin(_RestObjectBase): class ListMixin(_RestManagerBase): _computed_path: Optional[str] _from_parent_attrs: Dict[str, Any] + _list_filters: Tuple[str, ...] = () _obj_cls: Optional[Type[base.RESTObject]] _parent: Optional[base.RESTObject] _parent_attrs: Dict[str, Any] diff --git a/gitlab/tests/objects/test_repositories.py b/gitlab/tests/objects/test_repositories.py new file mode 100644 index 0000000..7c4d77d --- /dev/null +++ b/gitlab/tests/objects/test_repositories.py @@ -0,0 +1,49 @@ +""" +GitLab API: +https://docs.gitlab.com/ee/api/repositories.html +https://docs.gitlab.com/ee/api/repository_files.html +""" +from urllib.parse import quote + +import pytest +import responses + +from gitlab.v4.objects import ProjectFile + +file_path = "app/models/key.rb" +ref = "main" + + +@pytest.fixture +def resp_get_repository_file(): + file_response = { + "file_name": "key.rb", + "file_path": file_path, + "size": 1476, + "encoding": "base64", + "content": "IyA9PSBTY2hlbWEgSW5mb3...", + "content_sha256": "4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481", + "ref": ref, + "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83", + "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50", + "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", + } + + # requests also encodes `.` + encoded_path = quote(file_path, safe="").replace(".", "%2E") + + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url=f"http://localhost/api/v4/projects/1/repository/files/{encoded_path}", + json=file_response, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_get_repository_file(project, resp_get_repository_file): + file = project.files.get(file_path, ref=ref) + assert isinstance(file, ProjectFile) + assert file.file_path == file_path diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 70986f7..42b94aa 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -145,13 +145,10 @@ def _populate_sub_parser_by_class(cls, sub_parser): ) if action_name == "list": - if hasattr(mgr_cls, "_list_filters"): - [ - sub_parser_action.add_argument( - "--%s" % x.replace("_", "-"), required=False - ) - for x in mgr_cls._list_filters - ] + for x in mgr_cls._list_filters: + sub_parser_action.add_argument( + "--%s" % x.replace("_", "-"), required=False + ) sub_parser_action.add_argument("--page", required=False) sub_parser_action.add_argument("--per-page", required=False) @@ -377,7 +374,7 @@ class LegacyPrinter(object): if obj._id_attr: id = getattr(obj, obj._id_attr) print("%s: %s" % (obj._id_attr.replace("_", "-"), id)) - if hasattr(obj, "_short_print_attr"): + if obj._short_print_attr: value = getattr(obj, obj._short_print_attr) or "None" value = value.replace("\r", "").replace("\n", " ") # If the attribute is a note (ProjectCommitComment) then we do diff --git a/gitlab/v4/objects/audit_events.py b/gitlab/v4/objects/audit_events.py index c99856a..20ea116 100644 --- a/gitlab/v4/objects/audit_events.py +++ b/gitlab/v4/objects/audit_events.py @@ -2,8 +2,6 @@ GitLab API: https://docs.gitlab.com/ee/api/audit_events.html """ -import warnings - from gitlab.base import RESTManager, RESTObject from gitlab.mixins import RetrieveMixin @@ -43,14 +41,6 @@ class GroupAuditEventManager(RetrieveMixin, RESTManager): class ProjectAuditEvent(RESTObject): _id_attr = "id" - def __init_subclass__(self): - warnings.warn( - "This class has been renamed to ProjectAuditEvent " - "and will be removed in a future release.", - DeprecationWarning, - 2, - ) - class ProjectAuditEventManager(RetrieveMixin, RESTManager): _path = "/projects/%(project_id)s/audit_events" @@ -58,14 +48,6 @@ class ProjectAuditEventManager(RetrieveMixin, RESTManager): _from_parent_attrs = {"project_id": "id"} _list_filters = ("created_after", "created_before") - def __init_subclass__(self): - warnings.warn( - "This class has been renamed to ProjectAuditEventManager " - "and will be removed in a future release.", - DeprecationWarning, - 2, - ) - class ProjectAudit(ProjectAuditEvent): pass diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index 9fe692f..5d0401f 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -94,7 +94,6 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa Returns: object: The generated RESTObject """ - file_path = file_path.replace("/", "%2F") return GetMixin.get(self, file_path, ref=ref, **kwargs) @cli.register_custom_action( |