Skip to content

Commit e901f44

Browse files
author
Gauvain Pocentek
committed
Issues: add missing attributes and methods
1 parent 4ec8975 commit e901f44

File tree

4 files changed

+78
-36
lines changed

4 files changed

+78
-36
lines changed

docs/gl_objects/issues.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,11 @@ Reset spent time for an issue::
145145
Get user agent detail for the issue (admin only)::
146146

147147
detail = issue.user_agent_detail()
148+
149+
Get the list of merge requests that will close an issue when merged::
150+
151+
mrs = issue.closed_by()
152+
153+
Get the list of participants::
154+
155+
users = issue.participants()

gitlab/mixins.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,29 @@ def reset_spent_time(self, **kwargs):
545545
"""
546546
path = '%s/%s/reset_spent_time' % (self.manager.path, self.get_id())
547547
return self.manager.gitlab.http_post(path, **kwargs)
548+
549+
550+
class ParticipantsMixin(object):
551+
@cli.register_custom_action('ProjectMergeRequest', 'ProjectIssue')
552+
@exc.on_http_error(exc.GitlabListError)
553+
def participants(self, **kwargs):
554+
"""List the participants.
555+
556+
Args:
557+
all (bool): If True, return all the items, without pagination
558+
per_page (int): Number of items to retrieve per request
559+
page (int): ID of the page to return (starts with page 1)
560+
as_list (bool): If set to False and no pagination option is
561+
defined, return a generator instead of a list
562+
**kwargs: Extra options to send to the server (e.g. sudo)
563+
564+
Raises:
565+
GitlabAuthenticationError: If authentication is not correct
566+
GitlabListError: If the list could not be retrieved
567+
568+
Returns:
569+
RESTObjectList: The list of participants
570+
"""
571+
572+
path = '%s/%s/participants' % (self.manager.path, self.get_id())
573+
return self.manager.gitlab.http_get(path, **kwargs)

gitlab/v4/objects.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,10 @@ class GroupIssueManager(ListMixin, RESTManager):
542542
_path = '/groups/%(group_id)s/issues'
543543
_obj_cls = GroupIssue
544544
_from_parent_attrs = {'group_id': 'id'}
545-
_list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort')
545+
_list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort',
546+
'iids', 'author_id', 'assignee_id', 'my_reaction_emoji',
547+
'search', 'created_after', 'created_before',
548+
'updated_after', 'updated_before')
546549
_types = {'labels': types.ListAttribute}
547550

548551

@@ -772,7 +775,10 @@ class Issue(RESTObject):
772775
class IssueManager(ListMixin, RESTManager):
773776
_path = '/issues'
774777
_obj_cls = Issue
775-
_list_filters = ('state', 'labels', 'order_by', 'sort')
778+
_list_filters = ('state', 'labels', 'milestone', 'scope', 'author_id',
779+
'assignee_id', 'my_reaction_emoji', 'iids', 'order_by',
780+
'sort', 'search', 'created_after', 'created_before',
781+
'updated_after', 'updated_before')
776782
_types = {'labels': types.ListAttribute}
777783

778784

@@ -1440,8 +1446,8 @@ class ProjectIssueDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
14401446

14411447

14421448
class ProjectIssue(UserAgentDetailMixin, SubscribableMixin, TodoMixin,
1443-
TimeTrackingMixin, SaveMixin, ObjectDeleteMixin,
1444-
RESTObject):
1449+
TimeTrackingMixin, ParticipantsMixin, SaveMixin,
1450+
ObjectDeleteMixin, RESTObject):
14451451
_short_print_attr = 'title'
14461452
_id_attr = 'iid'
14471453
_managers = (
@@ -1469,18 +1475,42 @@ def move(self, to_project_id, **kwargs):
14691475
**kwargs)
14701476
self._update_attrs(server_data)
14711477

1478+
@cli.register_custom_action('ProjectIssue')
1479+
@exc.on_http_error(exc.GitlabGetError)
1480+
def closed_by(self, **kwargs):
1481+
"""List merge requests that will close the issue when merged.
1482+
1483+
Args:
1484+
**kwargs: Extra options to send to the server (e.g. sudo)
1485+
1486+
Raises:
1487+
GitlabAuthenticationError: If authentication is not correct
1488+
GitlabGetErrot: If the merge requests could not be retrieved
1489+
1490+
Returns:
1491+
list: The list of merge requests.
1492+
"""
1493+
path = '%s/%s/closed_by' % (self.manager.path, self.get_id())
1494+
return self.manager.gitlab.http_get(path, **kwargs)
1495+
14721496

14731497
class ProjectIssueManager(CRUDMixin, RESTManager):
14741498
_path = '/projects/%(project_id)s/issues/'
14751499
_obj_cls = ProjectIssue
14761500
_from_parent_attrs = {'project_id': 'id'}
1477-
_list_filters = ('state', 'labels', 'milestone', 'order_by', 'sort')
1501+
_list_filters = ('iids', 'state', 'labels', 'milestone', 'scope',
1502+
'author_id', 'assignee_id', 'my_reaction_emoji',
1503+
'order_by', 'sort', 'search', 'created_after',
1504+
'created_before', 'updated_after', 'updated_before')
14781505
_create_attrs = (('title', ),
1479-
('description', 'assignee_id', 'milestone_id', 'labels',
1480-
'created_at', 'due_date'))
1481-
_update_attrs = (tuple(), ('title', 'description', 'assignee_id',
1482-
'milestone_id', 'labels', 'created_at',
1483-
'updated_at', 'state_event', 'due_date'))
1506+
('description', 'confidential', 'assignee_id',
1507+
'assignee_idss' 'milestone_id', 'labels', 'created_at',
1508+
'due_date', 'merge_request_to_resolve_discussions_of' ,
1509+
'discussion_to_resolve'))
1510+
_update_attrs = (tuple(), ('title', 'description', 'confidential',
1511+
'assignee_ids', 'assignee_id', 'milestone_id',
1512+
'labels', 'state_event', 'updated_at',
1513+
'due_date', 'discussion_locked'))
14841514
_types = {'labels': types.ListAttribute}
14851515

14861516

@@ -1655,7 +1685,8 @@ class ProjectMergeRequestDiscussionManager(RetrieveMixin, CreateMixin,
16551685

16561686

16571687
class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin,
1658-
SaveMixin, ObjectDeleteMixin, RESTObject):
1688+
ParticipantsMixin, SaveMixin, ObjectDeleteMixin,
1689+
RESTObject):
16591690
_id_attr = 'iid'
16601691

16611692
_managers = (
@@ -1793,30 +1824,6 @@ def merge(self, merge_commit_message=None,
17931824
**kwargs)
17941825
self._update_attrs(server_data)
17951826

1796-
@cli.register_custom_action('ProjectMergeRequest')
1797-
@exc.on_http_error(exc.GitlabListError)
1798-
def participants(self, **kwargs):
1799-
"""List the merge request participants.
1800-
1801-
Args:
1802-
all (bool): If True, return all the items, without pagination
1803-
per_page (int): Number of items to retrieve per request
1804-
page (int): ID of the page to return (starts with page 1)
1805-
as_list (bool): If set to False and no pagination option is
1806-
defined, return a generator instead of a list
1807-
**kwargs: Extra options to send to the server (e.g. sudo)
1808-
1809-
Raises:
1810-
GitlabAuthenticationError: If authentication is not correct
1811-
GitlabListError: If the list could not be retrieved
1812-
1813-
Returns:
1814-
RESTObjectList: The list of participants
1815-
"""
1816-
1817-
path = '%s/%s/participants' % (self.manager.path, self.get_id())
1818-
return self.manager.gitlab.http_get(path, **kwargs)
1819-
18201827

18211828
class ProjectMergeRequestManager(CRUDMixin, RESTManager):
18221829
_path = '/projects/%(project_id)s/merge_requests'

tools/python_test_v4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@
511511
assert(isinstance(issue1.user_agent_detail(), dict))
512512

513513
assert(issue1.user_agent_detail()['user_agent'])
514+
assert(issue1.participants())
514515

515516
discussion = issue1.discussions.create({'body': 'Discussion body'})
516517
assert(len(issue1.discussions.list()) == 1)
@@ -604,7 +605,7 @@
604605
# basic testing: only make sure that the methods exist
605606
mr.commits()
606607
mr.changes()
607-
mr.participants() # not yet available
608+
assert(mr.participants())
608609

609610
mr.merge()
610611
admin_project.branches.delete('branch1')

0 commit comments

Comments
 (0)