| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Hello @prokher
Group labels have just been added to the Gitlab API and are not yet implemented in python-gitlab.
https://docs.gitlab.com/ce/api/group_labels.html: added in 11.8
Is there some roadmap/table for missing API functions?
I miss group labels too since we handle most our repositories with python-gitlab. I have a patch to add support for them, still testing, hope it helps:
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 16a3da8..edec6cb 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -969,6 +969,54 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
_list_filters = ("iids", "state", "search")
+class GroupLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
+ _id_attr = "name"
+
+ # Update without ID, but we need an ID to get from list.
+ @exc.on_http_error(exc.GitlabUpdateError)
+ def save(self, **kwargs):
+ """Saves the changes made to the object to the server.
+
+ The object is updated to match what the server returns.
+
+ Args:
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct.
+ GitlabUpdateError: If the server cannot perform the request.
+ """
+ updated_data = self._get_updated_data()
+
+ # call the manager
+ server_data = self.manager.update(None, updated_data, **kwargs)
+ self._update_attrs(server_data)
+
+
+class GroupLabelManager(
+ ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
+):
+ _path = "/groups/%(group_id)s/labels"
+ _obj_cls = GroupLabel
+ _from_parent_attrs = {"group_id": "id"}
+ _create_attrs = (("name", "color"), ("description", "priority"))
+ _update_attrs = (("name",), ("new_name", "color", "description", "priority"))
+
+ # Delete without ID.
+ @exc.on_http_error(exc.GitlabDeleteError)
+ def delete(self, name, **kwargs):
+ """Delete a Label on the server.
+
+ Args:
+ name: The name of the label
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabDeleteError: If the server cannot perform the request
+ """
+ self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
+
class GroupNotificationSettings(NotificationSettings):
pass
@@ -1042,6 +1090,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
("customattributes", "GroupCustomAttributeManager"),
("epics", "GroupEpicManager"),
("issues", "GroupIssueManager"),
+ ("labels", "GroupLabelManager"),
("members", "GroupMemberManager"),
("mergerequests", "GroupMergeRequestManager"),
("milestones", "GroupMilestoneManager"),@sidisel-albertolopez can you make a pull request with those changes? Thank you.
@sidisel-albertolopez Are you happy with the state of the patch? Do you have time to do a pull request so everyone can benefit from your work?
Just incase someone is looking for quick solution you can use something like below
# lab is instance of python-gitlab
lab.http_request('POST',"/groups/" + group + "/labels", query_data={}, post_data={
"name": "Stale",
"new_name": "Stale", # You can use same request to update the label, replace verb with PUT
"color": "#34495E",
"description": "Stale issue which has not been active for long time."
})
I have knowingly used verb, you can use put request.
Why build workarounds and patches if you can submit a pull request? I would be happy to review it.
@promethe42 Sorry for the delay. Thanks @sathieu
I have just published #847 which includes just the patch @sathieu have published in #845 with and extra commit for subscribable api support. I am not used to Github pull-request mechanism, so apologies if there is a better way to provide the extra commit than another pull-request.
@knackaron I have used it for quite a while with no issues or extra changes. But take into account the comments I include in #847. The GitLab GroupLabels API does not use the id to identify the label, just the name, which leads to ambiguity. It is a Gitlab REST server problem, not python-gitlab.
Thanks @sidisel-albertolopez . Tested and verified it works.
Also confirmed to work as part of gitlabracadabra/gitlabracadabra!36
| Back | FazBrowse Home | New Git URL |
Description of the problem, including code/CLI snippet
Cannot find a way to manipulate group labels.
Attempt to update the group label trough the project.labels interface leads to the error.
Code snippet:
gives the error:
when the label belongs to the group, not to the project.
Specifications