Skip to content

Commit 5127b15

Browse files
chore: rename types.ListAttribute to types.CommaSeparatedListAttribute
This name more accurately describes what the type is. Also this is the first step in a series of steps of our goal to add full support for the GitLab API data types[1]: * array * hash * array of hashes [1] https://docs.gitlab.com/ee/api/#encoding-api-parameters-of-array-and-hash-types
1 parent 07539c9 commit 5127b15

File tree

13 files changed

+63
-48
lines changed

13 files changed

+63
-48
lines changed

gitlab/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_for_api(self) -> Any:
3232
return self._value
3333

3434

35-
class ListAttribute(GitlabAttribute):
35+
class CommaSeparatedListAttribute(GitlabAttribute):
3636
def set_from_cli(self, cli_value: str) -> None:
3737
if not cli_value.strip():
3838
self._value = []

gitlab/v4/objects/deploy_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
3939
"username",
4040
),
4141
)
42-
_types = {"scopes": types.ListAttribute}
42+
_types = {"scopes": types.CommaSeparatedListAttribute}
4343

4444

4545
class ProjectDeployToken(ObjectDeleteMixin, RESTObject):
@@ -60,4 +60,4 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager
6060
"username",
6161
),
6262
)
63-
_types = {"scopes": types.ListAttribute}
63+
_types = {"scopes": types.CommaSeparatedListAttribute}

gitlab/v4/objects/epics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GroupEpicManager(CRUDMixin, RESTManager):
4242
_update_attrs = RequiredOptional(
4343
optional=("title", "labels", "description", "start_date", "end_date"),
4444
)
45-
_types = {"labels": types.ListAttribute}
45+
_types = {"labels": types.CommaSeparatedListAttribute}
4646

4747
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupEpic:
4848
return cast(GroupEpic, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/groups.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ class GroupManager(CRUDMixin, RESTManager):
314314
"shared_runners_setting",
315315
),
316316
)
317-
_types = {"avatar": types.ImageAttribute, "skip_groups": types.ListAttribute}
317+
_types = {
318+
"avatar": types.ImageAttribute,
319+
"skip_groups": types.CommaSeparatedListAttribute,
320+
}
318321

319322
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Group:
320323
return cast(Group, super().get(id=id, lazy=lazy, **kwargs))
@@ -374,7 +377,7 @@ class GroupSubgroupManager(ListMixin, RESTManager):
374377
"with_custom_attributes",
375378
"min_access_level",
376379
)
377-
_types = {"skip_groups": types.ListAttribute}
380+
_types = {"skip_groups": types.CommaSeparatedListAttribute}
378381

379382

380383
class GroupDescendantGroup(RESTObject):

gitlab/v4/objects/issues.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class IssueManager(RetrieveMixin, RESTManager):
6565
"updated_after",
6666
"updated_before",
6767
)
68-
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
68+
_types = {
69+
"iids": types.CommaSeparatedListAttribute,
70+
"labels": types.CommaSeparatedListAttribute,
71+
}
6972

7073
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Issue:
7174
return cast(Issue, super().get(id=id, lazy=lazy, **kwargs))
@@ -95,7 +98,10 @@ class GroupIssueManager(ListMixin, RESTManager):
9598
"updated_after",
9699
"updated_before",
97100
)
98-
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
101+
_types = {
102+
"iids": types.CommaSeparatedListAttribute,
103+
"labels": types.CommaSeparatedListAttribute,
104+
}
99105

100106

101107
class ProjectIssue(
@@ -233,7 +239,10 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
233239
"discussion_locked",
234240
),
235241
)
236-
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
242+
_types = {
243+
"iids": types.CommaSeparatedListAttribute,
244+
"labels": types.CommaSeparatedListAttribute,
245+
}
237246

