1
1
# -*- coding: utf-8 -*-
2
+ """Module with class(es) representing issue comments."""
2
3
from __future__ import unicode_literals
3
4
5
+ from .. import decorators
6
+ from .. import models
4
7
from .. import users
5
- from ..utils import timestamp_parameter
6
- from ..models import BaseComment
8
+ from .. import utils
7
9
8
10
9
- class IssueComment (BaseComment ):
10
- """The :class:`IssueComment <IssueComment>` object. This structures and
11
- handles the comments on issues specifically.
11
+ class IssueComment (models .GitHubCore ):
12
+ """Representation of a comment left on an issue.
12
13
13
- Two comment instances can be checked like so::
14
+ See also: http://developer.github.com/v3/issues/comments/
14
15
15
- c1 == c2
16
- c1 != c2
16
+ This object has the following attributes:
17
17
18
- And is equivalent to::
18
+ .. attribute:: author_association
19
19
20
- c1.id == c2.id
21
- c1.id != c2.id
20
+ The association of the author (:attr:`user`) with the repository
21
+ this issue belongs to.
22
22
23
- See also: http://developer.github.com/v3/issues/comments/
23
+ .. attribute:: body
24
+
25
+ The markdown formatted original text written by the author.
26
+
27
+ .. attribute:: body_html
28
+
29
+ The HTML formatted comment body.
30
+
31
+ .. attribute:: body_text
32
+
33
+ The plain-text formatted comment body.
34
+
35
+ .. attribute:: created_at
36
+
37
+ A :class:`~datetime.datetime` object representing the date and time
38
+ when this comment was created.
39
+
40
+ .. attribute:: html_url
41
+
42
+ The URL to view this comment in a browser.
43
+
44
+ .. attribute:: id
45
+
46
+ The unique identifier for this comment.
47
+
48
+ .. attribute:: issue_url
49
+
50
+ The URL of the parent issue in the API.
51
+
52
+ .. attribute:: updated_at
53
+
54
+ A :class:`~datetime.datetime` object representing the date and time
55
+ when this comment was most recently updated.
56
+
57
+ .. attribute:: user
58
+
59
+ A :class:`~github3.users.ShortUser` representing the author of this
60
+ comment.
24
61
"""
62
+
25
63
def _update_attributes (self , comment ):
26
- super (IssueComment , self )._update_attributes (comment )
64
+ self ._api = comment ['url' ]
65
+ self .author_association = comment ['author_association' ]
66
+ self .body = comment ['body' ]
67
+ self .body_html = comment ['body_html' ]
68
+ self .body_text = comment ['body_text' ]
69
+ self .created_at = self ._strptime (comment ['created_at' ])
70
+ self .html_url = comment ['html_url' ]
71
+ self .id = comment ['id' ]
72
+ self .issue_url = comment ['issue_url' ]
73
+ self .updated_at = self ._strptime (comment ['updated_at' ])
74
+ self .user = users .ShortUser (comment ['user' ], self )
27
75
28
- #: :class:`User <github3.users.User>` who made the comment
29
- self .user = self ._class_attribute (
30
- comment , 'user' , users .ShortUser , self ,
31
- )
76
+ def _repr (self ):
77
+ return '<IssueComment [{0}]>' .format (self .user .login )
32
78
33
- #: Issue url (not a template)
34
- self .issue_url = self ._get_attribute (comment , 'issue_url' )
79
+ @decorators .requires_auth
80
+ def delete (self ):
81
+ """Delete this comment.
35
82
36
- #: Html url (not a template)
37
- self .html_url = self ._get_attribute (comment , 'html_url' )
83
+ :returns: bool
84
+ """
85
+ return self ._boolean (self ._delete (self ._api ), 204 , 404 )
38
86
39
- def _repr (self ):
40
- return '<Issue Comment [{0}]>' .format (self .user .login )
87
+ @decorators .requires_auth
88
+ def edit (self , body ):
89
+ """Edit this comment.
90
+
91
+ :param str body: (required), new body of the comment, Markdown
92
+ formatted
93
+ :returns: bool
94
+ """
95
+ if body :
96
+ json = self ._json (self ._patch (self ._api ,
97
+ json = {'body' : body }), 200 )
98
+ if json :
99
+ self ._update_attributes (json )
100
+ return True
101
+ return False
41
102
42
103
43
104
def issue_comment_params (sort , direction , since ):
105
+ """Properly format parameters for issue comments.
106
+
107
+ .. warning::
108
+
109
+ This is not a public API designed for users of github3.py.
110
+
111
+ """
44
112
params = {}
45
113
46
114
if sort in ('created' , 'updated' ):
@@ -49,7 +117,7 @@ def issue_comment_params(sort, direction, since):
49
117
if direction in ('asc' , 'desc' ):
50
118
params ['direction' ] = direction
51
119
52
- since = timestamp_parameter (since )
120
+ since = utils . timestamp_parameter (since )
53
121
if since :
54
122
params ['since' ] = since
55
123
0 commit comments