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

Commita57334f

Browse files
chore: create new ArrayAttribute class
Create a new ArrayAttribute class. This is to indicate types which aresent to the GitLab server as arrayshttps://docs.gitlab.com/ee/api/#arrayAt this stage it is identical to the CommaSeparatedListAttribute classbut will be used later to support the array types sent to GitLab.This is the second step in a series of steps of our goal to add fullsupport for the GitLab API data types[1]: * array * hash * array of hashesStep one was: commit5127b15[1]https://docs.gitlab.com/ee/api/#encoding-api-parameters-of-array-and-hash-typesRelated:#1698
1 parent7a13b9b commita57334f

File tree

10 files changed

+68
-49
lines changed

10 files changed

+68
-49
lines changed

‎gitlab/types.py‎

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

3434

35-
classCommaSeparatedListAttribute(GitlabAttribute):
35+
class_ListArrayAttribute(GitlabAttribute):
36+
"""Helper class to support `list` / `array` types."""
37+
3638
defset_from_cli(self,cli_value:str)->None:
3739
ifnotcli_value.strip():
3840
self._value= []
@@ -49,6 +51,17 @@ def get_for_api(self) -> str:
4951
return",".join([str(x)forxinself._value])
5052

5153

54+
classArrayAttribute(_ListArrayAttribute):
55+
"""To support `array` types as documented in
56+
https://docs.gitlab.com/ee/api/#array"""
57+
58+
59+
classCommaSeparatedListAttribute(_ListArrayAttribute):
60+
"""For values which are sent to the server as a Comma Separated Values
61+
(CSV) string. We allow them to be specified as a list and we convert it
62+
into a CSV"""
63+
64+
5265
classLowercaseStringAttribute(GitlabAttribute):
5366
defget_for_api(self)->str:
5467
returnstr(self._value).lower()

‎gitlab/v4/objects/groups.py‎

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

322319
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->Group:
323320
returncast(Group,super().get(id=id,lazy=lazy,**kwargs))
@@ -377,7 +374,7 @@ class GroupSubgroupManager(ListMixin, RESTManager):
377374
"with_custom_attributes",
378375
"min_access_level",
379376
)
380-
_types= {"skip_groups":types.CommaSeparatedListAttribute}
377+
_types= {"skip_groups":types.ArrayAttribute}
381378

382379

383380
classGroupDescendantGroup(RESTObject):

‎gitlab/v4/objects/issues.py‎

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

7370
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->Issue:
7471
returncast(Issue,super().get(id=id,lazy=lazy,**kwargs))
@@ -98,10 +95,7 @@ class GroupIssueManager(ListMixin, RESTManager):
9895
"updated_after",
9996
"updated_before",
10097
)
101-
_types= {
102-
"iids":types.CommaSeparatedListAttribute,
103-
"labels":types.CommaSeparatedListAttribute,
104-
}
98+
_types= {"iids":types.ArrayAttribute,"labels":types.CommaSeparatedListAttribute}
10599

106100

107101
classProjectIssue(
@@ -239,10 +233,7 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
239233
"discussion_locked",
240234
),
241235
)
242-
_types= {
243-
"iids":types.CommaSeparatedListAttribute,
244-
"labels":types.CommaSeparatedListAttribute,
245-
}
236+
_types= {"iids":types.ArrayAttribute,"labels":types.CommaSeparatedListAttribute}
246237

247238
defget(
248239
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.CommaSeparatedListAttribute}
44+
_types= {"user_ids":types.ArrayAttribute}
4545

4646
defget(
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.CommaSeparatedListAttribute}
104+
_types= {"user_ids":types.ArrayAttribute}
105105

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

‎gitlab/v4/objects/merge_requests.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class MergeRequestManager(ListMixin, RESTManager):
9595
"deployed_after",
9696
)
9797
_types= {
98-
"approver_ids":types.CommaSeparatedListAttribute,
99-
"approved_by_ids":types.CommaSeparatedListAttribute,
98+
"approver_ids":types.ArrayAttribute,
99+
"approved_by_ids":types.ArrayAttribute,
100100
"in":types.CommaSeparatedListAttribute,
101101
"labels":types.CommaSeparatedListAttribute,
102102
}
@@ -133,8 +133,8 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
133133
"wip",
134134
)
135135
_types= {
136-
"approver_ids":types.CommaSeparatedListAttribute,
137-
"approved_by_ids":types.CommaSeparatedListAttribute,
136+
"approver_ids":types.ArrayAttribute,
137+
"approved_by_ids":types.ArrayAttribute,
138138
"labels":types.CommaSeparatedListAttribute,
139139
}
140140

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

‎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.CommaSeparatedListAttribute}
96+
_types= {"iids":types.ArrayAttribute}
9797

9898
defget(
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.CommaSeparatedListAttribute}
180+
_types= {"iids":types.ArrayAttribute}
181181

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

‎gitlab/v4/objects/projects.py‎

Lines changed: 1 addition & 1 deletion
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.CommaSeparatedListAttribute}
128+
_types= {"skip_groups":types.ArrayAttribute}
129129

130130

131131
classProject(RefreshMixin,SaveMixin,ObjectDeleteMixin,RepositoryMixin,RESTObject):

‎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.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,
83+
"asset_proxy_allowlist":types.ArrayAttribute,
84+
"disabled_oauth_sign_in_sources":types.ArrayAttribute,
85+
"domain_allowlist":types.ArrayAttribute,
86+
"domain_denylist":types.ArrayAttribute,
87+
"import_sources":types.ArrayAttribute,
88+
"restricted_visibility_levels":types.ArrayAttribute,
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.CommaSeparatedListAttribute}
372+
_types= {"skip_users":types.ArrayAttribute}
373373

374374

375375
classUserEmail(ObjectDeleteMixin,RESTObject):

‎tests/unit/test_types.py‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,63 @@ def test_gitlab_attribute_get():
3030
asserto._valueisNone
3131

3232

33-
deftest_csv_list_attribute_input():
34-
o=types.CommaSeparatedListAttribute()
33+
deftest_array_attribute_input():
34+
o=types.ArrayAttribute()
3535
o.set_from_cli("foo,bar,baz")
3636
asserto.get()== ["foo","bar","baz"]
3737

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

4141

42-
deftest_csv_list_attribute_empty_input():
43-
o=types.CommaSeparatedListAttribute()
42+
deftest_array_attribute_empty_input():
43+
o=types.ArrayAttribute()
4444
o.set_from_cli("")
4545
asserto.get()== []
4646

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

5050

51-
deftest_csv_list_attribute_get_for_api_from_cli():
52-
o=types.CommaSeparatedListAttribute()
51+
deftest_array_attribute_get_for_api_from_cli():
52+
o=types.ArrayAttribute()
5353
o.set_from_cli("foo,bar,baz")
5454
asserto.get_for_api()=="foo,bar,baz"
5555

5656

57-
deftest_csv_list_attribute_get_for_api_from_list():
58-
o=types.CommaSeparatedListAttribute(["foo","bar","baz"])
57+
deftest_array_attribute_get_for_api_from_list():
58+
o=types.ArrayAttribute(["foo","bar","baz"])
5959
asserto.get_for_api()=="foo,bar,baz"
6060

6161

62-
deftest_csv_list_attribute_get_for_api_from_int_list():
63-
o=types.CommaSeparatedListAttribute([1,9,7])
62+
deftest_array_attribute_get_for_api_from_int_list():
63+
o=types.ArrayAttribute([1,9,7])
6464
asserto.get_for_api()=="1,9,7"
6565

6666

67-
deftest_csv_list_attribute_does_not_split_string():
68-
o=types.CommaSeparatedListAttribute("foo")
67+
deftest_array_attribute_does_not_split_string():
68+
o=types.ArrayAttribute("foo")
6969
asserto.get_for_api()=="foo"
7070

7171

72+
# CommaSeparatedListAttribute tests
73+
deftest_csv_string_attribute_get_for_api_from_cli():
74+
o=types.CommaSeparatedListAttribute()
75+
o.set_from_cli("foo,bar,baz")
76+
asserto.get_for_api()=="foo,bar,baz"
77+
78+
79+
deftest_csv_string_attribute_get_for_api_from_list():
80+
o=types.CommaSeparatedListAttribute(["foo","bar","baz"])
81+
asserto.get_for_api()=="foo,bar,baz"
82+
83+
84+
deftest_csv_string_attribute_get_for_api_from_int_list():
85+
o=types.CommaSeparatedListAttribute([1,9,7])
86+
asserto.get_for_api()=="1,9,7"
87+
88+
89+
# LowercaseStringAttribute tests
7290
deftest_lowercase_string_attribute_get_for_api():
7391
o=types.LowercaseStringAttribute("FOO")
7492
asserto.get_for_api()=="foo"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp