From f23ad16aaaf4c5b2f312317cabf3c3e67dccc92b Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 9 May 2012 18:20:26 +0200 Subject: [PATCH] Add a GitAuthor class --- .../description.000.human_readable.json | 14 +++- .../description.001.normalized.json | 38 +++++++++-- NewIntegrationTest.py | 8 ++- ReferenceOfClasses.md | 13 +++- github/GithubObjects/GitAuthor.py | 65 +++++++++++++++++++ github/GithubObjects/GitCommit.py | 7 +- 6 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 github/GithubObjects/GitAuthor.py diff --git a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index 3cd91314..468d9244 100644 --- a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -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": { diff --git a/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 15bd91e5..634a227b 100644 --- a/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -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" }, diff --git a/NewIntegrationTest.py b/NewIntegrationTest.py index 537e0763..ca0d8deb 100644 --- a/NewIntegrationTest.py +++ b/NewIntegrationTest.py @@ -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" ) diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 35632e60..64b12969 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -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` diff --git a/github/GithubObjects/GitAuthor.py b/github/GithubObjects/GitAuthor.py new file mode 100644 index 00000000..e6e12a92 --- /dev/null +++ b/github/GithubObjects/GitAuthor.py @@ -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" ] diff --git a/github/GithubObjects/GitCommit.py b/github/GithubObjects/GitCommit.py index efa7acf3..8724d508 100644 --- a/github/GithubObjects/GitCommit.py +++ b/github/GithubObjects/GitCommit.py @@ -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: