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

Commit0b1e5cd

Browse files
committed
Update RepoComment for consistency
This adds the ShortComment class to represent comments without text andhtml bodies. This also removes the BaseAccount, BaseComment, andBaseCommit classes as they're no longer used or necessary.
1 parenta38a111 commit0b1e5cd

File tree

11 files changed

+147
-207
lines changed

11 files changed

+147
-207
lines changed

‎docs/models.rst‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,3 @@ Objects
1313

1414
..autoclass::GitHubCore
1515
:inherited-members:
16-
17-
------
18-
19-
..autoclass::BaseAccount
20-
:inherited-members:
21-
22-
------
23-
24-
..autoclass::BaseComment
25-
:inherited-members:
26-
27-
------
28-
29-
..autoclass::BaseCommit
30-
:inherited-members:

‎github3/events.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ def list_types():
455455

456456

457457
def_commitcomment(payload,session):
458-
from .repos.commentimportRepoComment
458+
from .repos.commentimportShortComment
459459
ifpayload.get('comment'):
460-
payload['comment']=RepoComment(payload['comment'],session)
460+
payload['comment']=ShortComment(payload['comment'],session)
461461
returnpayload
462462

463463

‎github3/models.py‎

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
github3.models
4-
==============
5-
6-
This module provides the basic models used in github3.py
7-
8-
"""
2+
"""This module provides the basic models used in github3.py."""
93
from __future__importunicode_literals
104

115
fromdatetimeimportdatetime
@@ -16,7 +10,6 @@
1610
fromrequests.compatimportis_py2,urlparse
1711

1812
from .importexceptions
19-
from .decoratorsimportrequires_auth
2013
from .sessionimportGitHubSession
2114
from .utilsimportUTC
2215

@@ -352,66 +345,6 @@ def new_session(self):
352345
returnGitHubSession()
353346

354347

355-
classBaseComment(GitHubCore):
356-
357-
"""A basic class for Gist, Issue and Pull Request Comments."""
358-
359-
def_update_attributes(self,comment):
360-
#: Unique ID of the comment.
361-
self.id=self._get_attribute(comment,'id')
362-
363-
#: Body of the comment. (As written by the commenter)
364-
self.body=self._get_attribute(comment,'body')
365-
366-
#: Body of the comment formatted as plain-text. (Stripped of markdown,
367-
#: etc.)
368-
self.body_text=self._get_attribute(comment,'body_text')
369-
370-
#: Body of the comment formatted as html.
371-
self.body_html=self._get_attribute(comment,'body_html')
372-
373-
#: datetime object representing when the comment was created.
374-
self.created_at=self._strptime_attribute(comment,'created_at')
375-
376-
#: datetime object representing when the comment was updated.
377-
self.updated_at=self._strptime_attribute(comment,'updated_at')
378-
379-
self._api=self._get_attribute(comment,'url')
380-
self.links=self._get_attribute(comment,'_links', {})
381-
#: The url of this comment at GitHub
382-
self.html_url=''
383-
384-
#: The url of the pull request, if it exists
385-
self.pull_request_url=''
386-
ifself.links:
387-
self.html_url=self.links.get('html')
388-
self.pull_request_url=self.links.get('pull_request')
389-
390-
@requires_auth
391-
defdelete(self):
392-
"""Delete this comment.
393-
394-
:returns: bool
395-
"""
396-
returnself._boolean(self._delete(self._api),204,404)
397-
398-
@requires_auth
399-
defedit(self,body):
400-
"""Edit this comment.
401-
402-
:param str body: (required), new body of the comment, Markdown
403-
formatted
404-
:returns: bool
405-
"""
406-
ifbody:
407-
json=self._json(self._patch(self._api,
408-
data=dumps({'body':body})),200)
409-
ifjson:
410-
self._update_attributes(json)
411-
returnTrue
412-
returnFalse
413-
414-
415348
classBaseCommit(GitHubCore):
416349

417350
"""This abstracts a lot of the common attributes for commit-like objects.
@@ -439,69 +372,3 @@ def _update_attributes(self, commit):
439372
self.sha=self._api[i+1:]
440373

441374
self._uniq=self.sha
442-
443-
444-
classBaseAccount(GitHubCore):
445-
446-
"""This class holds the commonalities of Organizations and Users.
447-
448-
The :class:`BaseAccount <BaseAccount>` object is used to do the
449-
heavy lifting for :class:`Organization <github3.orgs.Organization>` and
450-
:class:`User <github3.users.User>` objects.
451-
"""
452-
453-
def_update_attributes(self,acct):
454-
#: Tells you what type of account this is
455-
self.type=self._get_attribute(acct,'type')
456-
457-
self._api=self._get_attribute(acct,'url')
458-
459-
#: URL of the avatar at gravatar
460-
self.avatar_url=self._get_attribute(acct,'avatar_url')
461-
462-
#: URL of the blog
463-
self.blog=self._get_attribute(acct,'blog')
464-
465-
#: Name of the company
466-
self.company=self._get_attribute(acct,'company')
467-
468-
#: datetime object representing the date the account was created
469-
self.created_at=self._strptime_attribute(acct,'created_at')
470-
471-
#: E-mail address of the user/org
472-
self.email=self._get_attribute(acct,'email')
473-
474-
# The number of people following this acct
475-
#: Number of followers
476-
self.followers_count=self._get_attribute(acct,'followers')
477-
478-
# The number of people this acct follows
479-
#: Number of people the user is following
480-
self.following_count=self._get_attribute(acct,'following')
481-
482-
#: Unique ID of the account
483-
self.id=self._get_attribute(acct,'id')
484-
485-
#: Location of the user/org
486-
self.location=self._get_attribute(acct,'location')
487-
488-
#: User name of the user/organization
489-
self.login=self._get_attribute(acct,'login')
490-
491-
# e.g. first_name last_name
492-
#: Real name of the user/org
493-
self.name=self._get_attribute(acct,'name')
494-
495-
# The number of public_repos
496-
#: Number of public repos owned by the user/org
497-
self.public_repos_count=self._get_attribute(acct,'public_repos')
498-
499-
# e.g. https://github.com/self._login
500-
#: URL of the user/org's profile
501-
self.html_url=self._get_attribute(acct,'html_url')
502-
503-
#: Markdown formatted biography
504-
self.bio=self._get_attribute(acct,'bio')
505-
506-
def_repr(self):
507-
return'<{s.type} [{s.login}:{s.name}]>'.format(s=self)

‎github3/repos/comment.py‎

Lines changed: 126 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
# -*- 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."""
93
from __future__importunicode_literals
104

5+
from ..importmodels
116
from ..importusers
127

138
from ..decoratorsimportrequires_auth
14-
from ..modelsimportBaseComment
159

1610

17-
classRepoComment(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.
2015
2116
Two comment instances can be checked like so::
2217
@@ -29,49 +24,135 @@ class RepoComment(BaseComment):
2924
c1.id != c2.id
3025
3126
"""
27+
28+
class_name='_RepoComment'
29+
3230
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)
3443

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.loginor''
47+
)
3748

38-
#: URL of the comment on GitHub.
39-
self.html_url=self._get_attribute(comment,'html_url')
49+
@requires_auth
50+
defdelete(self):
51+
"""Delete this comment.
4052
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+
returnself._boolean(self._delete(self._api),204,404)
4359

44-
#: The path to the file where the comment was made.
45-
self.path=self._get_attribute(comment,'path')
60+
@requires_auth
61+
defedit(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+
ifbody:
72+
json=self._json(self._patch(self._api,
73+
json={'body':body}),200)
74+
ifjson:
75+
self._update_attributes(json)
76+
returnTrue
77+
returnFalse
4678

47-
#: The position in the diff where the comment was made.
48-
self.position=self._get_attribute(comment,'position')
79+
update=edit
4980

50-
#: datetime object representing when the comment was updated.
51-
self.updated_at=self._strptime_attribute(comment,'updated_at')
5281

53-
#: Login of the user who left the comment.
54-
self.user=self._class_attribute(
55-
comment,'user',users.ShortUser,self
56-
)
82+
classShortComment(_RepoComment):
83+
"""The representation of an abridged comment on an object in a repo.
5784
58-
def_repr(self):
59-
return'<Repository Comment [{0}/{1}]>'.format(
60-
self.commit_id[:7],self.user.loginor''
61-
)
85+
This object has the following attributes:
6286
63-
@requires_auth
64-
defupdate(self,body):
65-
"""Update this comment.
87+
.. attribute:: author_association
6688
67-
:param str body: (required)
68-
:returns: bool
69-
"""
70-
json=None
71-
ifbody:
72-
json=self._json(self._post(self._api,data={'body':body}),200)
89+
The affiliation the author of this comment has with the repository.
7390
74-
ifjson:
75-
self._update_attributes(json)
76-
returnTrue
77-
returnFalse
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+
classRepoComment(_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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp