1
1
# -*- coding: utf-8 -*-
2
- """
3
- github3.repos.comment
4
- =====================
5
-
6
- This module contains the RepoComment class
7
-
8
- """
2
+ """This module contains the RepoComment class."""
9
3
from __future__ import unicode_literals
10
4
5
+ from .. import models
11
6
from .. import users
12
7
13
8
from ..decorators import requires_auth
14
- from ..models import BaseComment
15
9
16
10
17
- class RepoComment (BaseComment ):
18
- """The :class:`RepoComment <RepoComment>` object. This stores the
19
- information about a comment on a file in a repository.
11
+ class _RepoComment (models .GitHubCore ):
12
+ """The :class:`RepoComment <RepoComment>` object.
13
+
14
+ This stores the information about a comment on a file in a repository.
20
15
21
16
Two comment instances can be checked like so::
22
17
@@ -29,49 +24,135 @@ class RepoComment(BaseComment):
29
24
c1.id != c2.id
30
25
31
26
"""
27
+
28
+ class_name = '_RepoComment'
29
+
32
30
def _update_attributes (self , comment ):
33
- super (RepoComment , self )._update_attributes (comment )
31
+ self ._api = comment ['url' ]
32
+ self .author_association = comment ['author_association' ]
33
+ self .body = comment ['body' ]
34
+ self .commit_id = comment ['commit_id' ]
35
+ self .created_at = self ._strptime (comment ['created_at' ])
36
+ self .html_url = comment ['html_url' ]
37
+ self .id = comment ['id' ]
38
+ self .line = comment ['line' ]
39
+ self .path = comment ['path' ]
40
+ self .position = comment ['position' ]
41
+ self .updated_at = self ._strptime (comment ['updated_at' ])
42
+ self .user = users .ShortUser (comment ['user' ], self )
34
43
35
- #: Commit id on which the comment was made.
36
- self .commit_id = self ._get_attribute (comment , 'commit_id' )
44
+ def _repr (self ):
45
+ return '<{0} [{1}/{2}]>' .format (
46
+ self .class_name , self .commit_id [:7 ], self .user .login or ''
47
+ )
37
48
38
- #: URL of the comment on GitHub.
39
- self .html_url = self ._get_attribute (comment , 'html_url' )
49
+ @requires_auth
50
+ def delete (self ):
51
+ """Delete this comment.
40
52
41
- #: The line number where the comment is located.
42
- self .line = self ._get_attribute (comment , 'line' )
53
+ :returns:
54
+ True if successfully deleted, False otherwise
55
+ :rtype:
56
+ bool
57
+ """
58
+ return self ._boolean (self ._delete (self ._api ), 204 , 404 )
43
59
44
- #: The path to the file where the comment was made.
45
- self .path = self ._get_attribute (comment , 'path' )
60
+ @requires_auth
61
+ def edit (self , body ):
62
+ """Edit this comment.
63
+
64
+ :param str body:
65
+ (required), new body of the comment, Markdown formatted
66
+ :returns:
67
+ True if successful, False otherwise
68
+ :rtype:
69
+ bool
70
+ """
71
+ if body :
72
+ json = self ._json (self ._patch (self ._api ,
73
+ json = {'body' : body }), 200 )
74
+ if json :
75
+ self ._update_attributes (json )
76
+ return True
77
+ return False
46
78
47
- #: The position in the diff where the comment was made.
48
- self .position = self ._get_attribute (comment , 'position' )
79
+ update = edit
49
80
50
- #: datetime object representing when the comment was updated.
51
- self .updated_at = self ._strptime_attribute (comment , 'updated_at' )
52
81
53
- #: Login of the user who left the comment.
54
- self .user = self ._class_attribute (
55
- comment , 'user' , users .ShortUser , self
56
- )
82
+ class ShortComment (_RepoComment ):
83
+ """The representation of an abridged comment on an object in a repo.
57
84
58
- def _repr (self ):
59
- return '<Repository Comment [{0}/{1}]>' .format (
60
- self .commit_id [:7 ], self .user .login or ''
61
- )
85
+ This object has the following attributes:
62
86
63
- @requires_auth
64
- def update (self , body ):
65
- """Update this comment.
87
+ .. attribute:: author_association
66
88
67
- :param str body: (required)
68
- :returns: bool
69
- """
70
- json = None
71
- if body :
72
- json = self ._json (self ._post (self ._api , data = {'body' : body }), 200 )
89
+ The affiliation the author of this comment has with the repository.
73
90
74
- if json :
75
- self ._update_attributes (json )
76
- return True
77
- return False
91
+ .. attribute:: body
92
+
93
+ The Markdown formatted text of this comment.
94
+
95
+ .. attribute:: commit_id
96
+
97
+ The SHA1 associated with this comment.
98
+
99
+ .. attribute:: created_at
100
+
101
+ A :class:`~dateteime.datetime` object representing the date and time
102
+ when this comment was created.
103
+
104
+ .. attribute:: html_url
105
+
106
+ The URL to view this comment in a browser.
107
+
108
+ .. attribute:: id
109
+
110
+ The unique identifier of this comment.
111
+
112
+ .. attribute:: line
113
+
114
+ The line number where the comment is located.
115
+
116
+ .. attribute:: path
117
+
118
+ The path to the file where this comment was made.
119
+
120
+ .. attribute:: position
121
+
122
+ The position in the diff where the comment was left.
123
+
124
+ .. attribute:: updated_at
125
+
126
+ A :class:`~datetime.datetime` object representing the date and time
127
+ when this comment was most recently updated.
128
+
129
+ .. attribute:: user
130
+
131
+ A :class:`~github3.users.ShortUser` representing the author of this
132
+ comment.
133
+ """
134
+
135
+ class_name = 'Short Repository Comment'
136
+
137
+
138
+ class RepoComment (_RepoComment ):
139
+ """The representation of the full comment on an object in a repository.
140
+
141
+ This object has the same attributes as a
142
+ :class:`~github3.repos.comment.ShortComment` as well as the following:
143
+
144
+ .. attribute:: body_html
145
+
146
+ The HTML formatted text of this comment.
147
+
148
+ .. attribute:: body_text
149
+
150
+ The plain-text formatted text of this comment.
151
+ """
152
+
153
+ class_name = 'Repository Comment'
154
+
155
+ def _update_attributes (self , comment ):
156
+ super (RepoComment , self )._update_attributes (comment )
157
+ self .body_text = comment ['body_text' ]
158
+ self .body_html = comment ['body_html' ]
0 commit comments