summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-02-01 00:04:56 +0100
committerGitHub <noreply@github.com>2022-02-01 00:04:56 +0100
commit7646360d6b622b1008917116dc4f64ced32f4057 (patch)
tree8a5032d8ead259ff3d78615bc51140a488f882b6 /gitlab
parent7a13b9bfa4aead6c731f9a92e0946dba7577c61b (diff)
parenta57334f1930752c70ea15847a39324fa94042460 (diff)
downloadgitlab-7646360d6b622b1008917116dc4f64ced32f4057.tar.gz
Merge pull request #1866 from python-gitlab/jlvillal/arrays_2
chore: create new ArrayAttribute class
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/types.py15
-rw-r--r--gitlab/v4/objects/groups.py7
-rw-r--r--gitlab/v4/objects/issues.py15
-rw-r--r--gitlab/v4/objects/members.py4
-rw-r--r--gitlab/v4/objects/merge_requests.py14
-rw-r--r--gitlab/v4/objects/milestones.py4
-rw-r--r--gitlab/v4/objects/projects.py2
-rw-r--r--gitlab/v4/objects/settings.py12
-rw-r--r--gitlab/v4/objects/users.py2
9 files changed, 38 insertions, 37 deletions
diff --git a/gitlab/types.py b/gitlab/types.py
index 2dc8121..bf74f2e 100644
--- a/gitlab/types.py
+++ b/gitlab/types.py
@@ -32,7 +32,9 @@ class GitlabAttribute:
return self._value
-class CommaSeparatedListAttribute(GitlabAttribute):
+class _ListArrayAttribute(GitlabAttribute):
+ """Helper class to support `list` / `array` types."""
+
def set_from_cli(self, cli_value: str) -> None:
if not cli_value.strip():
self._value = []
@@ -49,6 +51,17 @@ class CommaSeparatedListAttribute(GitlabAttribute):
return ",".join([str(x) for x in self._value])
+class ArrayAttribute(_ListArrayAttribute):
+ """To support `array` types as documented in
+ https://docs.gitlab.com/ee/api/#array"""
+
+
+class CommaSeparatedListAttribute(_ListArrayAttribute):
+ """For values which are sent to the server as a Comma Separated Values
+ (CSV) string. We allow them to be specified as a list and we convert it
+ into a CSV"""
+
+
class LowercaseStringAttribute(GitlabAttribute):
def get_for_api(self) -> str:
return str(self._value).lower()
diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py
index 5e2ac00..a3a1051 100644
--- a/gitlab/v4/objects/groups.py
+++ b/gitlab/v4/objects/groups.py
@@ -314,10 +314,7 @@ class GroupManager(CRUDMixin, RESTManager):
"shared_runners_setting",
),
)
- _types = {
- "avatar": types.ImageAttribute,
- "skip_groups": types.CommaSeparatedListAttribute,
- }
+ _types = {"avatar": types.ImageAttribute, "skip_groups": types.ArrayAttribute}
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Group:
return cast(Group, super().get(id=id, lazy=lazy, **kwargs))
@@ -377,7 +374,7 @@ class GroupSubgroupManager(ListMixin, RESTManager):
"with_custom_attributes",
"min_access_level",
)
- _types = {"skip_groups": types.CommaSeparatedListAttribute}
+ _types = {"skip_groups": types.ArrayAttribute}
class GroupDescendantGroup(RESTObject):
diff --git a/gitlab/v4/objects/issues.py b/gitlab/v4/objects/issues.py
index 3452daf..f20252b 100644
--- a/gitlab/v4/objects/issues.py
+++ b/gitlab/v4/objects/issues.py
@@ -65,10 +65,7 @@ class IssueManager(RetrieveMixin, RESTManager):
"updated_after",
"updated_before",
)
- _types = {
- "iids": types.CommaSeparatedListAttribute,
- "labels": types.CommaSeparatedListAttribute,
- }
+ _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Issue:
return cast(Issue, super().get(id=id, lazy=lazy, **kwargs))
@@ -98,10 +95,7 @@ class GroupIssueManager(ListMixin, RESTManager):
"updated_after",
"updated_before",
)
- _types = {
- "iids": types.CommaSeparatedListAttribute,
- "labels": types.CommaSeparatedListAttribute,
- }
+ _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}
class ProjectIssue(
@@ -239,10 +233,7 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
"discussion_locked",
),
)
- _types = {
- "iids": types.CommaSeparatedListAttribute,
- "labels": types.CommaSeparatedListAttribute,
- }
+ _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
diff --git a/gitlab/v4/objects/members.py b/gitlab/v4/objects/members.py
index 16fb925..5ee0b0e 100644
--- a/gitlab/v4/objects/members.py
+++ b/gitlab/v4/objects/members.py
@@ -41,7 +41,7 @@ class GroupMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
- _types = {"user_ids": types.CommaSeparatedListAttribute}
+ _types = {"user_ids": types.ArrayAttribute}
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
@@ -101,7 +101,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
- _types = {"user_ids": types.CommaSeparatedListAttribute}
+ _types = {"user_ids": types.ArrayAttribute}
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
diff --git a/gitlab/v4/objects/merge_requests.py b/gitlab/v4/objects/merge_requests.py
index 7f0be4b..edd7d01 100644
--- a/gitlab/v4/objects/merge_requests.py
+++ b/gitlab/v4/objects/merge_requests.py
@@ -95,8 +95,8 @@ class MergeRequestManager(ListMixin, RESTManager):
"deployed_after",
)
_types = {
- "approver_ids": types.CommaSeparatedListAttribute,
- "approved_by_ids": types.CommaSeparatedListAttribute,
+ "approver_ids": types.ArrayAttribute,
+ "approved_by_ids": types.ArrayAttribute,
"in": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}
@@ -133,8 +133,8 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
"wip",
)
_types = {
- "approver_ids": types.CommaSeparatedListAttribute,
- "approved_by_ids": types.CommaSeparatedListAttribute,
+ "approver_ids": types.ArrayAttribute,
+ "approved_by_ids": types.ArrayAttribute,
"labels": types.CommaSeparatedListAttribute,
}
@@ -455,9 +455,9 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
"wip",
)
_types = {
- "approver_ids": types.CommaSeparatedListAttribute,
- "approved_by_ids": types.CommaSeparatedListAttribute,
- "iids": types.CommaSeparatedListAttribute,
+ "approver_ids": types.ArrayAttribute,
+ "approved_by_ids": types.ArrayAttribute,
+ "iids": types.ArrayAttribute,
"labels": types.CommaSeparatedListAttribute,
}
diff --git a/gitlab/v4/objects/milestones.py b/gitlab/v4/objects/milestones.py
index dc6266a..da75826 100644
--- a/gitlab/v4/objects/milestones.py
+++ b/gitlab/v4/objects/milestones.py
@@ -93,7 +93,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
- _types = {"iids": types.CommaSeparatedListAttribute}
+ _types = {"iids": types.ArrayAttribute}
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
@@ -177,7 +177,7 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
- _types = {"iids": types.CommaSeparatedListAttribute}
+ _types = {"iids": types.ArrayAttribute}
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py
index 354e56e..23f3d3c 100644
--- a/gitlab/v4/objects/projects.py
+++ b/gitlab/v4/objects/projects.py
@@ -125,7 +125,7 @@ class ProjectGroupManager(ListMixin, RESTManager):
"shared_min_access_level",
"shared_visible_only",
)
- _types = {"skip_groups": types.CommaSeparatedListAttribute}
+ _types = {"skip_groups": types.ArrayAttribute}
class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject):
diff --git a/gitlab/v4/objects/settings.py b/gitlab/v4/objects/settings.py
index 3075d9c..9be545c 100644
--- a/gitlab/v4/objects/settings.py
+++ b/gitlab/v4/objects/settings.py
@@ -80,12 +80,12 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
),
)
_types = {
- "asset_proxy_allowlist": types.CommaSeparatedListAttribute,
- "disabled_oauth_sign_in_sources": types.CommaSeparatedListAttribute,
- "domain_allowlist": types.CommaSeparatedListAttribute,
- "domain_denylist": types.CommaSeparatedListAttribute,
- "import_sources": types.CommaSeparatedListAttribute,
- "restricted_visibility_levels": types.CommaSeparatedListAttribute,
+ "asset_proxy_allowlist": types.ArrayAttribute,
+ "disabled_oauth_sign_in_sources": types.ArrayAttribute,
+ "domain_allowlist": types.ArrayAttribute,
+ "domain_denylist": types.ArrayAttribute,
+ "import_sources": types.ArrayAttribute,
+ "restricted_visibility_levels": types.ArrayAttribute,
}
@exc.on_http_error(exc.GitlabUpdateError)
diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py
index e3553b0..b2de337 100644
--- a/gitlab/v4/objects/users.py
+++ b/gitlab/v4/objects/users.py
@@ -369,7 +369,7 @@ class ProjectUserManager(ListMixin, RESTManager):
_obj_cls = ProjectUser
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("search", "skip_users")
- _types = {"skip_users": types.CommaSeparatedListAttribute}
+ _types = {"skip_users": types.ArrayAttribute}
class UserEmail(ObjectDeleteMixin, RESTObject):