@@ -24,25 +24,25 @@ class Blob(GitHubCore):
2424 """
2525
2626def _update_attributes (self ,blob ):
27- self ._api = self . _get_attribute ( blob , 'url' )
27+ self ._api = blob [ 'url' ]
2828
2929#: Raw content of the blob.
30- self .content = self . _get_attribute ( blob , 'content' )
30+ self .content = blob [ 'content' ]
3131if self .content is not None :
3232self .content = self .content .encode ()
3333
3434#: Encoding of the raw content.
35- self .encoding = self . _get_attribute ( blob , 'encoding' )
35+ self .encoding = blob [ 'encoding' ]
3636
3737#: Decoded content of the blob.
3838self .decoded = self .content
3939if self .encoding == 'base64' :
4040self .decoded = b64decode (self .content )
4141
4242#: Size of the blob in bytes
43- self .size = self . _get_attribute ( blob , 'size' )
43+ self .size = blob [ 'size' ]
4444#: SHA1 of the blob
45- self .sha = self . _get_attribute ( blob , 'sha' )
45+ self .sha = blob [ 'sha' ]
4646
4747def _repr (self ):
4848return '<Blob [{0:.10}]>' .format (self .sha )
@@ -58,8 +58,8 @@ class GitData(GitHubCore):
5858
5959def _update_attributes (self ,data ):
6060#: SHA of the object
61- self .sha = self . _get_attribute ( data , 'sha' )
62- self ._api = self . _get_attribute ( data , 'url' )
61+ self .sha = data [ 'sha' ]
62+ self ._api = data [ 'url' ]
6363
6464
6565class Commit (BaseCommit ):
@@ -75,21 +75,25 @@ def _update_attributes(self, commit):
7575super (Commit ,self )._update_attributes (commit )
7676#: dict containing at least the name, email and date the commit was
7777#: created
78- self .author = self ._get_attribute (commit ,'author' , {})
79- # If GH returns nil/None then make sure author is a dict
80- self ._author_name = self ._get_attribute (self .author ,'name' )
78+ self .author = commit ['author' ]
79+ # GitHub may not provide a name for the author
80+ if self .author .get ('name' ):
81+ self ._author_name = self .author ['name' ]
8182
8283#: dict containing similar information to the author attribute
83- self .committer = self ._get_attribute (commit ,'committer' , {})
84- # blank the data if GH returns no data
84+ # If the committer is not different from the author, we may not get
85+ # a committer key
86+ if commit .get ('committer' ):
87+ self .committer = commit ['committer' ]
8588
86- self ._commit_name = self ._get_attribute (self .committer ,'name' )
89+ if self .committer .get ('name' ):
90+ self ._commit_name = self .committer ['name' ]
8791
88- #: :class:`Tree <Tree >` the commit belongs to.
89- self .tree = self . _class_attribute (commit , 'tree' , Tree ,self )
92+ #: :class:`CommitTree <CommitTree >` the commit belongs to.
93+ self .tree = CommitTree (commit [ 'tree' ] ,self )
9094
9195def _repr (self ):
92- return '<Commit [{0}:{1} ]>' .format (self . _author_name , self .sha )
96+ return '<Commit [{0}]>' .format (self .sha )
9397
9498
9599class Reference (GitHubCore ):
@@ -102,13 +106,13 @@ class Reference(GitHubCore):
102106 """
103107
104108def _update_attributes (self ,ref ):
105- self ._api = self . _get_attribute ( ref , 'url' )
109+ self ._api = ref [ 'url' ]
106110
107111#: The reference path, e.g., refs/heads/sc/featureA
108- self .ref = self . _get_attribute ( ref , 'ref' )
112+ self .ref = ref [ 'ref' ]
109113
110114#: :class:`GitObject <GitObject>` the reference points to
111- self .object = self . _class_attribute (ref , 'object' , GitObject ,self )
115+ self .object = GitObject (ref [ 'object' ] ,self )
112116
113117def _repr (self ):
114118return '<Reference [{0}]>' .format (self .ref )
@@ -146,7 +150,7 @@ class GitObject(GitData):
146150def _update_attributes (self ,obj ):
147151super (GitObject ,self )._update_attributes (obj )
148152#: The type of object.
149- self .type = self . _get_attribute ( obj , 'type' )
153+ self .type = obj [ 'type' ]
150154
151155def _repr (self ):
152156return '<Git Object [{0}]>' .format (self .sha )
@@ -164,21 +168,43 @@ def _update_attributes(self, tag):
164168super (Tag ,self )._update_attributes (tag )
165169
166170#: String of the tag
167- self .tag = self . _get_attribute ( tag , 'tag' )
171+ self .tag = tag [ 'tag' ]
168172
169173#: Commit message for the tag
170- self .message = self . _get_attribute ( tag , 'message' )
174+ self .message = tag [ 'message' ]
171175
172176#: dict containing the name and email of the person
173- self .tagger = self . _get_attribute ( tag , 'tagger' )
177+ self .tagger = tag [ 'tagger' ]
174178
175179#: :class:`GitObject <GitObject>` for the tag
176- self .object = self . _class_attribute (tag , 'object' , GitObject ,self )
180+ self .object = GitObject (tag [ 'object' ] ,self )
177181
178182def _repr (self ):
179183return '<Tag [{0}]>' .format (self .tag )
180184
181185
186+ class CommitTree (GitData ):
187+
188+ """The :class:`CommitTree <CommitTree>` object.
189+
190+ Represents the tree data found in a commit object
191+
192+ """
193+
194+ def _update_attributes (self ,tree ):
195+ super (CommitTree ,self )._update_attributes (tree )
196+
197+ def _repr (self ):
198+ return '<CommitTree [{0}]>' .format (self .sha )
199+
200+ def to_tree (self ):
201+ """Retrieve a full Tree object for this CommitTree."""
202+ json = self ._json (self ._get (self ._api ),200 )
203+ return self ._instance_or_null (Tree ,json )
204+
205+ refresh = to_tree
206+
207+
182208class Tree (GitData ):
183209
184210"""The :class:`Tree <Tree>` object.
@@ -191,7 +217,7 @@ def _update_attributes(self, tree):
191217super (Tree ,self )._update_attributes (tree )
192218
193219#: list of :class:`Hash <Hash>` objects
194- self .tree = self . _get_attribute ( tree , 'tree' , [])
220+ self .tree = tree [ 'tree' ]
195221if self .tree :
196222self .tree = [Hash (t ,self )for t in self .tree ]
197223
@@ -224,22 +250,24 @@ class Hash(GitHubCore):
224250
225251def _update_attributes (self ,info ):
226252#: Path to file
227- self .path = self . _get_attribute ( info , 'path' )
253+ self .path = info [ 'path' ]
228254
229255#: File mode
230- self .mode = self . _get_attribute ( info , 'mode' )
256+ self .mode = info [ 'mode' ]
231257
232258#: Type of hash, e.g., blob
233- self .type = self . _get_attribute ( info , 'type' )
259+ self .type = info [ 'type' ]
234260
235261#: Size of hash
236- self .size = self ._get_attribute (info ,'size' )
262+ # Size is not set if the type is a tree
263+ if self .type != 'tree' :
264+ self .size = info ['size' ]
237265
238266#: SHA of the hash
239- self .sha = self . _get_attribute ( info , 'sha' )
267+ self .sha = info [ 'sha' ]
240268
241269#: URL of this object in the GitHub API
242- self .url = self . _get_attribute ( info , 'url' )
270+ self .url = info [ 'url' ]
243271
244272def _repr (self ):
245273return '<Hash [{0}]>' .format (self .sha )