diff --git a/IntegrationTest.py b/IntegrationTest.py index 6cd9374d..e2800f04 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -195,6 +195,8 @@ class IntegrationTest: c3 = rf.create_git_commit( "This commit was ter created by PyGithub", t3.sha, [ c2.sha ] ) rf.get_git_ref( "refs/heads/master" ).edit( c3.sha ) + p = r.create_pull( "Pull request created by PyGithub", "", "jacquev6:master", "BeaverSoftware:master" ) + self.dumpRepository( r ) def dumpUser( self, u, doPrivateThings ): @@ -258,6 +260,7 @@ class IntegrationTest: print " Issues:", ", ".join( i.title + " (" + ", ".join( l.name for l in i.get_labels() ) + ") (" + ", ".join( c.body for c in i.get_comments() ) + ")" for i in r.get_issues() ) print " Milestones:", ", ".join( m.title + " (created by " + m.creator.login + ", " + ", ".join( l.name for l in m.get_labels() ) + ")" for m in r.get_milestones() ) print " Closed milestones:", ", ".join( m.title for m in r.get_milestones( state = "closed" ) ) + print " Merge requests:", ", ".join( p.title + "(" + ", ".join( f.filename for f in p.get_files() ) + ")" for p in r.get_pulls() ) print sys.stdout.flush() diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 3d3c8e8b..5fe8f599 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -320,26 +320,26 @@ API `/repos/:user/:repo/milestones/:number/labels` API `/repos/:user/:repo/pulls` ============================== -* GET: (TODO SOON) -* POST: (TODO SOON) +* GET: `Repository.get_pulls` +* POST: `Repository.create_pull` (TODO: alternative input) API `/repos/:user/:repo/pulls/:id` ================================== -* GET: (TODO SOON) -* PATCH: (TODO SOON) +* GET: `Repository.get_pull` +* PATCH: `PullRequest.edit` API `/repos/:user/:repo/pulls/:id/comments` =========================================== -* GET: (TODO SOON) -* POST: (TODO SOON) +* GET: `PullRequest.get_comments` +* POST: `PullRequest.create_comment` (TODO: alternative input) API `/repos/:user/:repo/pulls/:id/commits` ========================================== -* GET: (TODO SOON) +* GET: `PullRequest.get_commits` API `/repos/:user/:repo/pulls/:id/files` ======================================== -* GET: (TODO SOON) +* GET: `PullRequest.get_files` API `/repos/:user/:repo/pulls/:id/merge` ======================================== @@ -348,9 +348,9 @@ API `/repos/:user/:repo/pulls/:id/merge` API `/repos/:user/:repo/pulls/comments/:id` =========================================== -* GET: (TODO SOON) -* PATCH: (TODO SOON) -* DELETE: (TODO SOON) +* GET: `PullRequest.get_comment` +* PATCH: `PullRequestComment.edit` +* DELETE: `PullRequestComment.delete` API `/repos/:user/:repo/tags` ============================= diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 1159dda8..06929fe7 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -464,6 +464,93 @@ Teams * `get_teams()`: list of `Team` * `create_team( name, [repo_names, permission] )`: `Team` +Class `PullRequest` +=================== + +Attributes +---------- +* `id` +* `url` +* `html_url` +* `diff_url` +* `patch_url` +* `issue_url` +* `number` +* `state` +* `title` +* `body` +* `created_at` +* `updated_at` +* `closed_at` +* `merged_at` +* `merged` +* `mergeable` +* `comments` +* `commits` +* `additions` +* `deletions` +* `changed_files` +* `head` +* `base` + +Modification +------------ +* `edit( [title, body, state] )` + +Commits +------- +* `get_commits()`: list of `Commit` + +Files +----- +* `get_files()`: list of `PullRequestFile` + +Comments +-------- +* `get_comments()`: list of `PullRequestComment` +* `get_comment( id )`: `PullRequestComment` +* `create_comment( body, commit_id, path, position )`: `PullRequestComment` + +Class `PullRequestComment` +========================== + +Attributes +---------- +* `url` +* `id` +* `body` +* `path` +* `position` +* `commit_id` +* `created_at` +* `updated_at` +* `html_url` +* `line` +* `user`: `NamedUser` + +Modification +------------ +* `edit( body )` + +Deletion +-------- +* `delete()` + +Class `PullRequestFile` +======================= + +Attributes +---------- +* `sha` +* `filename` +* `status` +* `additions` +* `deletions` +* `changes` +* `blob_url` +* `raw_url` +* `patch` + Class `Repository` ================== @@ -597,6 +684,12 @@ Branches -------- * `get_branches()`: list of `Branch` +Pulls +----- +* `get_pulls( [state] )`: list of `PullRequest` +* `get_pull( id )`: `PullRequest` +* `create_pull( title, body, base, head )`: `PullRequest` + Teams ----- * `get_teams()`: list of `Team` diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 7aa7dc61..ff4c7ab0 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -290,6 +290,53 @@ Branch = GithubObject( ) __modifyAttributesForObjectsReferingRepo = { "_repo": lambda repo: repo } +PullRequestFile = GithubObject( + "PullRequestFile", + InternalSimpleAttributes( + "sha", "filename", "status", "additions", "deletions", "changes", + "blob_url", "raw_url", "patch", + ), +) + +PullRequestComment = GithubObject( + "PullRequestComment", + BaseUrl( lambda obj: obj._repo._baseUrl + "/pulls/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(), +) + +PullRequest = GithubObject( + "PullRequest", + BaseUrl( lambda obj: obj._repo._baseUrl + "/pulls/" + str( obj.number ) ), + InternalSimpleAttributes( + "id", "url", "html_url", "diff_url", "patch_url", "issue_url", "number", + "state", "title", "body", "created_at", "updated_at", "closed_at", + "merged_at", "_links", "merged", "mergeable", "comments", "commits", + "additions", "deletions", "changed_files", "head", "base", "merged_by", + "review_comments", + "_repo", ### Ugly hack + ), + InternalObjectAttribute( "user", NamedUser ), + Editable( [], [ "title", "body", "state" ] ), + ExternalListOfObjects( "commits", "commit", Commit, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + ), + ExternalListOfObjects( "files", "file", PullRequestFile, + ListGetable( [], [] ), + ), + ExternalListOfObjects( "comments", "comment", PullRequestComment, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementCreatable( [ "body", "commit_id", "path", "position" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ), +) + Repository = GithubObject( "Repository", BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ), @@ -386,6 +433,11 @@ Repository._addAttributePolicy( SeveralAttributePolicies( [ ExternalListOfObjects( "branches", "branch", Branch, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), ), + ExternalListOfObjects( "pulls", "pull", PullRequest, + ListGetable( [], [ "state" ], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ), + ElementCreatable( [ "title", "body", "base", "head" ], [], __modifyAttributesForObjectsReferingRepo ), + ), ] ) ) __repoElementCreatable = ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )