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

Commit9c0d7a7

Browse files
fix: remove customdelete method for labels
The usage of deleting was incorrect according to the current API.Remove custom `delete()` method as not needed.Add tests to show it works with labels needing to be encoded.Also enable the test_group_labels() test function. Previously it wasdisabled.Add ability to do a `get()` for group labels.Closes:#1867
1 parent7646360 commit9c0d7a7

File tree

3 files changed

+17
-44
lines changed

3 files changed

+17
-44
lines changed

‎gitlab/v4/objects/labels.py‎

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
fromtypingimportAny,cast,Dict,Optional,TYPE_CHECKING,Union
1+
fromtypingimportAny,cast,Dict,Optional,Union
22

33
fromgitlabimportexceptionsasexc
44
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
55
fromgitlab.mixinsimport (
66
CreateMixin,
77
DeleteMixin,
8-
ListMixin,
98
ObjectDeleteMixin,
109
PromoteMixin,
1110
RetrieveMixin,
@@ -47,7 +46,9 @@ def save(self, **kwargs: Any) -> None:
4746
self._update_attrs(server_data)
4847

4948

50-
classGroupLabelManager(ListMixin,CreateMixin,UpdateMixin,DeleteMixin,RESTManager):
49+
classGroupLabelManager(
50+
RetrieveMixin,CreateMixin,UpdateMixin,DeleteMixin,RESTManager
51+
):
5152
_path="/groups/{group_id}/labels"
5253
_obj_cls=GroupLabel
5354
_from_parent_attrs= {"group_id":"id"}
@@ -58,6 +59,9 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
5859
required=("name",),optional=("new_name","color","description","priority")
5960
)
6061

62+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->GroupLabel:
63+
returncast(GroupLabel,super().get(id=id,lazy=lazy,**kwargs))
64+
6165
# Update without ID.
6266
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
6367
# type error
@@ -78,25 +82,6 @@ def update( # type: ignore
7882
new_data["name"]=name
7983
returnsuper().update(id=None,new_data=new_data,**kwargs)
8084

81-
# Delete without ID.
82-
@exc.on_http_error(exc.GitlabDeleteError)
83-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84-
# type error
85-
defdelete(self,name:str,**kwargs:Any)->None:# type: ignore
86-
"""Delete a Label on the server.
87-
88-
Args:
89-
name: The name of the label
90-
**kwargs: Extra options to send to the server (e.g. sudo)
91-
92-
Raises:
93-
GitlabAuthenticationError: If authentication is not correct
94-
GitlabDeleteError: If the server cannot perform the request
95-
"""
96-
ifTYPE_CHECKING:
97-
assertself.pathisnotNone
98-
self.gitlab.http_delete(self.path,query_data={"name":name},**kwargs)
99-
10085

10186
classProjectLabel(
10287
PromoteMixin,SubscribableMixin,SaveMixin,ObjectDeleteMixin,RESTObject
@@ -162,22 +147,3 @@ def update( # type: ignore
162147
ifname:
163148
new_data["name"]=name
164149
returnsuper().update(id=None,new_data=new_data,**kwargs)
165-
166-
# Delete without ID.
167-
@exc.on_http_error(exc.GitlabDeleteError)
168-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169-
# type error
170-
defdelete(self,name:str,**kwargs:Any)->None:# type: ignore
171-
"""Delete a Label on the server.
172-
173-
Args:
174-
name: The name of the label
175-
**kwargs: Extra options to send to the server (e.g. sudo)
176-
177-
Raises:
178-
GitlabAuthenticationError: If authentication is not correct
179-
GitlabDeleteError: If the server cannot perform the request
180-
"""
181-
ifTYPE_CHECKING:
182-
assertself.pathisnotNone
183-
self.gitlab.http_delete(self.path,query_data={"name":name},**kwargs)

‎tests/functional/api/test_groups.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def test_groups(gl):
104104
group2.members.delete(gl.user.id)
105105

106106

107-
@pytest.mark.skip(reason="Commented out in legacy test")
108107
deftest_group_labels(group):
109108
group.labels.create({"name":"foo","description":"bar","color":"#112233"})
110109
label=group.labels.get("foo")
@@ -116,6 +115,12 @@ def test_group_labels(group):
116115
assertlabel.description=="baz"
117116
assertlen(group.labels.list())==1
118117

118+
label.new_name="comp:Flat Export"
119+
label.save()
120+
assertlabel.name=="comp:Flat Export"
121+
label=group.labels.get("comp:Flat Export")
122+
assertlabel.name=="comp:Flat Export"
123+
119124
label.delete()
120125
assertlen(group.labels.list())==0
121126

‎tests/functional/api/test_projects.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ def test_project_labels(project):
146146
label=project.labels.get("label")
147147
assertlabel==labels[0]
148148

149-
label.new_name="labelupdated"
149+
label.new_name="comp:Flat Export"
150150
label.save()
151-
assertlabel.name=="labelupdated"
151+
assertlabel.name=="comp:Flat Export"
152+
label=project.labels.get("comp:Flat Export")
153+
assertlabel.name=="comp:Flat Export"
152154

153155
label.subscribe()
154156
assertlabel.subscribedisTrue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp