forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.py
More file actions
73 lines (58 loc) · 2.09 KB
/
comment.py
File metadata and controls
73 lines (58 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
github3.repos.comment
=====================
This module contains the RepoComment class
"""
from __future__ import unicode_literals
from ..decorators import requires_auth
from ..models import BaseComment
from ..users import User
class RepoComment(BaseComment):
"""The :class:`RepoComment <RepoComment>` object. This stores the
information about a comment on a file in a repository.
Two comment instances can be checked like so::
c1 == c2
c1 != c2
And is equivalent to::
c1.id == c2.id
c1.id != c2.id
"""
def __init__(self, comment, session=None):
super(RepoComment, self).__init__(comment, session)
#: Commit id on which the comment was made.
self.commit_id = comment.get('commit_id')
#: URL of the comment on GitHub.
self.html_url = comment.get('html_url')
#: The line number where the comment is located.
self.line = comment.get('line')
#: The path to the file where the comment was made.
self.path = comment.get('path')
#: The position in the diff where the comment was made.
self.position = comment.get('position')
#: datetime object representing when the comment was updated.
self.updated_at = self._strptime(comment.get('updated_at'))
#: Login of the user who left the comment.
self.user = None
if comment.get('user'):
self.user = User(comment.get('user'), self)
def _repr(self):
return '<Repository Comment [{0}/{1}]>'.format(
self.commit_id[:7], self.user.login or ''
)
def _update_(self, comment):
super(RepoComment, self)._update_(comment)
self.__init__(comment, self._session)
@requires_auth
def update(self, body):
"""Update this comment.
:param str body: (required)
:returns: bool
"""
json = None
if body:
json = self._json(self._post(self._api, data={'body': body}), 200)
if json:
self._update_(json)
return True
return False