diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-06-17 16:20:50 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-06-17 16:20:50 +0200 |
commit | ba90e305bc2d54eb42aa0f8251a9e45b0d1736e4 (patch) | |
tree | 7c220ff08ba92f203a0adf92b26633c6ba4f675a /gitlab | |
parent | b2cb70016e4fd2baa1f136a17946a474f1b18f24 (diff) | |
download | gitlab-ba90e305bc2d54eb42aa0f8251a9e45b0d1736e4.tar.gz |
Add support for epics API (EE)
Fixes #525
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/v4/objects.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 7231919..3e16bac 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -602,6 +602,83 @@ class GroupCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, _from_parent_attrs = {'group_id': 'id'} +class GroupEpicIssue(ObjectDeleteMixin, SaveMixin, RESTObject): + _id_attr = 'epic_issue_id' + + def save(self, **kwargs): + """Save 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) + + Raise: + GitlabAuthenticationError: If authentication is not correct + GitlabUpdateError: If the server cannot perform the request + """ + updated_data = self._get_updated_data() + # Nothing to update. Server fails if sent an empty dict. + if not updated_data: + return + + # call the manager + obj_id = self.get_id() + self.manager.update(obj_id, updated_data, **kwargs) + + +class GroupEpicIssueManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, + RESTManager): + _path = '/groups/%(group_id)s/epics/%(epic_iid)s/issues' + _obj_cls = GroupEpicIssue + _from_parent_attrs = {'group_id': 'group_id', 'epic_iid': 'iid'} + _create_attrs = (('issue_id',), tuple()) + _update_attrs = (tuple(), ('move_before_id', 'move_after_id')) + + @exc.on_http_error(exc.GitlabCreateError) + def create(self, data, **kwargs): + """Create a new object. + + Args: + data (dict): Parameters to send to the server to create the + resource + **kwargs: Extra data to send to the Gitlab server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabCreateError: If the server cannot perform the request + + Returns: + RESTObject: A new instance of the manage object class build with + the data sent by the server + """ + CreateMixin._check_missing_create_attrs(self, data) + path = '%s/%s' % (self.path, data.pop('issue_id')) + server_data = self.gitlab.http_post(path, **kwargs) + # The epic_issue_id attribute doesn't exist when creating the resource, + # but is used everywhere elese. Let's create it to be consistent client + # side + server_data['epic_issue_id'] = server_data['id'] + return self._obj_cls(self, server_data) + + +class GroupEpic(ObjectDeleteMixin, SaveMixin, RESTObject): + _id_attr = 'iid' + _managers = (('issues', 'GroupEpicIssueManager'),) + + +class GroupEpicManager(CRUDMixin, RESTManager): + _path = '/groups/%(group_id)s/epics' + _obj_cls = GroupEpic + _from_parent_attrs = {'group_id': 'id'} + _list_filters = ('author_id', 'labels', 'order_by', 'sort', 'search') + _create_attrs = (('title',), + ('labels', 'description', 'start_date', 'end_date')) + _update_attrs = (tuple(), ('title', 'labels', 'description', 'start_date', + 'end_date')) + _types = {'labels': types.ListAttribute} + + class GroupIssue(RESTObject): pass @@ -762,6 +839,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): ('badges', 'GroupBadgeManager'), ('boards', 'GroupBoardManager'), ('customattributes', 'GroupCustomAttributeManager'), + ('epics', 'GroupEpicManager'), ('issues', 'GroupIssueManager'), ('members', 'GroupMemberManager'), ('milestones', 'GroupMilestoneManager'), |