8000 Update IssueComment for consistency with project · pythonthings/github3.py@787e9b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 787e9b0

Browse files
committed
Update IssueComment for consistency with project
This removes the unnecessary reliance on BaseComment and directly accesses the properties we expect to be there.
1 parent 86e66e0 commit 787e9b0

File tree

7 files changed

+170
-31
lines changed

7 files changed

+170
-31
lines changed

github3/events.py

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,77 @@ def to_issue(self):
292292
refresh = to_issue
293293

294294

295+
class EventIssueComment(models.GitHubCore):
296+
"""Representation of a comment left on an issue.
297+
298+
See also: http://developer.github.com/v3/issues/comments/
299+
300+
This object has the following attributes:
301+
302+
.. attribute:: author_association
303+
304+
The association of the author (:attr:`user`) with the repository
305+
this issue belongs to.
306+
307+
.. attribute:: body
308+
309+
The markdown formatted original text written by the author.
310+
311+
.. attribute:: created_at
312+
313+
A :class:`~datetime.datetime` object representing the date and time
314+
when this comment was created.
315+
316+
.. attribute:: html_url
317+
318+
The URL to view this comment in a browser.
319+
320+
.. attribute:: id
321+
322+
The unique identifier for this comment.
323+
324+
.. attribute:: issue_url
325+
326+
The URL of the parent issue in the API.
327+
328+
.. attribute:: updated_at
329+
330+
A :class:`~datetime.datetime` object representing the date and time
331+
when this comment was most recently updated.
332+
333+
.. attribute:: user
334+
335+
A :class:`~github3.users.ShortUser` representing the author of this
336+
comment.
337+
"""
338+
339+
def _update_attributes(self, comment):
340+
from . import users
341+
self._api = comment['url']
342+
self.author_association = comment['author_association']
343+
self.body = comment['body']
344+
self.created_at = self._strptime(comment['created_at'])
345+
self.html_url = comment['html_url']
346+
self.id = comment['id']
347+
self.issue_url = comment['issue_url']
348+
self.updated_at = self._strptime(comment['updated_at'])
349+
self.user = users.ShortUser(comment['user'], self)
350+
351+
def to_issue_comment(self):
352+
"""Retrieve the full IssueComment object for this comment.
353+
354+
:returns:
355+
All the information about an IssueComment.
356+
:rtype:
357+
:class:`~github3.issues.comment.IssueComment`
358+
"""
359+
from .issues import comment
360+
json = self._json(self._get(self.url), 200)
361+
return self._instance_or_null(comment.IssueComment, json)
362+
363+
refresh = to_issue_comment
364+
365+
295366
class Event(models.GitHubCore):
296367
"""Represents an event as returned by the API.
297368
@@ -411,11 +482,10 @@ def _gist(payload, session):
411482

412483

413484
def _issuecomm(payload, session):
414-
from .issues.comment import IssueComment
415485
if payload.get('issue'):
416486
payload['issue'] = EventIssue(payload['issue'], session)
417487
if payload.get('comment'):
418-
payload['comment'] = IssueComment(payload['comment'], session)
488+
payload['comment'] = EventIssueComment(payload['comment'], session)
419489
return payload
420490

421491

github3/issues/comment.py

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,114 @@
11
# -*- coding: utf-8 -*-
2+
"""Module with class(es) representing issue comments."""
23
from __future__ import unicode_literals
34

5+
from .. import decorators
6+
from .. import models
47
from .. import users
5-
from ..utils import timestamp_parameter
6-
from ..models import BaseComment
8+
from .. import utils
79

810

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.
1213
13-
Two comment instances can be checked like so::
14+
See also: http://developer.github.com/v3/issues/comments/
1415
15-
c1 == c2
16-
c1 != c2
16+
This object has the following attributes:
1717
18-
And is equivalent to::
18+
.. attribute:: author_association
1919
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.
2222
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.
2461
"""
62+
2563
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)
2775

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)
3278

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.
3582
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)
3886

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
41102

42103

43104
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+
"""
44112
params = {}
45113

46114
if sort in ('created', 'updated'):
@@ -49,7 +117,7 @@ def issue_comment_params(sort, direction, since):
49117
if direction in ('asc', 'desc'):
50118
params['direction'] = direction
51119

52-
since = timestamp_parameter(since)
120+
since = utils.timestamp_parameter(since)
53121
if since:
54122
params['since'] = since
55123

tests/cassettes/PullRequest_create_comment.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
0