diff --git a/IntegrationTest.py b/IntegrationTest.py index 1cc34442..cfe31320 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -155,6 +155,9 @@ class IntegrationTest: tag = r.create_git_tag( "a_tag", "This tag was created by PyGithub", c2.sha, "commit" ) r.create_git_ref( "refs/tags/a_tag", tag.sha ) + c = r.get_commit( c2.sha ) + c.create_comment( "Commented with PyGithub", c.sha, 1, "foo.bar", 1 ) + # Issues and milestones l = r.create_label( "Label created by PyGithub", "00FF00" ) l.edit( "Label created and modified by PyGithub", "FFFF00" ) @@ -219,7 +222,10 @@ class IntegrationTest: print " Forks:", ", ".join( f.owner.login + "/" + f.name for f in r.get_forks() ) print " Languages:", r.get_languages() print " Downloads:", ", ".join( d.name for d in r.get_downloads() ) - print " References:", ", ".join( ref.ref + " (" + ref.object[ "sha" ][ :7 ] + ")" for ref in r.get_git_refs() ) + print " Tags:", ", ".join( t.name + " (" + t.commit.sha + ")" for t in r.get_tags() ) + print " Branches:", ", ".join( b.name + " (" + b.commit.sha + ")" for b in r.get_branches() ) + print " Commits:", ", ".join( c.commit.message + " (" + str( c.stats ) + " ".join( comment.body for comment in c.get_comments() ) + ")" for c in r.get_commits()[ : 10 ] ) + print " Git 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" ] masterCommit = r.get_git_commit( masterCommitSha ) masterTreeSha = masterCommit.tree[ "sha" ] diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 0909f86c..b6a0c33a 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -106,7 +106,7 @@ API `/repos/:user/:repo` API `/repos/:user/:repo/branches` ================================= -* GET: (TODO SOON) +* GET: `Repository.get_branches()`: list of `Branch` API `/repos/:user/:repo/collaborators` ====================================== @@ -120,26 +120,26 @@ API `/repos/:user/:repo/collaborators/:user` API `/repos/:user/:repo/comments` ================================= -* GET: (TODO SOON) +* GET: `Repository.get_comments()`: list of `CommitComment` API `/repos/:user/:repo/comments/:id` ===================================== -* GET: (TODO SOON) -* PATCH: (TODO SOON) -* DELETE: (TODO SOON) +* GET: `Repository.get_comment( id )`: `CommitComment` +* PATCH: `CommitComment.edit( ...)` +* DELETE: `CommitComment.delete()` API `/repos/:user/:repo/commits` ================================ -* GET: (TODO SOON) +* GET: `Repository.get_commits( ... )`: list of `Commit` API `/repos/:user/:repo/commits/:sha` ===================================== -* GET: (TODO SOON) +* GET: `Repository.get_commit( sha )`: `Commit` API `/repos/:user/:repo/commits/:sha/comments` ============================================== -* GET: (TODO SOON) -* POST: (TODO SOON) +* GET: `Commit.get_comments()`: list of `CommitComment` +* POST: `Commit.create_comment( ... )`: `CommitComment` API `/repos/:user/:repo/compare/:base...:head` ============================================== @@ -354,7 +354,7 @@ API `/repos/:user/:repo/pulls/comments/:id` API `/repos/:user/:repo/tags` ============================= -* GET: (TODO SOON) +* GET: `Repository.get_tags()`: list of `Tag` API `/repos/:user/:repo/teams` ============================== diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 8ced2155..149a7c6d 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -140,6 +140,15 @@ Git objects * `get_git_tag( sha )`: `GitTag` * `create_git_tag( ... )`: `GitTag`: see [API](http://developer.github.com/v3/git/tags/#create-a-tag-object) for parameters +Tags, branches, commits +----------------------- +* `get_tags()`: list of `Tag` +* `get_branches()`: list of `Branch` +* `get_commits( ... )`: list of `Commit`: see [API](http://developer.github.com/v3/repos/commits/#list-commits-on-a-repository) for parameters +* `get_commit( sha )`: `Commit` +* `get_comments()`: list of `CommitComment` +* `get_comment( id )`: `CommitComment` + Teams ----- * `get_teams()`: list of `Team` @@ -162,6 +171,26 @@ Downloads `Repository.create_download( ... )`: `Download`: see [API](http://developer.github.com/v3/repos/downloads/#create-a-new-download-part-1-create-the-resource) `Repository.get_download( id )`: `Download` +Class `Tag` +=========== +* Attributes: see [API](http://developer.github.com/v3/repos/#list-tags) + +Class `Branch` +============== +* Attributes: see [API](http://developer.github.com/v3/repos/#list-branches) + +Class `Commit` +============== +* Attributes: see [API](http://developer.github.com/v3/repos/commits/#get-a-single-commit) +* `get_comments()`: list of `CommitComment` +* `create_comment( ... )`: `CommitComment`: see [API](http://developer.github.com/v3/repos/commits/#create-a-commit-comment) for parameters + +Class `CommitComment` +===================== +* Attributes: see [API](http://developer.github.com/v3/repos/commits/#get-a-single-commit-comment) +* `edit( ... )`: see [API](http://developer.github.com/v3/repos/commits/#update-a-commit-comment) for parameters +* `delete()` + Class `Download` ================ * Attributes: see [API](http://developer.github.com/v3/repos/downloads/#get-a-single-download) diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 74d57a85..71c78697 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -199,6 +199,56 @@ Download = GithubObject( Deletable(), ) +CommitComment = GithubObject( + "CommitComment", + BaseUrl( lambda obj: obj._repo._baseUrl + "/comments/" + str( obj.id ) ), + InternalSimpleAttributes( + "url", "id", "body", "path", "position", "commit_id", + "created_at", "updated_at", "html_url", "line", + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "user", NamedUser ), + Editable( [ "body" ], [] ), + Deletable(), +) + +Commit = GithubObject( + "Commit", + BaseUrl( lambda obj: obj._repo._baseUrl + "/commits/" + str( obj.sha ) ), + InternalSimpleAttributes( + "sha", "url", + "parents", ### @todo Structure + "stats", ### @todo Structure + "files", ### @todo Structure + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "commit", GitCommit ), + InternalObjectAttribute( "author", NamedUser ), + InternalObjectAttribute( "committer", NamedUser ), + ExternalListOfObjects( "comments", CommitComment, + ListGetable( [], [] ), + ElementCreatable( "comment", [ "body", "commit_id", "line", "path", "position" ], [] ), + ), +) + +Tag = GithubObject( + "Tag", + InternalSimpleAttributes( + "name", "zipball_url", "tarball_url", + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "commit", Commit ) +) + +Branch = GithubObject( + "Branch", + InternalSimpleAttributes( + "name", + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "commit", Commit ) +) + __modifyAttributesForObjectsReferingRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) Repository = GithubObject( "Repository", @@ -259,7 +309,21 @@ Repository = GithubObject( ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), ElementGetable( "download", lambda repo, id : { "_repo": repo, "number": number } ), ElementCreatable( "download", [ "name", "size" ], [ "description", "content_type" ], __modifyAttributesForObjectsReferingRepo ), - ) + ), + ExternalListOfObjects( "comments", CommitComment, + ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( "comment", lambda repo, id : { "_repo": repo, "id": id } ), + ), + ExternalListOfObjects( "commits", Commit, + ListGetable( [], [ "sha", "path" ], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( "commit", lambda repo, sha : { "_repo": repo, "sha": sha } ), + ), + ExternalListOfObjects( "tags", Tag, + ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), + ), + ExternalListOfObjects( "branches", Branch, + ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), + ), ) Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) ) Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) ) diff --git a/github/Requester.py b/github/Requester.py index d37fd85b..049ad7db 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -18,12 +18,15 @@ class Requester: headers, output = self.__statusCheckedRequest( verb, url, parameters, input ) - page = 2 while "link" in headers and "next" in headers[ "link" ]: - parameters[ "page" ] = page + for link in headers[ "link" ].split( "," ): + if "next" in link: + linkUrl = link.split( ";" )[ 0 ][ : -1 ] + params = linkUrl.split( "?" )[ 1 ] + parameters.update( dict( p.split( "=" ) for p in params.split( "&" ) ) ) + break headers, newOutput = self.__statusCheckedRequest( verb, url, parameters, input ) output += newOutput - page += 1 return output