@@ -24,25 +24,25 @@ class Blob(GitHubCore):
24
24
"""
25
25
26
26
def _update_attributes (self , blob ):
27
- self ._api = self . _get_attribute ( blob , 'url' )
27
+ self ._api = blob [ 'url' ]
28
28
29
29
#: Raw content of the blob.
30
- self .content = self . _get_attribute ( blob , 'content' )
30
+ self .content = blob [ 'content' ]
31
31
if self .content is not None :
32
32
self .content = self .content .encode ()
33
33
34
34
#: Encoding of the raw content.
35
- self .encoding = self . _get_attribute ( blob , 'encoding' )
35
+ self .encoding = blob [ 'encoding' ]
36
36
37
37
#: Decoded content of the blob.
38
38
self .decoded = self .content
39
39
if self .encoding == 'base64' :
40
40
self .decoded = b64decode (self .content )
41
41
42
42
#: Size of the blob in bytes
43
- self .size = self . _get_attribute ( blob , 'size' )
43
+ self .size = blob [ 'size' ]
44
44
#: SHA1 of the blob
45
- self .sha = self . _get_attribute ( blob , 'sha' )
45
+ self .sha = blob [ 'sha' ]
46
46
47
47
def _repr (self ):
48
48
return '<Blob [{0:.10}]>' .format (self .sha )
@@ -58,8 +58,8 @@ class GitData(GitHubCore):
58
58
59
59
def _update_attributes (self , data ):
60
60
#: 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' ]
63
63
64
64
65
65
class Commit (BaseCommit ):
@@ -75,21 +75,25 @@ def _update_attributes(self, commit):
75
75
super (Commit , self )._update_attributes (commit )
76
76
#: dict containing at least the name, email and date the commit was
77
77
#: 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' ]
81
82
82
83
#: 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' ]
85
88
86
- self ._commit_name = self ._get_attribute (self .committer , 'name' )
89
+ if self .committer .get ('name' ):
90
+ self ._commit_name = self .committer ['name' ]
87
91
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 )
90
94
91
95
def _repr (self ):
92
- return '<Commit [{0}:{1} ]>' .format (self . _author_name , self .sha )
96
+ return '<Commit [{0}]>' .format (self .sha )
93
97
94
98
95
99
class Reference (GitHubCore ):
@@ -102,13 +106,13 @@ class Reference(GitHubCore):
102
106
"""
103
107
104
108
def _update_attributes (self , ref ):
105
- self ._api = self . _get_attribute ( ref , 'url' )
109
+ self ._api = ref [ 'url' ]
106
110
107
111
#: The reference path, e.g., refs/heads/sc/featureA
108
- self .ref = self . _get_attribute ( ref , 'ref' )
112
+ self .ref = ref [ 'ref' ]
109
113
110
114
#: :class:`GitObject <GitObject>` the reference points to
111
- self .object = self . _class_attribute (ref , 'object' , GitObject , self )
115
+ self .object = GitObject (ref [ 'object' ] , self )
112
116
113
117
def _repr (self ):
114
118
return '<Reference [{0}]>' .format (self .ref )
@@ -146,7 +150,7 @@ class GitObject(GitData):
146
150
def _update_attributes (self , obj ):
147
151
super (GitObject , self )._update_attributes (obj )
148
152
#: The type of object.
149
- self .type = self . _get_attribute ( obj , 'type' )
153
+ self .type = obj [ 'type' ]
150
154
151
155
def _repr (self ):
152
156
return '<Git Object [{0}]>' .format (self .sha )
@@ -164,21 +168,43 @@ def _update_attributes(self, tag):
164
168
super (Tag , self )._update_attributes (tag )
165
169
166
170
#: String of the tag
167
- self .tag = self . _get_attribute ( tag , 'tag' )
171
+ self .tag = tag [ 'tag' ]
168
172
169
173
#: Commit message for the tag
170
- self .message = self . _get_attribute ( tag , 'message' )
174
+ self .message = tag [ 'message' ]
171
175
172
176
#: dict containing the name and email of the person
173
- self .tagger = self . _get_attribute ( tag , 'tagger' )
177
+ self .tagger = tag [ 'tagger' ]
174
178
175
179
#: :class:`GitObject <GitObject>` for the tag
176
- self .object = self . _class_attribute (tag , 'object' , GitObject , self )
180
+ self .object = GitObject (tag [ 'object' ] , self )
177
181
178
182
def _repr (self ):
179
183
return '<Tag [{0}]>' .format (self .tag )
180
184
181
185
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
+
182
208
class Tree (GitData ):
183
209
184
210
"""The :class:`Tree <Tree>` object.
@@ -191,7 +217,7 @@ def _update_attributes(self, tree):
191
217
super (Tree , self )._update_attributes (tree )
192
218
193
219
#: list of :class:`Hash <Hash>` objects
194
- self .tree = self . _get_attribute ( tree , 'tree' , [])
220
+ self .tree = tree [ 'tree' ]
195
221
if self .tree :
196
222
self .tree = [Hash (t , self ) for t in self .tree ]
197
223
@@ -224,22 +250,24 @@ class Hash(GitHubCore):
224
250
225
251
def _update_attributes (self , info ):
226
252
#: Path to file
227
- self .path = self . _get_attribute ( info , 'path' )
253
+ self .path = info [ 'path' ]
228
254
229
255
#: File mode
230
- self .mode = self . _get_attribute ( info , 'mode' )
256
+ self .mode = info [ 'mode' ]
231
257
232
258
#: Type of hash, e.g., blob
233
- self .type = self . _get_attribute ( info , 'type' )
259
+ self .type = info [ 'type' ]
234
260
235
261
#: 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' ]
237
265
238
266
#: SHA of the hash
239
- self .sha = self . _get_attribute ( info , 'sha' )
267
+ self .sha = info [ 'sha' ]
240
268
241
269
#: URL of this object in the GitHub API
242
- self .url = self . _get_attribute ( info , 'url' )
270
+ self .url = info [ 'url' ]
243
271
244
272
def _repr (self ):
245
273
return '<Hash [{0}]>' .format (self .sha )
0 commit comments