diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-28 14:09:21 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-28 14:09:21 +0200 |
commit | e901f440d787c1fd43fdba1838a1f37066329ccf (patch) | |
tree | f37c6565a8676d38941b2385619db9a2f403fe24 | |
parent | 4ec8975982290f3950d629f0fd7c73f351ead84f (diff) | |
download | gitlab-e901f440d787c1fd43fdba1838a1f37066329ccf.tar.gz |
Issues: add missing attributes and methods
-rw-r--r-- | docs/gl_objects/issues.rst | 8 | ||||
-rw-r--r-- | gitlab/mixins.py | 26 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 77 | ||||
-rw-r--r-- | tools/python_test_v4.py | 3 |
4 files changed, 78 insertions, 36 deletions
diff --git a/docs/gl_objects/issues.rst b/docs/gl_objects/issues.rst index 2f58dd6..027d5bc 100644 --- a/docs/gl_objects/issues.rst +++ b/docs/gl_objects/issues.rst @@ -145,3 +145,11 @@ Reset spent time for an issue:: Get user agent detail for the issue (admin only):: detail = issue.user_agent_detail() + +Get the list of merge requests that will close an issue when merged:: + + mrs = issue.closed_by() + +Get the list of participants:: + + users = issue.participants() diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 988042b..7148ccd 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -545,3 +545,29 @@ class TimeTrackingMixin(object): """ path = '%s/%s/reset_spent_time' % (self.manager.path, self.get_id()) return self.manager.gitlab.http_post(path, **kwargs) + + +class ParticipantsMixin(object): + @cli.register_custom_action('ProjectMergeRequest', 'ProjectIssue') + @exc.on_http_error(exc.GitlabListError) + def participants(self, **kwargs): + """List the participants. + + Args: + all (bool): If True, return all the items, without pagination + per_page (int): Number of items to retrieve per request + page (int): ID of the page to return (starts with page 1) + as_list (bool): If set to False and no pagination option is + defined, return a generator instead of a list + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabListError: If the list could not be retrieved + + Returns: + RESTObjectList: The list of participants + """ + + path = '%s/%s/participants' % (self.manager.path, self.get_id()) + return self.manager.gitlab.http_get(path, **kwargs) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 7f9ca85..2be505e 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -542,7 +542,10 @@ class GroupIssueManager(ListMixin, RESTManager): _path = '/groups/%(group_id)s/issues' _obj_cls = GroupIssue _from_parent_attrs = {'group_id': 'id'} - _list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort') + _list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort', + 'iids', 'author_id', 'assignee_id', 'my_reaction_emoji', + 'search', 'created_after', 'created_before', + 'updated_after', 'updated_before') _types = {'labels': types.ListAttribute} @@ -772,7 +775,10 @@ class Issue(RESTObject): class IssueManager(ListMixin, RESTManager): _path = '/issues' _obj_cls = Issue - _list_filters = ('state', 'labels', 'order_by', 'sort') + _list_filters = ('state', 'labels', 'milestone', 'scope', 'author_id', + 'assignee_id', 'my_reaction_emoji', 'iids', 'order_by', + 'sort', 'search', 'created_after', 'created_before', + 'updated_after', 'updated_before') _types = {'labels': types.ListAttribute} @@ -1440,8 +1446,8 @@ class ProjectIssueDiscussionManager(RetrieveMixin, CreateMixin, RESTManager): class ProjectIssue(UserAgentDetailMixin, SubscribableMixin, TodoMixin, - TimeTrackingMixin, SaveMixin, ObjectDeleteMixin, - RESTObject): + TimeTrackingMixin, ParticipantsMixin, SaveMixin, + ObjectDeleteMixin, RESTObject): _short_print_attr = 'title' _id_attr = 'iid' _managers = ( @@ -1469,18 +1475,42 @@ class ProjectIssue(UserAgentDetailMixin, SubscribableMixin, TodoMixin, **kwargs) self._update_attrs(server_data) + @cli.register_custom_action('ProjectIssue') + @exc.on_http_error(exc.GitlabGetError) + def closed_by(self, **kwargs): + """List merge requests that will close the issue when merged. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabGetErrot: If the merge requests could not be retrieved + + Returns: + list: The list of merge requests. + """ + path = '%s/%s/closed_by' % (self.manager.path, self.get_id()) + return self.manager.gitlab.http_get(path, **kwargs) + class ProjectIssueManager(CRUDMixin, RESTManager): _path = '/projects/%(project_id)s/issues/' _obj_cls = ProjectIssue _from_parent_attrs = {'project_id': 'id'} - _list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort') + _list_filters = ('iids', 'state', 'labels', 'milestone', 'scope', + 'author_id', 'assignee_id', 'my_reaction_emoji', + 'order_by', 'sort', 'search', 'created_after', + 'created_before', 'updated_after', 'updated_before') _create_attrs = (('title', ), - ('description', 'assignee_id', 'milestone_id', 'labels', - 'created_at', 'due_date')) - _update_attrs = (tuple(), ('title', 'description', 'assignee_id', - 'milestone_id', 'labels', 'created_at', - 'updated_at', 'state_event', 'due_date')) + ('description', 'confidential', 'assignee_id', + 'assignee_idss' 'milestone_id', 'labels', 'created_at', + 'due_date', 'merge_request_to_resolve_discussions_of' , + 'discussion_to_resolve')) + _update_attrs = (tuple(), ('title', 'description', 'confidential', + 'assignee_ids', 'assignee_id', 'milestone_id', + 'labels', 'state_event', 'updated_at', + 'due_date', 'discussion_locked')) _types = {'labels': types.ListAttribute} @@ -1655,7 +1685,8 @@ class ProjectMergeRequestDiscussionManager(RetrieveMixin, CreateMixin, class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin, - SaveMixin, ObjectDeleteMixin, RESTObject): + ParticipantsMixin, SaveMixin, ObjectDeleteMixin, + RESTObject): _id_attr = 'iid' _managers = ( @@ -1793,30 +1824,6 @@ class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin, **kwargs) self._update_attrs(server_data) - @cli.register_custom_action('ProjectMergeRequest') - @exc.on_http_error(exc.GitlabListError) - def participants(self, **kwargs): - """List the merge request participants. - - Args: - all (bool): If True, return all the items, without pagination - per_page (int): Number of items to retrieve per request - page (int): ID of the page to return (starts with page 1) - as_list (bool): If set to False and no pagination option is - defined, return a generator instead of a list - **kwargs: Extra options to send to the server (e.g. sudo) - - Raises: - GitlabAuthenticationError: If authentication is not correct - GitlabListError: If the list could not be retrieved - - Returns: - RESTObjectList: The list of participants - """ - - path = '%s/%s/participants' % (self.manager.path, self.get_id()) - return self.manager.gitlab.http_get(path, **kwargs) - class ProjectMergeRequestManager(CRUDMixin, RESTManager): _path = '/projects/%(project_id)s/merge_requests' diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 1527c2e..24b729d 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -511,6 +511,7 @@ assert(len(issue1.notes.list()) == 0) assert(isinstance(issue1.user_agent_detail(), dict)) assert(issue1.user_agent_detail()['user_agent']) +assert(issue1.participants()) discussion = issue1.discussions.create({'body': 'Discussion body'}) assert(len(issue1.discussions.list()) == 1) @@ -604,7 +605,7 @@ assert(len(discussion.attributes['notes']) == 1) # basic testing: only make sure that the methods exist mr.commits() mr.changes() -mr.participants() # not yet available +assert(mr.participants()) mr.merge() admin_project.branches.delete('branch1') |