Skip to content

Commit 5b4d075

Browse files
committed
Add support for group labels
Fixes: #698
1 parent 2c1ea56 commit 5b4d075

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

gitlab/v4/objects.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,55 @@ class GroupIssueManager(ListMixin, RESTManager):
833833
_types = {"labels": types.ListAttribute}
834834

835835

836+
class GroupLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
837+
_id_attr = "name"
838+
839+
# Update without ID, but we need an ID to get from list.
840+
@exc.on_http_error(exc.GitlabUpdateError)
841+
def save(self, **kwargs):
842+
"""Saves the changes made to the object to the server.
843+
844+
The object is updated to match what the server returns.
845+
846+
Args:
847+
**kwargs: Extra options to send to the server (e.g. sudo)
848+
849+
Raises:
850+
GitlabAuthenticationError: If authentication is not correct.
851+
GitlabUpdateError: If the server cannot perform the request.
852+
"""
853+
updated_data = self._get_updated_data()
854+
855+
# call the manager
856+
server_data = self.manager.update(None, updated_data, **kwargs)
857+
self._update_attrs(server_data)
858+
859+
860+
class GroupLabelManager(
861+
ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
862+
):
863+
_path = "/groups/%(group_id)s/labels"
864+
_obj_cls = GroupLabel
865+
_from_parent_attrs = {"group_id": "id"}
866+
_create_attrs = (("name", "color"), ("description", "priority"))
867+
_update_attrs = (("name",), ("new_name", "color", "description", "priority"))
868+
869+
# Delete without ID.
870+
@exc.on_http_error(exc.GitlabDeleteError)
871+
def delete(self, name, **kwargs):
872+
"""Delete a Label on the server.
873+
874+
Args:
875+
name: The name of the label
876+
**kwargs: Extra options to send to the server (e.g. sudo)
877+
878+
Raises:
879+
GitlabAuthenticationError: If authentication is not correct
880+
GitlabDeleteError: If the server cannot perform the request
881+
"""
882+
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
883+
884+
836885
class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject):
837886
_short_print_attr = "username"
838887

@@ -1042,6 +1091,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
10421091
("customattributes", "GroupCustomAttributeManager"),
10431092
("epics", "GroupEpicManager"),
10441093
("issues", "GroupIssueManager"),
1094+
("labels", "GroupLabelManager"),
10451095
("members", "GroupMemberManager"),
10461096
("mergerequests", "GroupMergeRequestManager"),
10471097
("milestones", "GroupMilestoneManager"),

0 commit comments

Comments
 (0)