From 98c7953681a95bc3ead726d1ff79924a1a9543a0 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 3 Mar 2012 08:58:15 +0000 Subject: [PATCH] Git objects --- NewIntegrationTest.py | 23 +++++++++++++++++++++++ github/GithubObjects.py | 25 ++++++++++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/NewIntegrationTest.py b/NewIntegrationTest.py index 9d0d2cb9..eb70d889 100644 --- a/NewIntegrationTest.py +++ b/NewIntegrationTest.py @@ -291,6 +291,29 @@ class IntegrationTest: k.delete() self.printList( "Keys", u.get_keys(), lambda k: k.title ) + def testGitObjects( self ): + o = self.g.get_organization( self.cobayeOrganization ) + r = o.get_repo( "TestPyGithub" ) + + masterRef = r.get_git_ref( "refs/heads/master" ) + masterCommit = r.get_git_commit( masterRef.object[ "sha" ] ) + masterTree = r.get_git_tree( masterCommit.tree.sha ) + readmeBlob = None + for element in masterTree.tree: + if element[ "path" ] == "ReadMe.md": + readmeBlob = r.get_git_blob( element[ "sha" ] ) + break + + blob = r.create_git_blob( "This blob was created by PyGithub", encoding = "latin1" ) + tree = r.create_git_tree( [ { "path": "foo.bar", "mode": "100644", "type": "blob", "sha": blob.sha }, { "path": "ReadMe.md", "mode": "100644", "type": "blob", "sha": readmeBlob.sha } ] ) + commit = r.create_git_commit( "This commit was created by PyGithub", tree.sha, [ masterCommit.sha ] ) + r.create_git_ref( "refs/heads/previous_master", masterRef.object[ "sha" ] ) + masterRef.edit( commit.sha ) + + tag = r.create_git_tag( "tagCreatedByPyGithub", "This tag was created by PyGithub", commit.sha, "commit" ) + r.create_git_ref( "refs/tags/tagCreatedByPyGithub", tag.sha ) + reTag = r.get_git_tag( tag.sha ) + def printList( self, title, iterable, f = lambda x: x ): print title + ":", ", ".join( f( x ) for x in iterable[ :10 ] ), "..." if len( iterable ) > 10 else "" diff --git a/github/GithubObjects.py b/github/GithubObjects.py index d74e500e..2eac6927 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -144,19 +144,6 @@ GitRef = GithubObject( Editable( [ "sha" ], [ "force" ] ), ) -GitCommit = GithubObject( - "GitCommit", - BaseUrl( lambda obj: obj._repo._baseUrl + "/git/commits/" + obj.sha ), - InternalSimpleAttributes( - "sha", "url", "message", - "author", ### @todo Structure - "committer", ### @todo Structure - "tree", ### @todo Structure - "parents", ### @todo Structure - "_repo", ### Ugly hack - ), -) - GitTree = GithubObject( "GitTree", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/trees/" + obj.sha ), @@ -167,6 +154,18 @@ GitTree = GithubObject( ), ) +GitCommit = GithubObject( + "GitCommit", + BaseUrl( lambda obj: obj._repo._baseUrl + "/git/commits/" + obj.sha ), + InternalSimpleAttributes( + "sha", "url", "message", + "parents", ### @todo Structure + "author", "committer", + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "tree", GitTree ), +) + GitBlob = GithubObject( "GitBlob", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/blobs/" + obj.sha ),