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

Commit0517bbe

Browse files
committed
Update github3.repos.commit for consistency
1 parent0b1e5cd commit0517bbe

File tree

10 files changed

+116
-88
lines changed

10 files changed

+116
-88
lines changed

‎github3/models.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ def _instance_or_null(self, instance_class, json):
193193
)
194194
ifnotjson:
195195
returnNone
196-
try:
197-
returninstance_class(json,self)
198-
exceptTypeError:# instance_class is not a subclass of GitHubCore
199-
returninstance_class(json)
196+
197+
returninstance_class(json,self)
200198

201199
def_json(self,response,status_code,include_cache_info=True):
202200
ret=None

‎github3/pulls.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from .importmodels
1010
from .importusers
11+
from .reposimportcommitasrcommit
1112
from .decoratorsimportrequires_auth
1213
from .issuesimportIssue
1314
from .issues.commentimportIssueComment
14-
from .repos.commitimportRepoCommit
1515
from .repos.contentsimportContents
1616

1717

@@ -328,10 +328,10 @@ def commits(self, number=-1, etag=None):
328328
:returns:
329329
generator of repository commit objects
330330
:rtype:
331-
:class:`~github3.repos.commit.RepoCommit`
331+
:class:`~github3.repos.commit.ShortCommit`
332332
"""
333333
url=self._build_url('commits',base_url=self._api)
334-
returnself._iter(int(number),url,RepoCommit,etag=etag)
334+
returnself._iter(int(number),url,rcommit.ShortCommit,etag=etag)
335335

336336
deffiles(self,number=-1,etag=None):
337337
"""Iterate over the files associated with this pull request.

‎github3/repos/branch.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from .importcommit
88
from ..importmodels
99

10-
from .commitimportRepoCommit
11-
1210

1311
class_Branch(models.GitHubCore):
1412
"""A representation of a branch on a repository.
@@ -25,7 +23,7 @@ class _Branch(models.GitHubCore):
2523
class_name='Repository Branch'
2624

2725
def_update_attributes(self,branch):
28-
self.commit=commit.RepoCommit(branch['commit'],self)
26+
self.commit=commit.MiniCommit(branch['commit'],self)
2927
self.name=branch['name']
3028

3129
def_repr(self):
@@ -110,7 +108,7 @@ class ShortBranch(_Branch):
110108
111109
.. attribute:: commit
112110
113-
A :class:`~github3.repos.commit.RepoCommit` representation of the
111+
A :class:`~github3.repos.commit.MiniCommit` representation of the
114112
newest commit on this branch with the associated repository metadata.
115113
116114
.. attribute:: name
@@ -158,6 +156,7 @@ class Branch(_Branch):
158156

159157
def_update_attributes(self,branch):
160158
super(Branch,self)._update_attributes(branch)
159+
self.commit=commit.ShortCommit(branch['commit'],self)
161160
#: Returns '_links' attribute.
162161
self.links=branch['_links']
163162
#: Provides the branch's protection status.
@@ -166,7 +165,7 @@ def _update_attributes(self, branch):
166165
self.protection_url=branch['protection_url']
167166
ifself.linksand'self'inself.links:
168167
self._api=self.links['self']
169-
elifisinstance(self.commit,RepoCommit):
168+
elifisinstance(self.commit,commit.ShortCommit):
170169
# Branches obtained via `repo.branches` don't have links.
171170
base=self.commit.url.split('/commit',1)[0]
172171
self._api=self._build_url('branches',self.name,base_url=base)

‎github3/repos/commit.py‎

Lines changed: 86 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
github3.repos.commit
4-
====================
5-
6-
This module contains the RepoCommit class alone
7-
8-
"""
2+
"""This module contains the RepoCommit classes."""
93
from __future__importunicode_literals
104

115
from .importstatus
126
from ..importgit,models,users
137
from .commentimportRepoComment
148

159

16-
classRepoCommit(models.BaseCommit):
17-
"""The :class:`RepoCommit <RepoCommit>` object. This represents a commit as
10+
class_RepoCommit(models.GitHubCore):
11+
"""The :class:`RepoCommit <RepoCommit>` object.
12+
13+
This represents a commit as
1814
viewed by a :class:`Repository`. This is different from a Commit object
1915
returned from the git data section.
2016
@@ -30,53 +26,23 @@ class RepoCommit(models.BaseCommit):
3026
3127
"""
3228

33-
def_update_attributes(self,commit):
34-
super(RepoCommit,self)._update_attributes(commit)
35-
36-
self.author=self._class_attribute(
37-
commit,'author',users.ShortUser,self
38-
)
39-
self.committer=self._class_attribute(
40-
commit,'committer',users.ShortUser,self
41-
)
29+
class_name='_RepoCommit'
4230

43-
#: :class:`Commit <github3.git.Commit>`.
44-
self.commit=self._class_attribute(
45-
commit,'commit',git.ShortCommit,self,
46-
)
47-
48-
self.sha=self._get_attribute(commit,'sha')
49-
50-
#: The number of additions made in the commit.
51-
self.additions=0
52-
53-
#: The number of deletions made in the commit.
54-
self.deletions=0
55-
56-
#: Total number of changes in the files.
57-
self.total=0
58-
stats=self._get_attribute(commit,'stats')
59-
ifstats:
60-
self.additions=commit['stats'].get('additions')
61-
self.deletions=commit['stats'].get('deletions')
62-
self.total=commit['stats'].get('total')
63-
64-
#: The files that were modified by this commit.
65-
self.files=self._get_attribute(commit,'files', [])
66-
67-
self._uniq=self.sha
68-
69-
#: The commit message
70-
self.message=getattr(self.commit,'message',None)
31+
def_update_attributes(self,commit):
32+
self._api=commit['url']
33+
#: SHA of this commit.
34+
self._uniq=self.sha=commit['sha']
7135

7236
def_repr(self):
73-
return'<Repository Commit [{0}]>'.format(self.sha[:7])
37+
return'<{0} [{1}]>'.format(self.class_name,self.sha[:7])
7438

7539
defdiff(self):
7640
"""Retrieve the diff for this commit.
7741
78-
:returns: the diff as a bytes object
79-
:rtype: bytes
42+
:returns:
43+
the diff as a bytes object
44+
:rtype:
45+
bytes
8046
"""
8147
resp=self._get(self._api,
8248
headers={'Accept':'application/vnd.github.diff'})
@@ -85,8 +51,10 @@ def diff(self):
8551
defpatch(self):
8652
"""Retrieve the patch formatted diff for this commit.
8753
88-
:returns: the patch as a bytes object
89-
:rtype: bytes
54+
:returns:
55+
the patch as a bytes object
56+
:rtype:
57+
bytes
9058
"""
9159
resp=self._get(self._api,
9260
headers={'Accept':'application/vnd.github.patch'})
@@ -95,8 +63,10 @@ def patch(self):
9563
defstatus(self):
9664
"""Retrieve the combined status for this commit.
9765
98-
:returns: the combined status for this commit
99-
:rtype: :class:`~github3.repos.status.CombinedStatus`
66+
:returns:
67+
the combined status for this commit
68+
:rtype:
69+
:class:`~github3.repos.status.CombinedStatus`
10070
"""
10171
url=self._build_url('status',base_url=self._api)
10272
json=self._json(self._get(url),200)
@@ -105,21 +75,76 @@ def status(self):
10575
defstatuses(self):
10676
"""Retrieve the statuses for this commit.
10777
108-
:returns: the statuses for this commit
109-
:rtype: :class:`~github3.repos.status.Status`
78+
:returns:
79+
the statuses for this commit
80+
:rtype:
81+
:class:`~github3.repos.status.Status`
11082
"""
11183
url=self._build_url('statuses',base_url=self._api)
11284
returnself._iter(-1,url,status.Status)
11385

11486
defcomments(self,number=-1,etag=None):
11587
"""Iterate over comments for this commit.
11688
117-
:param int number: (optional), number of comments to return. Default:
118-
-1 returns all comments
119-
:param str etag: (optional), ETag from a previous request to the same
120-
endpoint
121-
:returns: generator of
122-
:class:`RepoComment <github3.repos.comment.RepoComment>`\ s
89+
:param int number:
90+
(optional), number of comments to return. Default: -1 returns all
91+
comments
92+
:param str etag:
93+
(optional), ETag from a previous request to the same endpoint
94+
:returns:
95+
generator of comments
96+
:rtype:
97+
:class:~github3.repos.comment.RepoComment`
12398
"""
12499
url=self._build_url('comments',base_url=self._api)
125100
returnself._iter(int(number),url,RepoComment,etag=etag)
101+
102+
103+
classMiniCommit(_RepoCommit):
104+
"""A commit returned on a ShortBranch."""
105+
106+
class_name='Mini Repository Commit'
107+
108+
109+
classShortCommit(_RepoCommit):
110+
"""Representation of an incomplete commit in a collection."""
111+
112+
class_name='Short Repository Commit'
113+
114+
def_update_attributes(self,commit):
115+
super(ShortCommit,self)._update_attributes(commit)
116+
self.author=commit['author']
117+
ifself.author:
118+
self.author=users.ShortUser(self.author,self)
119+
self.comments_url=commit['comments_url']
120+
self.commit=git.ShortCommit(commit['commit'],self)
121+
self.committer=commit['committer']
122+
ifself.committer:
123+
self.committer=users.ShortUser(self.committer,self)
124+
self.html_url=commit['html_url']
125+
#: List of parents to this commit.
126+
self.parents=commit['parents']
127+
#: The commit message
128+
self.message=getattr(self.commit,'message',None)
129+
130+
131+
classRepoCommit(_RepoCommit):
132+
"""Representation of a commit with repository and git data."""
133+
134+
class_name='Repository Commit'
135+
136+
def_update_attributes(self,commit):
137+
super(RepoCommit,self)._update_attributes(commit)
138+
#: The number of additions made in the commit.
139+
self.additions=0
140+
#: The number of deletions made in the commit.
141+
self.deletions=0
142+
#: The files that were modified by this commit.
143+
self.files=commit['files']
144+
#: Total number of changes in the files.
145+
self.total=0
146+
self.stats=commit['stats']
147+
ifself.stats:
148+
self.additions=self.stats['additions']
149+
self.deletions=self.stats['deletions']
150+
self.total=self.stats['total']

‎github3/repos/comparison.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"""
1010
from __future__importunicode_literals
1111

12+
from .importcommit
13+
1214
from ..modelsimportGitHubCore
13-
from .commitimportRepoCommit
1415

1516

1617
classComparison(GitHubCore):
@@ -50,7 +51,7 @@ def _update_attributes(self, compare):
5051
#: :class:`RepoCommit <github3.repos.commit.RepoCommit>` object
5152
#: representing the base of comparison.
5253
self.base_commit=self._class_attribute(
53-
compare,'base_commit',RepoCommit,None
54+
compare,'base_commit',commit.ShortCommit,None
5455
)
5556

5657
#: Behind or ahead.
@@ -69,7 +70,9 @@ def _update_attributes(self, compare):
6970
#: objects.
7071
self.commits=self._get_attribute(compare,'commits', [])
7172
ifself.commits:
72-
self.commits= [RepoCommit(com,self)forcominself.commits]
73+
self.commits= [
74+
commit.ShortCommit(com,self)forcominself.commits
75+
]
7376

7477
#: List of dicts describing the files modified.
7578
self.files=self._get_attribute(compare,'files', [])

‎github3/repos/repo.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
from ..pullsimportShortPullRequest,PullRequest
2929
from ..utilsimportstream_response_to_file,timestamp_parameter
3030
from .importbranch
31-
from .branchimportBranch
31+
from .importcommit
3232
from .commentimportRepoComment
33-
from .commitimportRepoCommit
3433
from .comparisonimportComparison
3534
from .contentsimportContents,validate_commmitter
3635
from .deploymentimportDeployment
@@ -203,9 +202,10 @@ def branch(self, name):
203202
json=None
204203
ifname:
205204
url=self._build_url('branches',name,base_url=self._api)
206-
json=self._json(self._get(url,headers=Branch.PREVIEW_HEADERS),
205+
json=self._json(self._get(url,
206+
headers=branch.Branch.PREVIEW_HEADERS),
207207
200)
208-
returnself._instance_or_null(Branch,json)
208+
returnself._instance_or_null(branch.Branch,json)
209209

210210
defbranches(self,number=-1,protected=False,etag=None):
211211
r"""Iterate over the branches in this repository.
@@ -284,7 +284,7 @@ def commit(self, sha):
284284
"""
285285
url=self._build_url('commits',sha,base_url=self._api)
286286
json=self._json(self._get(url),200)
287-
returnself._instance_or_null(RepoCommit,json)
287+
returnself._instance_or_null(commit.RepoCommit,json)
288288

289289
defcommit_activity(self,number=-1,etag=None):
290290
"""Iterate over last year of commit activity by week.
@@ -352,7 +352,7 @@ def commits(self, sha=None, path=None, author=None, number=-1, etag=None,
352352

353353
self._remove_none(params)
354354
url=self._build_url('commits',base_url=self._api)
355-
returnself._iter(int(number),url,RepoCommit,params,etag)
355+
returnself._iter(int(number),url,commit.ShortCommit,params,etag)
356356

357357
defcompare_commits(self,base,head):
358358
"""Compare two commits.
@@ -1395,7 +1395,7 @@ def merge(self, base, head, message=''):
13951395
ifmessage:
13961396
data['commit_message']=message
13971397
json=self._json(self._post(url,data=data),201)
1398-
returnself._instance_or_null(RepoCommit,json)
1398+
returnself._instance_or_null(commit.ShortCommit,json)
13991399

14001400
defmilestone(self,number):
14011401
"""Get the milestone indicated by ``number``.

‎tests/integration/test_pulls.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
classTestPullRequest(IntegrationHelper):
10-
1110
"""PullRequest integration tests."""
1211

1312
defget_pull_request(self,repository='sigmavirus24/github3.py',num=235):
@@ -43,7 +42,7 @@ def test_commits(self):
4342
withself.recorder.use_cassette(cassette_name):
4443
p=self.get_pull_request()
4544
forcommitinp.commits():
46-
assertisinstance(commit,github3.repos.commit.RepoCommit)
45+
assertisinstance(commit,github3.repos.commit.ShortCommit)
4746

4847
deftest_create_review_comment(self):
4948
"""Show that a user can create an in-line reveiw comment on a PR."""
@@ -175,6 +174,7 @@ class TestPullFile(IntegrationHelper):
175174
"""Integration tests for the PullFile object."""
176175

177176
defget_pull_request_file(self,owner,repo,pull_number,filename):
177+
"""Helper method to retrieve a PR file."""
178178
p=self.gh.pull_request(owner,repo,pull_number)
179179

180180
forpull_fileinp.files():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp