Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit787e9b0

Browse files
committed
Update IssueComment for consistency with project
This removes the unnecessary reliance on BaseComment and directlyaccesses the properties we expect to be there.
1 parent86e66e0 commit787e9b0

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+
classEventIssueComment(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 .importusers
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+
defto_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 .issuesimportcomment
360+
json=self._json(self._get(self.url),200)
361+
returnself._instance_or_null(comment.IssueComment,json)
362+
363+
refresh=to_issue_comment
364+
365+
295366
classEvent(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.commentimportIssueComment
415485
ifpayload.get('issue'):
416486
payload['issue']=EventIssue(payload['issue'],session)
417487
ifpayload.get('comment'):
418-
payload['comment']=IssueComment(payload['comment'],session)
488+
payload['comment']=EventIssueComment(payload['comment'],session)
419489
returnpayload
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__importunicode_literals
34

5+
from ..importdecorators
6+
from ..importmodels
47
from ..importusers
5-
from ..utilsimporttimestamp_parameter
6-
from ..modelsimportBaseComment
8+
from ..importutils
79

810

9-
classIssueComment(BaseComment):
10-
"""The :class:`IssueComment <IssueComment>` object. This structures and
11-
handles the comments on issues specifically.
11+
classIssueComment(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+
defdelete(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+
returnself._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+
defedit(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+
ifbody:
96+
json=self._json(self._patch(self._api,
97+
json={'body':body}),200)
98+
ifjson:
99+
self._update_attributes(json)
100+
returnTrue
101+
returnFalse
41102

42103

43104
defissue_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
ifsortin ('created','updated'):
@@ -49,7 +117,7 @@ def issue_comment_params(sort, direction, since):
49117
ifdirectionin ('asc','desc'):
50118
params['direction']=direction
51119

52-
since=timestamp_parameter(since)
120+
since=utils.timestamp_parameter(since)
53121
ifsince:
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)

[8]ページ先頭

©2009-2025 Movatter.jp