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
160 lines (107 loc) · 4.02 KB
/
comment.py
File metadata and controls
160 lines (107 loc) · 4.02 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
"""This module contains the RepoComment class."""
from __future__ import unicode_literals
from .. import models
from .. import users
from ..decorators import requires_auth
class _RepoComment(models.GitHubCore):
"""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
"""
class_name = "_RepoComment"
def _update_attributes(self, comment):
self._api = comment["url"]
self.author_association = comment["author_association"]
self.body = comment["body"]
self.commit_id = comment["commit_id"]
self.created_at = self._strptime(comment["created_at"])
self.html_url = comment["html_url"]
self.id = comment["id"]
self.line = comment["line"]
self.path = comment["path"]
self.position = comment["position"]
self.updated_at = self._strptime(comment["updated_at"])
self.user = users.ShortUser(comment["user"], self)
def _repr(self):
return "<{0} [{1}/{2}]>".format(
self.class_name, self.commit_id[:7], self.user.login or ""
)
@requires_auth
def delete(self):
"""Delete this comment.
:returns:
True if successfully deleted, False otherwise
:rtype:
bool
"""
return self._boolean(self._delete(self._api), 204, 404)
@requires_auth
def edit(self, body):
"""Edit this comment.
:param str body:
(required), new body of the comment, Markdown formatted
:returns:
True if successful, False otherwise
:rtype:
bool
"""
if body:
json = self._json(
self._patch(self._api, json={"body": body}), 200
)
if json:
self._update_attributes(json)
return True
return False
update = edit
class RepoComment(_RepoComment):
"""The representation of the full comment on an object in a repository.
This object has the same attributes as a
:class:`~github3.repos.comment.ShortComment` as well as the following:
.. attribute:: body_html
The HTML formatted text of this comment.
.. attribute:: body_text
The plain-text formatted text of this comment.
"""
class_name = "Repository Comment"
def _update_attributes(self, comment):
super(RepoComment, self)._update_attributes(comment)
self.body_text = comment["body_text"]
self.body_html = comment["body_html"]
class ShortComment(_RepoComment):
"""The representation of an abridged comment on an object in a repo.
This object has the following attributes:
.. attribute:: author_association
The affiliation the author of this comment has with the repository.
.. attribute:: body
The Markdown formatted text of this comment.
.. attribute:: commit_id
The SHA1 associated with this comment.
.. attribute:: created_at
A :class:`~dateteime.datetime` object representing the date and time
when this comment was created.
.. attribute:: html_url
The URL to view this comment in a browser.
.. attribute:: id
The unique identifier of this comment.
.. attribute:: line
The line number where the comment is located.
.. attribute:: path
The path to the file where this comment was made.
.. attribute:: position
The position in the diff where the comment was left.
.. attribute:: updated_at
A :class:`~datetime.datetime` object representing the date and time
when this comment was most recently updated.
.. attribute:: user
A :class:`~github3.users.ShortUser` representing the author of this
comment.
"""
class_name = "Short Repository Comment"
_refresh_to = RepoComment