diff --git a/doc/ReferenceOfApis.md b/doc/ReferenceOfApis.md index ce01775c..29f1b18a 100644 --- a/doc/ReferenceOfApis.md +++ b/doc/ReferenceOfApis.md @@ -73,6 +73,14 @@ API `/legacy/user/email/:email` ============================================================== * GET: `Github.search_user_by_email` +API `/markdown` +=============== +* POST: `Github.render_markdown` + +API `/markdown/raw` +=================== +* POST: see API `/markdown` + API `/networks/:user/:repo/events` ================================== * GET: `Repository.get_network_events` diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 485c5348..62563acc 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -37,6 +37,9 @@ Methods * `keyword`: string * `legacy_search_user_by_email( email )`: `NamedUser` * `email`: string +* `render_markdown( text, [context] )`: string + * `text`: string + * `context`: `Repository` Class `GithubException` ======================= diff --git a/github/Github.py b/github/Github.py index 3b388512..0c74e156 100644 --- a/github/Github.py +++ b/github/Github.py @@ -103,3 +103,20 @@ class Github( object ): None ) return NamedUser.NamedUser( self.__requester, Legacy.convertUser( data[ "user" ] ), completed = False ) + + def render_markdown( self, text, context = GithubObject.NotSet ): + assert isinstance( text, ( str, unicode ) ), text + assert context is GithubObject.NotSet or isinstance( context, Repository.Repository ), context + post_parameters = { + "text": text + } + if context is not GithubObject.NotSet: + post_parameters[ "mode" ] = "gfm" + post_parameters[ "context" ] = context._identity + status, headers, data = self.__requester.requestRaw( + "POST", + "https://api.github.com/markdown", + None, + post_parameters + ) + return data diff --git a/github/Requester.py b/github/Requester.py index 6bce409f..d6aa41ff 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -36,6 +36,7 @@ class Requester: def requestAndCheck( self, verb, url, parameters, input ): status, headers, output = self.requestRaw( verb, url, parameters, input ) + output = self.__structuredFromJson( output ) if status >= 400: raise GithubException.GithubException( status, output ) return headers, output @@ -60,7 +61,7 @@ class Requester: status = response.status headers = dict( response.getheaders() ) - output = self.__structuredFromJson( response.read() ) + output = response.read() cnx.close() diff --git a/test/IntegrationTest.py b/test/IntegrationTest.py index a2d966b6..49672c8f 100755 --- a/test/IntegrationTest.py +++ b/test/IntegrationTest.py @@ -48,6 +48,7 @@ from RepositoryKey import * from Tag import * from Team import * from UserKey import * +from Markdown import * from PaginatedList import * from Issue33 import * diff --git a/test/Markdown.py b/test/Markdown.py new file mode 100644 index 00000000..971fa167 --- /dev/null +++ b/test/Markdown.py @@ -0,0 +1,26 @@ +# Copyright 2012 Vincent Jacques +# vincent@vincent-jacques.net + +# This file is part of PyGithub. http://vincent-jacques.net/PyGithub + +# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see . + +import Framework + +class Markdown( Framework.TestCase ): + def setUp( self ): + Framework.TestCase.setUp( self ) + self.text = "MyTitle\n=======\n\nIssue #1" + self.repo = self.g.get_user().get_repo( "PyGithub" ) + + def testRenderMarkdown( self ): + self.assertEqual( self.g.render_markdown( self.text ), '

MyTitle

Issue #1

' ) + + def testRenderGithubFlavoredMarkdown( self ): + self.assertEqual( self.g.render_markdown( self.text, self.repo ), '

MyTitle

Issue #1

' ) diff --git a/test/ReplayData/Markdown.setUp.txt b/test/ReplayData/Markdown.setUp.txt new file mode 100644 index 00000000..24cca469 --- /dev/null +++ b/test/ReplayData/Markdown.setUp.txt @@ -0,0 +1,10 @@ +GET /user {'Authorization': 'Basic login_and_password_removed'} null +200 +[('status', '200 OK'), ('content-length', '801'), ('vary', 'Accept, Authorization, Cookie'), ('x-ratelimit-remaining', '4987'), ('server', 'nginx/1.0.13'), ('last-modified', 'Mon, 09 Jul 2012 06:49:53 GMT'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1bd2b9dfc8ba65f7665102d6245a1593"'), ('cache-control', 'private, max-age=60'), ('date', 'Fri, 13 Jul 2012 11:59:58 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"disk_usage":13720,"public_repos":11,"type":"User","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","total_private_repos":3,"collaborators":0,"hireable":false,"login":"jacquev6","owned_private_repos":3,"public_gists":3,"email":"vincent@vincent-jacques.net","bio":"","private_gists":5,"created_at":"2010-07-09T06:10:06Z","blog":"http://vincent-jacques.net","following":26,"location":"Paris, France","followers":13,"name":"Vincent Jacques","company":"Criteo","plan":{"collaborators":1,"private_repos":5,"name":"micro","space":614400},"html_url":"https://github.com/jacquev6","id":327146,"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225"} + +GET /repos/jacquev6/PyGithub {'Authorization': 'Basic login_and_password_removed'} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4986'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '1154'), ('server', 'nginx/1.0.13'), ('last-modified', 'Thu, 12 Jul 2012 18:10:45 GMT'), ('connection', 'keep-alive'), ('etag', '"7db49a096161f262ffd7e0545292f4c3"'), ('cache-control', 'private, max-age=60'), ('date', 'Fri, 13 Jul 2012 11:59:59 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"svn_url":"https://github.com/jacquev6/PyGithub","created_at":"2012-02-25T12:53:47Z","owner":{"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"login":"jacquev6","url":"https://api.github.com/users/jacquev6"},"full_name":"jacquev6/PyGithub","has_wiki":false,"watchers":43,"git_url":"git://github.com/jacquev6/PyGithub.git","html_url":"https://github.com/jacquev6/PyGithub","pushed_at":"2012-07-11T11:29:24Z","updated_at":"2012-07-12T18:10:45Z","permissions":{"pull":true,"push":true,"admin":true},"open_issues":11,"forks":7,"clone_url":"https://github.com/jacquev6/PyGithub.git","ssh_url":"git@github.com:jacquev6/PyGithub.git","homepage":"http://vincent-jacques.net/PyGithub","size":160,"fork":false,"master_branch":"master","mirror_url":null,"has_issues":true,"name":"PyGithub","has_downloads":true,"description":"Python library implementing the full Github API v3","private":false,"id":3544490,"language":"Python","url":"https://api.github.com/repos/jacquev6/PyGithub"} + diff --git a/test/ReplayData/Markdown.testRenderGithubFlavoredMarkdown.txt b/test/ReplayData/Markdown.testRenderGithubFlavoredMarkdown.txt new file mode 100644 index 00000000..7055d88a --- /dev/null +++ b/test/ReplayData/Markdown.testRenderGithubFlavoredMarkdown.txt @@ -0,0 +1,5 @@ +POST /markdown {'Authorization': 'Basic login_and_password_removed'} {"text": "MyTitle\n=======\n\nIssue #1", "mode": "gfm", "context": "jacquev6/PyGithub"} +200 +[('status', '200 OK'), ('content-length', '150'), ('x-ratelimit-remaining', '4988'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"63251bf7dbb58f62c59ae39bb72c7a38"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Fri, 13 Jul 2012 11:59:58 GMT'), ('content-type', 'text/html;charset=utf-8')] +

MyTitle

Issue #1

+ diff --git a/test/ReplayData/Markdown.testRenderMarkdown.txt b/test/ReplayData/Markdown.testRenderMarkdown.txt new file mode 100644 index 00000000..6c72da7c --- /dev/null +++ b/test/ReplayData/Markdown.testRenderMarkdown.txt @@ -0,0 +1,5 @@ +POST /markdown {'Authorization': 'Basic login_and_password_removed'} {"text": "MyTitle\n=======\n\nIssue #1"} +200 +[('status', '200 OK'), ('content-length', '133'), ('x-ratelimit-remaining', '4985'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4cb17c0ebe3cc45c1a7f27d4d0850c54"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Fri, 13 Jul 2012 11:59:59 GMT'), ('content-type', 'text/html;charset=utf-8')] +

MyTitle

Issue #1

+