238247
def get(
239248
self, id: Union[str, int], lazy: bool = False, **kwargs: Any

gitlab/v4/objects/members.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GroupMemberManager(CRUDMixin, RESTManager):
4141
_update_attrs = RequiredOptional(
4242
required=("access_level",), optional=("expires_at",)
4343
)
44-
_types = {"user_ids": types.ListAttribute}
44+
_types = {"user_ids": types.CommaSeparatedListAttribute}
4545

4646
def get(
4747
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
@@ -101,7 +101,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
101101
_update_attrs = RequiredOptional(
102102
required=("access_level",), optional=("expires_at",)
103103
)
104-
_types = {"user_ids": types.ListAttribute}
104+
_types = {"user_ids": types.CommaSeparatedListAttribute}
105105

106106
def get(
107107
self, id: Union[str, int], lazy: bool = False, **kwargs: Any

gitlab/v4/objects/merge_requests.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ class MergeRequestManager(ListMixin, RESTManager):
9595
"deployed_after",
9696
)
9797
_types = {
98-
"approver_ids": types.ListAttribute,
99-
"approved_by_ids": types.ListAttribute,
100-
"in": types.ListAttribute,
101-
"labels": types.ListAttribute,
98+
"approver_ids": types.CommaSeparatedListAttribute,
99+
"approved_by_ids": types.CommaSeparatedListAttribute,
100+
"in": types.CommaSeparatedListAttribute,
101+
"labels": types.CommaSeparatedListAttribute,
102102
}
103103

104104

@@ -133,9 +133,9 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
133133
"wip",
134134
)
135135
_types = {
136-
"approver_ids": types.ListAttribute,
137-
"approved_by_ids": types.ListAttribute,
138-
"labels": types.ListAttribute,
136+
"approver_ids": types.CommaSeparatedListAttribute,
137+
"approved_by_ids": types.CommaSeparatedListAttribute,
138+
"labels": types.CommaSeparatedListAttribute,
139139
}
140140

141141

@@ -455,10 +455,10 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
455455
"wip",
456456
)
457457
_types = {
458-
"approver_ids": types.ListAttribute,
459-
"approved_by_ids": types.ListAttribute,
460-
"iids": types.ListAttribute,
461-
"labels": types.ListAttribute,
458+
"approver_ids": types.CommaSeparatedListAttribute,
459+
"approved_by_ids": types.CommaSeparatedListAttribute,
460+
"iids": types.CommaSeparatedListAttribute,
461+
"labels": types.CommaSeparatedListAttribute,
462462
}
463463

464464
def get(

gitlab/v4/objects/milestones.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
9393
optional=("title", "description", "due_date", "start_date", "state_event"),
9494
)
9595
_list_filters = ("iids", "state", "search")
96-
_types = {"iids": types.ListAttribute}
96+
_types = {"iids": types.CommaSeparatedListAttribute}
9797

9898
def get(
9999
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
@@ -177,7 +177,7 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
177177
optional=("title", "description", "due_date", "start_date", "state_event"),
178178
)
179179
_list_filters = ("iids", "state", "search")
180-
_types = {"iids": types.ListAttribute}
180+
_types = {"iids": types.CommaSeparatedListAttribute}
181181

182182
def get(
183183
self, id: Union[str, int], lazy: bool = False, **kwargs: Any

gitlab/v4/objects/projects.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ProjectGroupManager(ListMixin, RESTManager):
125125
"shared_min_access_level",
126126
"shared_visible_only",
127127
)
128-
_types = {"skip_groups": types.ListAttribute}
128+
_types = {"skip_groups": types.CommaSeparatedListAttribute}
129129

130130

131131
class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject):
@@ -807,7 +807,10 @@ class ProjectManager(CRUDMixin, RESTManager):
807807
"with_merge_requests_enabled",
808808
"with_programming_language",
809809
)
810-
_types = {"avatar": types.ImageAttribute, "topic": types.ListAttribute}
810+
_types = {
811+
"avatar": types.ImageAttribute,
812+
"topic": types.CommaSeparatedListAttribute,
813+
}
811814

812815
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Project:
813816
return cast(Project, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/runners.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class RunnerManager(CRUDMixin, RESTManager):
6868
),
6969
)
7070
_list_filters = ("scope", "tag_list")
71-
_types = {"tag_list": types.ListAttribute}
71+
_types = {"tag_list": types.CommaSeparatedListAttribute}
7272

7373
@cli.register_custom_action("RunnerManager", tuple(), ("scope",))
7474
@exc.on_http_error(exc.GitlabListError)
@@ -130,7 +130,7 @@ class GroupRunnerManager(ListMixin, RESTManager):
130130
_from_parent_attrs = {"group_id": "id"}
131131
_create_attrs = RequiredOptional(required=("runner_id",))
132132
_list_filters = ("scope", "tag_list")
133-
_types = {"tag_list": types.ListAttribute}
133+
_types = {"tag_list": types.CommaSeparatedListAttribute}
134134

135135

136136
class ProjectRunner(ObjectDeleteMixin, RESTObject):
@@ -143,4 +143,4 @@ class ProjectRunnerManager(CreateMixin, DeleteMixin, ListMixin, RESTManager):
143143
_from_parent_attrs = {"project_id": "id"}
144144
_create_attrs = RequiredOptional(required=("runner_id",))
145145
_list_filters = ("scope", "tag_list")
146-
_types = {"tag_list": types.ListAttribute}
146+
_types = {"tag_list": types.CommaSeparatedListAttribute}

gitlab/v4/objects/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
8080
),
8181
)
8282
_types = {
83-
"asset_proxy_allowlist": types.ListAttribute,
84-
"disabled_oauth_sign_in_sources": types.ListAttribute,
85-
"domain_allowlist": types.ListAttribute,
86-
"domain_denylist": types.ListAttribute,
87-
"import_sources": types.ListAttribute,
88-
"restricted_visibility_levels": types.ListAttribute,
83+
"asset_proxy_allowlist": types.CommaSeparatedListAttribute,
84+
"disabled_oauth_sign_in_sources": types.CommaSeparatedListAttribute,
85+
"domain_allowlist": types.CommaSeparatedListAttribute,
86+
"domain_denylist": types.CommaSeparatedListAttribute,
87+
"import_sources": types.CommaSeparatedListAttribute,
88+
"restricted_visibility_levels": types.CommaSeparatedListAttribute,
8989
}
9090

9191
@exc.on_http_error(exc.GitlabUpdateError)

gitlab/v4/objects/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class ProjectUserManager(ListMixin, RESTManager):
369369
_obj_cls = ProjectUser
370370
_from_parent_attrs = {"project_id": "id"}
371371
_list_filters = ("search", "skip_users")
372-
_types = {"skip_users": types.ListAttribute}
372+
_types = {"skip_users": types.CommaSeparatedListAttribute}
373373

374374

375375
class UserEmail(ObjectDeleteMixin, RESTObject):

tests/unit/test_types.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,42 @@ def test_gitlab_attribute_get():
3030
assert o._value is None
3131

3232

33-
def test_list_attribute_input():
34-
o = types.ListAttribute()
33+
def test_csv_list_attribute_input():
34+
o = types.CommaSeparatedListAttribute()
3535
o.set_from_cli("foo,bar,baz")
3636
assert o.get() == ["foo", "bar", "baz"]
3737

3838
o.set_from_cli("foo")
3939
assert o.get() == ["foo"]
4040

4141

42-
def test_list_attribute_empty_input():
43-
o = types.ListAttribute()
42+
def test_csv_list_attribute_empty_input():
43+
o = types.CommaSeparatedListAttribute()
4444
o.set_from_cli("")
4545
assert o.get() == []
4646

4747
o.set_from_cli(" ")
4848
assert o.get() == []
4949

5050

51-
def test_list_attribute_get_for_api_from_cli():
52-
o = types.ListAttribute()
51+
def test_csv_list_attribute_get_for_api_from_cli():
52+
o = types.CommaSeparatedListAttribute()
5353
o.set_from_cli("foo,bar,baz")
5454
assert o.get_for_api() == "foo,bar,baz"
5555

5656

57-
def test_list_attribute_get_for_api_from_list():
58-
o = types.ListAttribute(["foo", "bar", "baz"])
57+
def test_csv_list_attribute_get_for_api_from_list():
58+
o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"])
5959
assert o.get_for_api() == "foo,bar,baz"
6060

6161

62-
def test_list_attribute_get_for_api_from_int_list():
63-
o = types.ListAttribute([1, 9, 7])
62+
def test_csv_list_attribute_get_for_api_from_int_list():
63+
o = types.CommaSeparatedListAttribute([1, 9, 7])
6464
assert o.get_for_api() == "1,9,7"
6565

6666

67-
def test_list_attribute_does_not_split_string():
68-
o = types.ListAttribute("foo")
67+
def test_csv_list_attribute_does_not_split_string():
68+
o = types.CommaSeparatedListAttribute("foo")
6969
assert o.get_for_api() == "foo"
7070

7171

0 commit comments

Comments
 (0)