Implement markdown rendering (Issue #56)

This commit is contained in:
Vincent Jacques
2012-07-13 18:13:43 +02:00
parent d40bec470e
commit 478c0aaa2b
9 changed files with 77 additions and 1 deletions
+8
View File
@@ -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`
+3
View File
@@ -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`
=======================
+17
View File
@@ -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
+2 -1
View File
@@ -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()
+1
View File
@@ -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 *
+26
View File
@@ -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 <http://www.gnu.org/licenses/>.
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 ), '<h1><a name="mytitle" class="anchor" href="#mytitle"><span class="mini-icon mini-icon-link"></span></a>MyTitle</h1><p>Issue #1</p>' )
def testRenderGithubFlavoredMarkdown( self ):
self.assertEqual( self.g.render_markdown( self.text, self.repo ), '<h1>MyTitle</h1><p>Issue <a href="https://github.com/jacquev6/PyGithub/issues/1" class="issue-link" title="Gitub -&gt; Github everywhere">#1</a></p>' )
+10
View File
@@ -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"}
@@ -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')]
<h1>MyTitle</h1><p>Issue <a href="https://github.com/jacquev6/PyGithub/issues/1" class="issue-link" title="Gitub -&gt; Github everywhere">#1</a></p>
@@ -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')]
<h1><a name="mytitle" class="anchor" href="#mytitle"><span class="mini-icon mini-icon-link"></span></a>MyTitle</h1><p>Issue #1</p>