Convert legacy objects to v3 ones

Still needed:
- test completion of objects returned by legacy API
- implement legacy pagination
This commit is contained in:
Vincent Jacques
2012-06-29 07:44:10 +02:00
parent ed31abe6de
commit 37c06ea4fc
4 changed files with 52 additions and 5 deletions
+6 -3
View File
@@ -18,6 +18,7 @@ import Organization
import Gist
import PaginatedList
import Repository
import Legacy
class Github( object ):
def __init__( self, login_or_token = None, password = None ):
@@ -74,7 +75,8 @@ class Github( object ):
None,
None
)
return PaginatedList.PaginatedList(
return Legacy.PaginatedList(
Legacy.convertRepo,
Repository.Repository,
self.__requester,
headers,
@@ -89,7 +91,8 @@ class Github( object ):
None,
None
)
return PaginatedList.PaginatedList(
return Legacy.PaginatedList(
Legacy.convertUser,
NamedUser.NamedUser,
self.__requester,
headers,
@@ -104,4 +107,4 @@ class Github( object ):
None,
None
)
return NamedUser.NamedUser( self.__requester, data[ "user" ], completed = False )
return NamedUser.NamedUser( self.__requester, Legacy.convertUser( data[ "user" ] ), completed = False )
+41
View File
@@ -0,0 +1,41 @@
# 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/>.
def PaginatedList( convert, contentClass, requester, headers, data ):
return [
contentClass( requester, convert( element ), completed = False )
for element in data
]
def convertUser( attributes ):
attributes[ "created_at" ] = attributes[ "created_at" ][ : 19 ] + "Z"
if not isinstance( attributes[ "id" ], int ):
attributes[ "id" ] = int( attributes[ "id" ][ 5 : ] )
return attributes
def convertRepo( attributes ):
attributes[ "created_at" ] = attributes[ "created_at" ][ : 19 ] + "Z"
if "pushed_at" in attributes:
attributes[ "pushed_at" ] = attributes[ "pushed_at" ][ : 19 ] + "Z"
attributes[ "owner" ] = { "login": attributes[ "owner" ] }
if "organization" in attributes:
attributes[ "organization" ] = { "login": attributes[ "organization" ] }
attributes[ "url" ] = "https://api.github.com/repos/" + "/".join( attributes[ "url" ].split( "/" )[ -2 : ] )
return attributes
def convertIssue( attributes ):
attributes[ "created_at" ] = attributes[ "created_at" ][ : 19 ] + "Z"
attributes[ "updated_at" ] = attributes[ "updated_at" ][ : 19 ] + "Z"
attributes[ "labels" ] = [ { "name": label } for label in attributes[ "labels" ] ]
attributes[ "user" ] = { "login": attributes[ "user" ] }
return attributes
+3 -1
View File
@@ -46,6 +46,7 @@ import GitTag
import Download
import Permissions
import Event
import Legacy
class Repository( GithubObject.GithubObject ):
@property
@@ -1011,7 +1012,8 @@ class Repository( GithubObject.GithubObject ):
None,
None
)
return PaginatedList.PaginatedList(
return Legacy.PaginatedList(
Legacy.convertIssue,
Issue.Issue,
self._requester,
headers,
+2 -1
View File
@@ -18,7 +18,8 @@ class Github( Framework.TestCase ):
self.assertListKeyBegin( self.g.get_gists(), lambda g: g.id, [ "2729695", "2729656", "2729597", "2729584", "2729569", "2729554", "2729543", "2729537", "2729536", "2729533", "2729525", "2729522", "2729519", "2729515", "2729506", "2729487", "2729484", "2729482", "2729441", "2729432", "2729420", "2729398", "2729372", "2729371", "2729351", "2729346", "2729316", "2729304", "2729296", "2729276", "2729272", "2729265", "2729195", "2729160", "2729143", "2729127", "2729119", "2729113", "2729103", "2729069", "2729059", "2729051", "2729029", "2729027", "2729026", "2729022", "2729002", "2728985", "2728979", "2728964", "2728937", "2728933", "2728884", "2728869", "2728866", "2728855", "2728854", "2728853", "2728846", "2728825", "2728814", "2728813", "2728812", "2728805", "2728802", "2728800", "2728798", "2728797", "2728796", "2728793", "2728758", "2728754", "2728751", "2728748", "2728721", "2728716", "2728715", "2728705", "2728701", "2728699", "2728697", "2728688", "2728683", "2728677", "2728649", "2728640", "2728625", "2728620", "2728615", "2728614", "2728565", "2728564", "2728554", "2728523", "2728519", "2728511", "2728497", "2728496", "2728495", "2728487" ] )
def testSearchRepos( self ):
self.assertListKeyBegin( self.g.search_repos( "github api v3" ), lambda r: r.full_name, [ "pengwynn/octokit", "jwilger/github-v3-api", "acoulton/github_v3_api" ] )
# self.assertListKeyBegin( self.g.search_repos( "github api v3" ), lambda r: r.full_name, [ "pengwynn/octokit", "jwilger/github-v3-api", "acoulton/github_v3_api" ] )
self.assertListKeyBegin( self.g.search_repos( "github api v3" ), lambda r: r.name, [ "octokit", "github-v3-api", "github_v3_api" ] )
def testSearchUsers( self ):
self.assertListKeyBegin( self.g.search_users( "vincent" ), lambda u: u.login, [ "nvie", "obra", "lusis" ] )