diff --git a/IntegrationTest.py b/IntegrationTest.py index 4faed8c5..da3615de 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -166,7 +166,8 @@ class IntegrationTest: print " Watchers:", ", ".join( u.login for u in r.get_watchers() ) 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() ) - print " Master:", r.get_git_ref( "refs/heads/master" ).object[ "sha" ] + masterCommitSha = r.get_git_ref( "refs/heads/master" ).object[ "sha" ] + print " Master:", masterCommitSha, r.get_git_commit( masterCommitSha ).message print sys.stdout.flush() diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 78cc1991..3bbb786d 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -178,11 +178,11 @@ API `/repos/:user/:repo/git/blobs/:sha` API `/repos/:user/:repo/git/commits` ==================================== -* POST: `Repository.create_git_commit( ... )`: `GitCommit` (TODO SOON) +* POST: `Repository.create_git_commit( ... )`: `GitCommit` API `/repos/:user/:repo/git/commits/:sha` ========================================= -* GET: `Repository.get_git_commit( sha )`: `GitCommit` (TODO SOON) +* GET: `Repository.get_git_commit( sha )`: `GitCommit` API `/repos/:user/:repo/git/refs` ================================= diff --git a/github/GithubObjects.py b/github/GithubObjects.py index a6db20f2..4805654c 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -64,13 +64,26 @@ GitRef = GithubObject( BaseUrl( lambda obj: obj._repo._baseUrl + "/git/" + obj.ref ), BasicAttributes( "ref", "url", - "object", ### @todo Structure, + "object", ### @todo Structure "_repo", ### Ugly hack ), Editable( [ "sha" ], [ "force" ] ), ) -__modifyAttributesForGitRef = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) +GitCommit = GithubObject( + "GitCommit", + BaseUrl( lambda obj: obj._repo._baseUrl + "/git/commits/" + obj.sha ), + BasicAttributes( + "sha", "url", "message", + "author", ### @todo Structure + "committer", ### @todo Structure + "tree", ### @todo Structure + "parents", ### @todo Structure + "_repo", ### Ugly hack + ), +) + +__modifyAttributesForGitObjects = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) Repository = GithubObject( "Repository", BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ), @@ -90,10 +103,14 @@ Repository = GithubObject( ListAttribute( "watchers", NamedUser, ListGetable( [], [] ) ), Editable( [ "name" ], [ "description", "homepage", "public", "has_issues", "has_wiki", "has_downloads" ] ), ListAttribute( "git/refs", GitRef, - ListGetable( [], [], __modifyAttributesForGitRef ), + ListGetable( [], [], __modifyAttributesForGitObjects ), ElementGetable( "git_ref", lambda repo, ref: { "_repo": repo, "ref": ref } ), - ElementCreatable( "git_ref", [ "ref", "sha" ], [], __modifyAttributesForGitRef ) - ) + ElementCreatable( "git_ref", [ "ref", "sha" ], [], __modifyAttributesForGitObjects ) + ), + ListAttribute( "git/commits", GitCommit, + ElementGetable( "git_commit", lambda repo, sha: { "_repo": repo, "sha": sha } ), + ElementCreatable( "git_commit", [ "message", "tree", "parents" ], [ "author", "commiter" ], __modifyAttributesForGitObjects ) + ), ) Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) ) Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )