Skip to content

Commit

Permalink
Add support for award emojis
Browse files Browse the repository at this point in the history
Fixes #361
  • Loading branch information
Gauvain Pocentek committed Dec 16, 2017
1 parent 2167409 commit b33265c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/api-objects.rst
Expand Up @@ -6,6 +6,7 @@ API examples
:maxdepth: 1

gl_objects/access_requests
gl_objects/emojis
gl_objects/branches
gl_objects/protected_branches
gl_objects/messages
Expand Down
94 changes: 88 additions & 6 deletions gitlab/v4/objects.py
Expand Up @@ -1091,10 +1091,35 @@ class ProjectHookManager(CRUDMixin, RESTManager):
)


class ProjectIssueNote(SaveMixin, ObjectDeleteMixin, RESTObject):
class ProjectIssueAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = '/projects/%(project_id)s/issues/%(issue_iid)s/award_emoji'
_obj_cls = ProjectIssueAwardEmoji
_from_parent_attrs = {'project_id': 'project_id', 'issue_iid': 'iid'}
_create_attrs = (('name', ), tuple())


class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = ('/projects/%(project_id)s/issues/%(issue_iid)s'
'/notes/%(note_id)s/award_emoji')
_obj_cls = ProjectIssueNoteAwardEmoji
_from_parent_attrs = {'project_id': 'project_id',
'issue_iid': 'issue_iid',
'note_id': 'id'}
_create_attrs = (('name', ), tuple())


class ProjectIssueNote(SaveMixin, ObjectDeleteMixin, RESTObject):
_managers = (('awardemojis', 'ProjectIssueNoteAwardEmojiManager'),)


class ProjectIssueNoteManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/issues/%(issue_iid)s/notes'
_obj_cls = ProjectIssueNote
Expand All @@ -1107,7 +1132,10 @@ class ProjectIssue(SubscribableMixin, TodoMixin, TimeTrackingMixin, SaveMixin,
ObjectDeleteMixin, RESTObject):
_short_print_attr = 'title'
_id_attr = 'iid'
_managers = (('notes', 'ProjectIssueNoteManager'), )
_managers = (
('notes', 'ProjectIssueNoteManager'),
('awardemojis', 'ProjectIssueAwardEmojiManager'),
)

@cli.register_custom_action('ProjectIssue')
@exc.on_http_error(exc.GitlabUpdateError)
Expand Down Expand Up @@ -1243,6 +1271,17 @@ class ProjectTagManager(NoUpdateMixin, RESTManager):
_create_attrs = (('tag_name', 'ref'), ('message',))


class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = '/projects/%(project_id)s/merge_requests/%(mr_iid)s/award_emoji'
_obj_cls = ProjectMergeRequestAwardEmoji
_from_parent_attrs = {'project_id': 'project_id', 'mr_iid': 'iid'}
_create_attrs = (('name', ), tuple())


class ProjectMergeRequestDiff(RESTObject):
pass

Expand All @@ -1253,10 +1292,24 @@ class ProjectMergeRequestDiffManager(RetrieveMixin, RESTManager):
_from_parent_attrs = {'project_id': 'project_id', 'mr_iid': 'iid'}


class ProjectMergeRequestNote(SaveMixin, ObjectDeleteMixin, RESTObject):
class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = ('/projects/%(project_id)s/merge_requests/%(mr_iid)s'
'/notes/%(note_id)s/award_emoji')
_obj_cls = ProjectMergeRequestNoteAwardEmoji
_from_parent_attrs = {'project_id': 'project_id',
'mr_iid': 'issue_iid',
'note_id': 'id'}
_create_attrs = (('name', ), tuple())


class ProjectMergeRequestNote(SaveMixin, ObjectDeleteMixin, RESTObject):
_managers = (('awardemojis', 'ProjectMergeRequestNoteAwardEmojiManager'),)


class ProjectMergeRequestNoteManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/merge_requests/%(mr_iid)s/notes'
_obj_cls = ProjectMergeRequestNote
Expand All @@ -1270,8 +1323,9 @@ class ProjectMergeRequest(SubscribableMixin, TodoMixin, TimeTrackingMixin,
_id_attr = 'iid'

_managers = (
('awardemojis', 'ProjectMergeRequestAwardEmojiManager'),
('diffs', 'ProjectMergeRequestDiffManager'),
('notes', 'ProjectMergeRequestNoteManager'),
('diffs', 'ProjectMergeRequestDiffManager')
)

@cli.register_custom_action('ProjectMergeRequest')
Expand Down Expand Up @@ -1764,10 +1818,24 @@ def create(self, data, **kwargs):
return CreateMixin.create(self, data, path=path, **kwargs)


class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject):
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = ('/projects/%(project_id)s/snippets/%(snippet_id)s'
'/notes/%(note_id)s/award_emoji')
_obj_cls = ProjectSnippetNoteAwardEmoji
_from_parent_attrs = {'project_id': 'project_id',
'snippet_id': 'snippet_id',
'note_id': 'id'}
_create_attrs = (('name', ), tuple())


class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject):
_managers = (('awardemojis', 'ProjectSnippetNoteAwardEmojiManager'),)


class ProjectSnippetNoteManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/snippets/%(snippet_id)s/notes'
_obj_cls = ProjectSnippetNote
Expand All @@ -1777,10 +1845,24 @@ class ProjectSnippetNoteManager(CRUDMixin, RESTManager):
_update_attrs = (('body', ), tuple())


class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject):
pass


class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = '/projects/%(project_id)s/snippets/%(snippet_id)s/award_emoji'
_obj_cls = ProjectSnippetAwardEmoji
_from_parent_attrs = {'project_id': 'project_id', 'snippet_id': 'id'}
_create_attrs = (('name', ), tuple())


class ProjectSnippet(SaveMixin, ObjectDeleteMixin, RESTObject):
_url = '/projects/%(project_id)s/snippets'
_short_print_attr = 'title'
_managers = (('notes', 'ProjectSnippetNoteManager'), )
_managers = (
('awardemojis', 'ProjectSnippetAwardEmojiManager'),
('notes', 'ProjectSnippetNoteManager'),
)

@cli.register_custom_action('ProjectSnippet')
@exc.on_http_error(exc.GitlabGetError)
Expand Down
4 changes: 4 additions & 0 deletions tools/python_test_v4.py
Expand Up @@ -436,6 +436,10 @@
assert(m1.issues().next().title == 'my issue 1')
note = issue1.notes.create({'body': 'This is an issue note'})
assert(len(issue1.notes.list()) == 1)
emoji = note.awardemojis.create({'name': 'tractor'})
assert(len(note.awardemojis.list()) == 1)
emoji.delete()
assert(len(note.awardemojis.list()) == 0)
note.delete()
assert(len(issue1.notes.list()) == 0)
assert(isinstance(issue1.user_agent_detail(), dict))
Expand Down

0 comments on commit b33265c

Please sign in to comment.