FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cannot create/update group labels · Issue #698 · python-gitlab/python-gitlab · GitHub

Repository navigation

Cannot create/update group labels #698

Description

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:

project = gl.projects.get(...)
labels = project.labels.list()
label = labels[0]
label.color = "#FFF"
label.save()

gives the error:

gitlab.exceptions.GitlabHttpError: 404: 404 Label not found Not Found

when the label belongs to the group, not to the project.

Specifications

  • python-gitlab version: 1.7.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 11.6.0-ee

Activity

  1. changed the title [-]Cannot create/update group label[/-] [+]Cannot create/update group labels[/+] on Feb 8, 2019
  2. gpocentek commented on Feb 10, 2019

    Contributor

    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

  3. koliyo commented on Apr 12, 2019

    Is there some roadmap/table for missing API functions?

  4. sidisel-albertolopez commented on May 24, 2019

    Contributor

    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"),
  5. JMLX42 commented on Jul 3, 2019

    @sidisel-albertolopez can you make a pull request with those changes? Thank you.

  6. knackaron commented on Jul 20, 2019

    @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?

  7. m301 commented on Jul 22, 2019

    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.

  8. max-wittig commented on Jul 22, 2019

    Member

    Why build workarounds and patches if you can submit a pull request? I would be happy to review it.

  9. added 3 commits that reference this issue on Jul 25, 2019
    5b4d075
    d90946b
    e2413ac
  10. sidisel-albertolopez commented on Jul 25, 2019

    Contributor

    @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.

  11. knackaron commented on Jul 25, 2019

    Thanks @sidisel-albertolopez . Tested and verified it works.

  12. sathieu commented on Jul 26, 2019

    Contributor

    Also confirmed to work as part of gitlabracadabra/gitlabracadabra!36

  13. locked as resolved and limited conversation to collaborators on Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL