From ce5eb2c02226f18eba9481b56c72efae43182d6e Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 22 Feb 2012 21:32:35 +0000 Subject: [PATCH] Repository.get_git_tree (and .create_git_tree, not tested) --- IntegrationTest.py | 5 ++++- ReferenceOfApis.md | 8 ++++++-- github/GithubObjects.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/IntegrationTest.py b/IntegrationTest.py index da3615de..47eb288b 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -167,7 +167,10 @@ class IntegrationTest: print " Forks:", ", ".join( f.owner.login + "/" + f.name for f in r.get_forks() ) print " References:", ", ".join( ref.ref + " (" + ref.object[ "sha" ][ :7 ] + ")" for ref in r.get_git_refs() ) masterCommitSha = r.get_git_ref( "refs/heads/master" ).object[ "sha" ] - print " Master:", masterCommitSha, r.get_git_commit( masterCommitSha ).message + masterCommit = r.get_git_commit( masterCommitSha ) + masterTreeSha = masterCommit.tree[ "sha" ] + masterTree = r.get_git_tree( masterTreeSha ) + print " Master:", masterCommitSha, masterCommit.message, ", ".join( element[ "path" ] + " (" + element[ "type" ] + ")" for element in masterTree.tree ) print sys.stdout.flush() diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 3bbb786d..581e3cb0 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -204,11 +204,15 @@ API `/repos/:user/:repo/git/tags/:sha` API `/repos/:user/:repo/git/trees` ================================== -* POST: `Repository.create_git_tree( ... )`: `GitTree` (TODO SOON) +* POST: `Repository.create_git_tree( ... )`: `GitTree` + +API `/repos/:user/:repo/git/trees?base_tree=` +============================================= +* POST: `GitTree.create_update( ... )`: `GitTree` (TODO SOON) API `/repos/:user/:repo/git/trees/:sha` ======================================= -* GET: `Repository.get_git_tree( sha )`: `GitTree` (TODO SOON) +* GET: `Repository.get_git_tree( sha )`: `GitTree` API `/repos/:user/:repo/git/trees/:sha?recursive=1` =================================================== diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 4805654c..88cfdbe3 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -83,6 +83,16 @@ GitCommit = GithubObject( ), ) +GitTree = GithubObject( + "GitTree", + BaseUrl( lambda obj: obj._repo._baseUrl + "/git/trees/" + obj.sha ), + BasicAttributes( + "sha", "url", + "tree", ### @todo Structure + "_repo", ### Ugly hack + ), +) + __modifyAttributesForGitObjects = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) Repository = GithubObject( "Repository", @@ -111,6 +121,10 @@ Repository = GithubObject( ElementGetable( "git_commit", lambda repo, sha: { "_repo": repo, "sha": sha } ), ElementCreatable( "git_commit", [ "message", "tree", "parents" ], [ "author", "commiter" ], __modifyAttributesForGitObjects ) ), + ListAttribute( "git/trees", GitTree, + ElementGetable( "git_tree", lambda repo, sha: { "_repo": repo, "sha": sha } ), + ElementCreatable( "git_tree", [ "tree" ], [], __modifyAttributesForGitObjects ) + ), ) Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) ) Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )