Add a GitAuthor class

This commit is contained in:
Vincent Jacques
2012-05-09 18:20:26 +02:00
parent 80b4e550f3
commit f23ad16aaa
6 changed files with 133 additions and 12 deletions
@@ -512,8 +512,8 @@
{
"name": "GitCommit",
"attributes": [
{ "name": "author", "type": "@todo" },
{ "name": "committer", "type": "@todo" },
{ "name": "author", "type": "GitAuthor" },
{ "name": "committer", "type": "GitAuthor" },
{ "name": "message", "type": "@todo" },
{ "name": "parents", "type": "@todo" },
{ "name": "sha", "type": "@todo" },
@@ -565,6 +565,16 @@
"collections": [
]
},
{
"name": "GitAuthor",
"attributes": [
{ "name": "date", "type": "string" },
{ "name": "email", "type": "string" },
{ "name": "name", "type": "string" }
],
"collections": [
]
},
{
"name": "Hook",
"edit": {
@@ -2903,6 +2903,36 @@
}
]
},
{
"attributes": [
{
"type": {
"simple": true,
"cardinality": "scalar",
"name": "string"
},
"name": "date"
},
{
"type": {
"simple": true,
"cardinality": "scalar",
"name": "string"
},
"name": "email"
},
{
"type": {
"simple": true,
"cardinality": "scalar",
"name": "string"
},
"name": "name"
}
],
"name": "GitAuthor",
"methods": []
},
{
"attributes": [
{
@@ -2953,17 +2983,17 @@
"attributes": [
{
"type": {
"simple": true,
"simple": false,
"cardinality": "scalar",
"name": "@todo"
"name": "GitAuthor"
},
"name": "author"
},
{
"type": {
"simple": true,
"simple": false,
"cardinality": "scalar",
"name": "@todo"
"name": "GitAuthor"
},
"name": "committer"
},
+6 -2
View File
@@ -203,8 +203,12 @@ class GitCommit( TestCase ):
self.c = self.g.get_user().get_repo( "PyGithub" ).get_git_commit( "4303c5b90e2216d927155e9609436ccb8984c495" )
def testAttributes( self ):
self.assertEqual( self.c.author, { "date": "2012-04-17T10:55:16-07:00", "email": "vincent@vincent-jacques.net", "name": "Vincent Jacques" } ) ### @todo Structure
self.assertEqual( self.c.committer, { "date": "2012-04-17T10:55:16-07:00", "email": "vincent@vincent-jacques.net", "name": "Vincent Jacques" } ) ### @todo Structure
self.assertEqual( self.c.author.name, "Vincent Jacques" )
self.assertEqual( self.c.author.email, "vincent@vincent-jacques.net" )
self.assertEqual( self.c.author.date, "2012-04-17T10:55:16-07:00" )
self.assertEqual( self.c.committer.name, "Vincent Jacques" )
self.assertEqual( self.c.committer.email, "vincent@vincent-jacques.net" )
self.assertEqual( self.c.committer.date, "2012-04-17T10:55:16-07:00" )
self.assertEqual( self.c.message, "Merge branch 'develop'\n" )
self.assertEqual( self.c.parents, [{u'url': u'https://api.github.com/repos/jacquev6/PyGithub/git/commits/936f4a97f1a86392637ec002bbf89ff036a5062d', u'sha': u'936f4a97f1a86392637ec002bbf89ff036a5062d'}, {u'url': u'https://api.github.com/repos/jacquev6/PyGithub/git/commits/2a7e80e6421c5d4d201d60619068dea6bae612cb', u'sha': u'2a7e80e6421c5d4d201d60619068dea6bae612cb'}] ) ### @todo Structure
self.assertEqual( self.c.sha, "4303c5b90e2216d927155e9609436ccb8984c495" )
+11 -2
View File
@@ -349,6 +349,15 @@ Modification
* `edit( body )`
* `body`
Class `GitAuthor`
=================
Attributes
----------
* `date`: string
* `email`: string
* `name`: string
Class `GitBlob`
===============
@@ -365,8 +374,8 @@ Class `GitCommit`
Attributes
----------
* `author`
* `committer`
* `author`: `GitAuthor`
* `committer`: `GitAuthor`
* `message`
* `parents`
* `sha`
+65
View File
@@ -0,0 +1,65 @@
# WARNING: this file is generated automaticaly.
# Do not modify it manually, your work would be lost.
import PaginatedList
# This allows None as a valid value for an optional parameter
class DefaultValueForOptionalParametersType:
pass
DefaultValueForOptionalParameters = DefaultValueForOptionalParametersType()
class GitAuthor( object ):
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
if not lazy:
self.__complete()
@property
def date( self ):
self.__completeIfNeeded( self.__date )
return self.__date
@property
def email( self ):
self.__completeIfNeeded( self.__email )
return self.__email
@property
def name( self ):
self.__completeIfNeeded( self.__name )
return self.__name
def __initAttributes( self ):
self.__date = None
self.__email = None
self.__name = None
def __completeIfNeeded( self, testedAttribute ):
if not self.__completed and testedAttribute is None:
self.__complete()
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "date" in attributes and attributes[ "date" ] is not None:
assert isinstance( attributes[ "date" ], ( str, unicode ) )
self.__date = attributes[ "date" ]
if "email" in attributes and attributes[ "email" ] is not None:
assert isinstance( attributes[ "email" ], ( str, unicode ) )
self.__email = attributes[ "email" ]
if "name" in attributes and attributes[ "name" ] is not None:
assert isinstance( attributes[ "name" ], ( str, unicode ) )
self.__name = attributes[ "name" ]
+5 -2
View File
@@ -2,6 +2,7 @@
# Do not modify it manually, your work would be lost.
import PaginatedList
import GitAuthor
import GitTree
# This allows None as a valid value for an optional parameter
@@ -79,9 +80,11 @@ class GitCommit( object ):
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "author" in attributes and attributes[ "author" ] is not None:
self.__author = attributes[ "author" ]
assert isinstance( attributes[ "author" ], dict )
self.__author = GitAuthor.GitAuthor( self.__requester, attributes[ "author" ], lazy = True )
if "committer" in attributes and attributes[ "committer" ] is not None:
self.__committer = attributes[ "committer" ]
assert isinstance( attributes[ "committer" ], dict )
self.__committer = GitAuthor.GitAuthor( self.__requester, attributes[ "committer" ], lazy = True )
if "message" in attributes and attributes[ "message" ] is not None:
self.__message = attributes[ "message" ]
if "parents" in attributes and attributes[ "parents" ] is not None: