diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index b7e4df24..a5beea55 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -549,6 +549,16 @@ "collections": [ ] }, + { + "name": "GitObject", + "attributes": [ + { "name": "sha", "type": "string" }, + { "name": "type", "type": "string" }, + { "name": "url", "type": "string" } + ], + "collections": [ + ] + }, { "name": "GitRef", "edit": { @@ -561,9 +571,9 @@ }, "delete": true, "attributes": [ - { "name": "object", "type": "@todo" }, + { "name": "object", "type": "GitObject" }, { "name": "ref", "type": "string" }, - { "name": "url", "type": "@todo" } + { "name": "url", "type": "string" } ], "collections": [ ] @@ -1382,7 +1392,7 @@ }, "url": [ { "type": "attribute", "value": [ "url" ] }, - { "type": "constant", "value": "/git/refs" } + { "type": "constant", "value": "/git" } ] }, { diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 7d819f06..4373621d 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -3155,7 +3155,37 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" + }, + "name": "sha" + }, + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "type" + }, + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "url" + } + ], + "name": "GitObject", + "methods": [] + }, + { + "attributes": [ + { + "type": { + "simple": false, + "cardinality": "scalar", + "name": "GitObject" }, "name": "object" }, @@ -3171,7 +3201,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "url" } @@ -8188,7 +8218,7 @@ }, { "type": "constant", - "value": "/git/refs" + "value": "/git" } ], "information": "status", @@ -8229,7 +8259,7 @@ }, { "type": "constant", - "value": "/git/refs" + "value": "/git" }, { "type": "constant", @@ -8270,7 +8300,7 @@ }, { "type": "constant", - "value": "/git/refs" + "value": "/git" } ], "information": "data", diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 89398ae4..d7e69d6a 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -406,14 +406,23 @@ Attributes * `tree`: `GitTree` * `url`: string +Class `GitObject` +================= + +Attributes +---------- +* `sha`: string +* `type`: string +* `url`: string + Class `GitRef` ============== Attributes ---------- -* `object` +* `object`: `GitObject` * `ref`: string -* `url` +* `url`: string Deletion -------- diff --git a/src/github/GitObject.py b/src/github/GitObject.py new file mode 100644 index 00000000..5893f22c --- /dev/null +++ b/src/github/GitObject.py @@ -0,0 +1,64 @@ +# 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 GitObject( 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 sha( self ): + self.__completeIfNeeded( self.__sha ) + return self.__sha + + @property + def type( self ): + self.__completeIfNeeded( self.__type ) + return self.__type + + @property + def url( self ): + self.__completeIfNeeded( self.__url ) + return self.__url + + def __initAttributes( self ): + self.__sha = None + self.__type = None + self.__url = None + + def __completeIfNeeded( self, testedAttribute ): + if not self.__completed and testedAttribute is None: + self.__complete() + + 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 "sha" in attributes and attributes[ "sha" ] is not None: + assert isinstance( attributes[ "sha" ], ( str, unicode ) ) + self.__sha = attributes[ "sha" ] + if "type" in attributes and attributes[ "type" ] is not None: + assert isinstance( attributes[ "type" ], ( str, unicode ) ) + self.__type = attributes[ "type" ] + if "url" in attributes and attributes[ "url" ] is not None: + assert isinstance( attributes[ "url" ], ( str, unicode ) ) + self.__url = attributes[ "url" ] diff --git a/src/github/GitRef.py b/src/github/GitRef.py index a2f3b19c..8437f216 100644 --- a/src/github/GitRef.py +++ b/src/github/GitRef.py @@ -2,6 +2,7 @@ # Do not modify it manually, your work would be lost. import PaginatedList +import GitObject # This allows None as a valid value for an optional parameter class DefaultValueForOptionalParametersType: @@ -76,9 +77,11 @@ class GitRef( object ): def __useAttributes( self, attributes ): #@todo No need to check if attribute is in attributes when attribute is mandatory if "object" in attributes and attributes[ "object" ] is not None: - self.__object = attributes[ "object" ] + assert isinstance( attributes[ "object" ], dict ) + self.__object = GitObject.GitObject( self.__requester, attributes[ "object" ], lazy = True ) if "ref" in attributes and attributes[ "ref" ] is not None: assert isinstance( attributes[ "ref" ], ( str, unicode ) ) self.__ref = attributes[ "ref" ] if "url" in attributes and attributes[ "url" ] is not None: + assert isinstance( attributes[ "url" ], ( str, unicode ) ) self.__url = attributes[ "url" ] diff --git a/src/github/Repository.py b/src/github/Repository.py index c12e6ee9..253aa973 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -261,7 +261,7 @@ class Repository( object ): } status, headers, data = self.__requester.request( "POST", - str( self.url ) + "/git/refs", + str( self.url ) + "/git", None, post_parameters ) @@ -563,7 +563,7 @@ class Repository( object ): def get_git_ref( self, ref ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/git/refs" + "/" + str( ref ), + str( self.url ) + "/git" + "/" + str( ref ), None, None ) @@ -572,7 +572,7 @@ class Repository( object ): def get_git_refs( self ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/git/refs", + str( self.url ) + "/git", None, None ) diff --git a/test/GitObjects.py b/test/GitObjects.py index e839e087..3bd03cc8 100644 --- a/test/GitObjects.py +++ b/test/GitObjects.py @@ -44,6 +44,18 @@ class GitTree( Framework.TestCase ): self.assertEqual( len( self.t.tree ), 11 ) self.assertEqual( self.t.url, "https://api.github.com/repos/jacquev6/PyGithub/git/trees/f492784d8ca837779650d1fb406a1a3587a764ad" ) +class GitRef( Framework.TestCase ): + def setUp( self ): + Framework.TestCase.setUp( self ) + self.r = self.g.get_user().get_repo( "PyGithub" ).get_git_ref( "refs/heads/topic/RewriteWithGeneratedCode" ) + + def testAttributes( self ): + self.assertEqual( self.r.object.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a" ) + self.assertEqual( self.r.object.type, "commit" ) + self.assertEqual( self.r.object.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a" ) + self.assertEqual( self.r.ref, "refs/heads/topic/RewriteWithGeneratedCode" ) + self.assertEqual( self.r.url, "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/topic/RewriteWithGeneratedCode" ) + class Branch( Framework.TestCase ): def setUp( self ): Framework.TestCase.setUp( self ) diff --git a/test/ReplayData/GitRef.setUp.txt b/test/ReplayData/GitRef.setUp.txt new file mode 100644 index 00000000..be0210c9 --- /dev/null +++ b/test/ReplayData/GitRef.setUp.txt @@ -0,0 +1,15 @@ +GET /user {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4989'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"b945f11dd3b44dd11184918914b87c02"'), ('date', 'Thu, 10 May 2012 14:37:56 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"private_gists":5,"type":"User","url":"https://api.github.com/users/jacquev6","owned_private_repos":5,"disk_usage":16776,"plan":{"private_repos":5,"collaborators":1,"space":614400,"name":"micro"},"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jacquev6","collaborators":0,"email":"vincent@vincent-jacques.net","html_url":"https://github.com/jacquev6","created_at":"2010-07-09T06:10:06Z","company":"Criteo","location":"Paris, France","hireable":false,"public_repos":10,"followers":13,"following":24,"name":"Vincent Jacques","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","public_gists":1,"bio":"","id":327146,"total_private_repos":5,"blog":"http://vincent-jacques.net"} + +GET /repos/jacquev6/PyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4988'), ('content-length', '1097'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"044706cdc7381a70bf368b2afccbdb89"'), ('date', 'Thu, 10 May 2012 14:37:57 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"homepage":"http://vincent-jacques.net/PyGithub","clone_url":"https://github.com/jacquev6/PyGithub.git","url":"https://api.github.com/repos/jacquev6/PyGithub","has_downloads":true,"watchers":13,"permissions":{"admin":true,"pull":true,"push":true},"has_wiki":false,"has_issues":true,"fork":false,"mirror_url":null,"forks":2,"language":"Python","size":264,"description":"Python library implementing the full Github API v3","html_url":"https://github.com/jacquev6/PyGithub","private":false,"created_at":"2012-02-25T12:53:47Z","open_issues":15,"svn_url":"https://github.com/jacquev6/PyGithub","git_url":"git://github.com/jacquev6/PyGithub.git","owner":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146},"name":"PyGithub","pushed_at":"2012-05-09T16:22:47Z","id":3544490,"ssh_url":"git@github.com:jacquev6/PyGithub.git","updated_at":"2012-05-09T16:22:48Z"} + +GET /repos/jacquev6/PyGithub/git/refs/heads/topic/RewriteWithGeneratedCode {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '336'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"ef55032f07a176e09c65b2ac524c2ecf"'), ('date', 'Thu, 10 May 2012 14:38:00 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/topic/RewriteWithGeneratedCode","object":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a","type":"commit","sha":"1292bf0e22c796e91cc3d6e24b544aece8c21f2a"},"ref":"refs/heads/topic/RewriteWithGeneratedCode"} +