From 366ca58ca004b9129f9d435db8204ce0f5bc57c3 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Mon, 12 Mar 2012 22:08:22 +0100 Subject: [PATCH] PullRequest.is_merged and PullRequest.merge --- IntegrationTest.py | 7 +++++++ ReferenceOfApis.md | 4 ++-- github/GithubObjects.py | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/IntegrationTest.py b/IntegrationTest.py index bb62fa12..61573f2c 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -481,6 +481,13 @@ class IntegrationTest: k.delete() self.printList( "Keys", u.get_keys(), lambda k: k.title ) + def testMergePullRequest( self ): + r = self.g.get_user().get_repo( "TestPyGithub" ) + p = r.get_pull( 26 ) + assert not p.is_merged() + p.merge() + assert p.is_merged() + def testNamedUserDetails( self ): u = self.g.get_user( "jacquev6" ) print u.login, "(" + u.name + ") is from", u.location diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 242c91f7..8230f5fd 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -343,8 +343,8 @@ API `/repos/:user/:repo/pulls/:id/files` API `/repos/:user/:repo/pulls/:id/merge` ======================================== -* GET: (TODO) -* PUT: (TODO) +* GET: `PullRequest.is_merged` +* PUT: `PullRequest.merge` API `/repos/:user/:repo/pulls/comments/:id` =========================================== diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 51deea5f..8906c646 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -423,6 +423,10 @@ PullRequestComment = GithubObject( Deletable(), ) +def __pullRequestIsMerged( r ): + return r._github._statusRequest( "GET", r._baseUrl + "/merge", None, None ) == 204 +def __mergePullRequest( r, **data ): + r._github._statusRequest( "PUT", r._baseUrl + "/merge", None, data ) PullRequest = GithubObject( "PullRequest", BaseUrl( lambda obj: obj._repo._baseUrl + "/pulls/" + str( obj.number ) ), @@ -447,6 +451,8 @@ PullRequest = GithubObject( ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), ElementCreatable( [ "body", "commit_id", "path", "position" ], [], __modifyAttributesForObjectsReferingReferedRepo ), ), + MethodFromCallable( "is_merged", [], [], __pullRequestIsMerged, SimpleTypePolicy( "bool" ) ), + MethodFromCallable( "merge", [], [ "commit_message" ], __mergePullRequest, SimpleTypePolicy( None ) ), ) RepositoryKey = GithubObject( @@ -588,7 +594,7 @@ Repository._addAttributePolicy( SeveralAttributePolicies( [ ), ExternalListOfObjects( "pulls", "pull", PullRequest, ListGetable( [], [ "state" ], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "title", "body", "base", "head" ], [], __modifyAttributesForObjectsReferingRepo ), ), ] ) )