mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Move classes around
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
from GithubObject import *
|
||||
|
||||
from Authorization import Authorization
|
||||
from UserKey import UserKey
|
||||
from Event import Event
|
||||
from NamedUser import NamedUser
|
||||
from Organization import Organization
|
||||
|
||||
def __getOrganizationEvents( user, org ):
|
||||
return [
|
||||
Event( user._github, attributes, lazy = True )
|
||||
for attributes
|
||||
in user._github._dataRequest( "GET", "/users/" + user.login + "/events/orgs/" + org.login, None, None )
|
||||
]
|
||||
|
||||
AuthenticatedUser = GithubObject(
|
||||
"AuthenticatedUser",
|
||||
BaseUrl( lambda obj: "/user" ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
InternalSimpleAttributes(
|
||||
"login", "id", "avatar_url", "gravatar_id", "url", "name", "company",
|
||||
"blog", "location", "email", "hireable", "bio", "public_repos",
|
||||
"public_gists", "followers", "following", "html_url", "created_at",
|
||||
"type", "total_private_repos", "owned_private_repos", "private_gists",
|
||||
"disk_usage", "collaborators", "plan",
|
||||
),
|
||||
Editable( [], [ "name", "email", "blog", "company", "location", "hireable", "bio" ] ),
|
||||
ExternalListOfSimpleTypes( "emails", "email", "string",
|
||||
ListGetable( [], [] ),
|
||||
SeveralElementsAddable(),
|
||||
SeveralElementsRemovable()
|
||||
),
|
||||
ExternalListOfObjects( "authorizations", "authorization", Authorization,
|
||||
ListGetable( [], [] ),
|
||||
ElementGetable( [ "id" ], [] ),
|
||||
ElementCreatable( [], [ "scopes", "note", "note_url" ] ),
|
||||
url = "/authorizations",
|
||||
),
|
||||
ExternalListOfObjects( "keys", "key", UserKey,
|
||||
ListGetable( [], [] ),
|
||||
ElementGetable( [ "id" ], [] ),
|
||||
ElementCreatable( [ "title", "key" ], [] ),
|
||||
),
|
||||
ExternalListOfObjects( "events", "event", Event,
|
||||
ListGetable( [], [] ),
|
||||
url = "/events"
|
||||
),
|
||||
ExternalListOfObjects( "followers", "follower", NamedUser,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
ExternalListOfObjects( "following", "following", NamedUser,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
ExternalListOfObjects( "orgs", "org", Organization,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
MethodFromCallable( "get_organization_events", [ "org" ], [], __getOrganizationEvents, SimpleTypePolicy( "list of `Event`" ) ),
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
from GithubObject import *
|
||||
|
||||
Authorization = GithubObject(
|
||||
"Authorization",
|
||||
BaseUrl( lambda obj: "/authorizations/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"id", "url", "scopes", "token", "app", "note", "note_url", "updated_at",
|
||||
"created_at",
|
||||
),
|
||||
Editable( [], [ "scopes", "add_scopes", "remove_scopes", "note", "note_url" ] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
from GithubObject import *
|
||||
|
||||
from Commit import Commit
|
||||
|
||||
Branch = GithubObject(
|
||||
"Branch",
|
||||
InternalSimpleAttributes(
|
||||
"name",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "commit", Commit )
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
from GithubObject import *
|
||||
|
||||
from GitCommit import GitCommit
|
||||
from NamedUser import NamedUser
|
||||
from CommitComment import CommitComment
|
||||
|
||||
__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo }
|
||||
|
||||
Commit = GithubObject(
|
||||
"Commit",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/commits/" + str( obj.sha ) ),
|
||||
InternalSimpleAttributes(
|
||||
"sha", "url",
|
||||
"parents",
|
||||
"stats",
|
||||
"files",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "commit", GitCommit ),
|
||||
InternalObjectAttribute( "author", NamedUser ),
|
||||
InternalObjectAttribute( "committer", NamedUser ),
|
||||
ExternalListOfObjects( "comments", "comment", CommitComment,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementCreatable( [ "body" ], [ "commit_id", "line", "path", "position" ], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
|
||||
CommitComment = GithubObject(
|
||||
"CommitComment",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/comments/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "id", "body", "path", "position", "commit_id",
|
||||
"created_at", "updated_at", "html_url", "line",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [ "body" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
from GithubObject import *
|
||||
|
||||
Download = GithubObject(
|
||||
"Download",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/downloads/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "html_url", "id", "name", "description", "size",
|
||||
"download_count", "content_type", "policy", "signature", "bucket",
|
||||
"accesskeyid", "path", "acl", "expirationdate", "prefix", "mime_type",
|
||||
"redirect", "s3_url", "created_at",
|
||||
"_repo",
|
||||
),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
from GithubObject import *
|
||||
|
||||
Event = GithubObject(
|
||||
"Event",
|
||||
InternalSimpleAttributes(
|
||||
"type", "public", "payload", "created_at", "id", "commit_id", "url",
|
||||
"event", "issue",
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,39 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from GistComment import GistComment
|
||||
|
||||
def __isStarred( gist ):
|
||||
return gist._github._statusRequest( "GET", gist._baseUrl() + "/star", None, None ) == 204
|
||||
def __setStarred( gist ):
|
||||
gist._github._statusRequest( "PUT", gist._baseUrl() + "/star", None, None )
|
||||
def __resetStarred( gist ):
|
||||
gist._github._statusRequest( "DELETE", gist._baseUrl() + "/star", None, None )
|
||||
Gist = GithubObject(
|
||||
"Gist",
|
||||
BaseUrl( lambda obj: "/gists/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "id", "description", "public", "files", "comments", "html_url",
|
||||
"git_pull_url", "git_push_url", "created_at", "forks", "history",
|
||||
"updated_at",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [], [ "description", "files" ] ),
|
||||
Deletable(),
|
||||
ExternalListOfObjects( "comments", "comment", GistComment,
|
||||
ListGetable( [], [] ),
|
||||
ElementGetable( [ "id" ], [] ),
|
||||
ElementCreatable( [ "body" ], [] ),
|
||||
),
|
||||
SeveralAttributePolicies( [
|
||||
MethodFromCallable( "is_starred", [], [], __isStarred, SimpleTypePolicy( "bool" ) ),
|
||||
MethodFromCallable( "set_starred", [], [], __setStarred, SimpleTypePolicy( None ) ),
|
||||
MethodFromCallable( "reset_starred", [], [], __resetStarred, SimpleTypePolicy( None ) ),
|
||||
], "Starring" ),
|
||||
)
|
||||
def __createFork( gist ):
|
||||
return Gist( gist._github, gist._github._dataRequest( "POST", gist._baseUrl() + "/fork", None, None ), lazy = True )
|
||||
Gist._addAttributePolicy( SeveralAttributePolicies( [
|
||||
MethodFromCallable( "create_fork", [], [], __createFork, ObjectTypePolicy( Gist ) ),
|
||||
], "Forking" ),
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
|
||||
GistComment = GithubObject(
|
||||
"GistComment",
|
||||
BaseUrl( lambda obj: "/gists/comments/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"id", "url", "body", "created_at",
|
||||
"updated_at",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [ "body" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
from GithubObject import *
|
||||
|
||||
GitBlob = GithubObject(
|
||||
"GitBlob",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/git/blobs/" + obj.sha ),
|
||||
InternalSimpleAttributes(
|
||||
"sha", "size", "url",
|
||||
"content", "encoding",
|
||||
"_repo",
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
from GithubObject import *
|
||||
|
||||
from GitTree import GitTree
|
||||
|
||||
GitCommit = GithubObject(
|
||||
"GitCommit",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/git/commits/" + obj.sha ),
|
||||
InternalSimpleAttributes(
|
||||
"sha", "url", "message",
|
||||
"parents",
|
||||
"author", "committer",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "tree", GitTree ),
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
from GithubObject import *
|
||||
|
||||
GitRef = GithubObject(
|
||||
"GitRef",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/git/" + obj.ref ),
|
||||
InternalSimpleAttributes(
|
||||
"ref", "url",
|
||||
"object",
|
||||
"_repo",
|
||||
),
|
||||
Editable( [ "sha" ], [ "force" ] ),
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
from GithubObject import *
|
||||
|
||||
GitTag = GithubObject(
|
||||
"GitTag",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/git/tags/" + obj.sha ),
|
||||
InternalSimpleAttributes(
|
||||
"tag", "sha", "url",
|
||||
"message",
|
||||
"tagger",
|
||||
"object",
|
||||
"_repo",
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
from GithubObject import *
|
||||
|
||||
GitTree = GithubObject(
|
||||
"GitTree",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/git/trees/" + obj.sha ),
|
||||
InternalSimpleAttributes(
|
||||
"sha", "url",
|
||||
"tree",
|
||||
"_repo",
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,572 @@
|
||||
import unittest
|
||||
import MockMockMock
|
||||
|
||||
from GithubObject import *
|
||||
|
||||
class GithubObjectTestCase( unittest.TestCase ):
|
||||
def testDuplicatedAttributeInOnePolicy( self ):
|
||||
with self.assertRaises( BadGithubObjectException ):
|
||||
GithubObject( "", InternalSimpleAttributes( "a", "a" ) )
|
||||
|
||||
def testDuplicatedAttributeInTwoPolicies( self ):
|
||||
with self.assertRaises( BadGithubObjectException ):
|
||||
GithubObject( "", InternalSimpleAttributes( "a" ), InternalSimpleAttributes( "a" ) )
|
||||
|
||||
class TestCaseWithGithubTestObject( unittest.TestCase ):
|
||||
def setUp( self ):
|
||||
unittest.TestCase.setUp( self )
|
||||
self.g = MockMockMock.Mock( "github" )
|
||||
self.o = self.GithubTestObject( self.g.object, { "a1": 1, "a2": 2 }, lazy = True )
|
||||
self.GithubTestObject._autoDocument() # Only for coverage
|
||||
|
||||
def tearDown( self ):
|
||||
self.g.tearDown()
|
||||
unittest.TestCase.tearDown( self )
|
||||
|
||||
def expectDataGet( self, url, arguments = None ):
|
||||
return self.g.expect._dataRequest( "GET", url, arguments, None )
|
||||
|
||||
def expectDataPost( self, url, data ):
|
||||
return self.g.expect._dataRequest( "POST", url, None, data )
|
||||
|
||||
def expectDataPatch( self, url, data ):
|
||||
return self.g.expect._dataRequest( "PATCH", url, None, data )
|
||||
|
||||
def expectStatusGet( self, url ):
|
||||
return self.g.expect._statusRequest( "GET", url, None, None )
|
||||
|
||||
def expectStatusPost( self, url, data ):
|
||||
return self.g.expect._statusRequest( "POST", url, None, data )
|
||||
|
||||
def expectStatusPut( self, url, data = None ):
|
||||
return self.g.expect._statusRequest( "PUT", url, None, data )
|
||||
|
||||
def expectStatusDelete( self, url, data = None ):
|
||||
return self.g.expect._statusRequest( "DELETE", url, None, data )
|
||||
|
||||
class GithubObjectWithDocumentationCoveringSpecialCases( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2", "_a3" ),
|
||||
MethodFromCallable( "myMethod", [ "mock", "arg" ], [], lambda obj: 42, ObjectTypePolicy( GithubObject ) ),
|
||||
AttributeFromCallable( "myAttr", lambda obj: 42 )
|
||||
)
|
||||
|
||||
def testNothing( self ):
|
||||
pass
|
||||
|
||||
class GithubObjectWithBaseUrlDependingOnAttribute( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test/" + str( obj.a1 ) ),
|
||||
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
|
||||
Editable( [ "a1" ], [] )
|
||||
)
|
||||
|
||||
def test( self ):
|
||||
self.expectDataPatch( "/test/1", { "a1": 11 } ).andReturn( { "a1": 110 } )
|
||||
self.expectDataPatch( "/test/110", { "a1": 111 } ).andReturn( { "a1": 1110 } )
|
||||
self.o.edit( 11 )
|
||||
self.o.edit( 111 )
|
||||
|
||||
class GithubObjectWithOnlyInternalSimpleAttributes( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2", "a3", "a4" )
|
||||
)
|
||||
|
||||
def testInterface( self ):
|
||||
self.assertEqual( [ e for e in dir( self.o ) if not e.startswith( "_" ) ], [ "a1", "a2", "a3", "a4" ] )
|
||||
|
||||
def testCompletion( self ):
|
||||
# A GithubObject:
|
||||
# - knows the attributes given to its constructor
|
||||
self.assertEqual( self.o.a1, 1 )
|
||||
self.assertEqual( self.o.a2, 2 )
|
||||
# - is completed the first time any unknown attribute is requested
|
||||
self.expectDataGet( "/test" ).andReturn( { "a2": 22, "a3": 3 } )
|
||||
self.assertEqual( self.o.a3, 3 )
|
||||
# - remembers the attributes that were not updated
|
||||
self.assertEqual( self.o.a1, 1 )
|
||||
# - acknowledges updates of attributes
|
||||
self.assertEqual( self.o.a2, 22 )
|
||||
# - remembers that some attributes are absent even after an update
|
||||
self.assertEqual( self.o.a4, None )
|
||||
|
||||
def testUnknownAttribute( self ):
|
||||
self.assertRaises( AttributeError, lambda: self.o.foobar )
|
||||
|
||||
def testNonLazyConstruction( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( { "a2": 2, "a3": 3 } )
|
||||
o = self.GithubTestObject( self.g.object, {}, lazy = False )
|
||||
self.g.tearDown()
|
||||
self.assertEqual( o.a1, None )
|
||||
self.assertEqual( o.a2, 2 )
|
||||
self.assertEqual( o.a3, 3 )
|
||||
self.assertEqual( o.a4, None )
|
||||
|
||||
class GithubObjectWithOtherBaseUrl( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/other/" + str( obj.a1 ) ),
|
||||
InternalSimpleAttributes( "a1", "a2", "a3", "a4" )
|
||||
)
|
||||
|
||||
def testCompletion( self ):
|
||||
self.expectDataGet( "/other/1" ).andReturn( { "a2": 22, "a3": 3 } )
|
||||
self.assertEqual( self.o.a3, 3 )
|
||||
|
||||
class EditableGithubObject( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
|
||||
Editable( [ "a1" ], [ "a2", "a4" ] ),
|
||||
)
|
||||
|
||||
def testEditWithoutArgument( self ):
|
||||
with self.assertRaises( TypeError ):
|
||||
self.o.edit()
|
||||
|
||||
def testEditWithoutMandatoryArgument( self ):
|
||||
with self.assertRaises( TypeError ):
|
||||
self.o.edit( a2 = 2, a4 = 3 )
|
||||
|
||||
def testEditWithSillyArgument( self ):
|
||||
with self.assertRaises( TypeError ):
|
||||
self.o.edit( foobar = 42 )
|
||||
|
||||
def testEditWithOneKeywordArgument( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( {} )
|
||||
self.o.edit( a1 = 11 )
|
||||
|
||||
def testEditWithTwoKeywordArguments( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
|
||||
self.o.edit( a1 = 11, a2 = 22 )
|
||||
|
||||
def testEditWithTwoKeywordArgumentsSkipingFirstOptionalArgument( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a4": 44 } ).andReturn( {} )
|
||||
self.o.edit( a1 = 11, a4 = 44 )
|
||||
|
||||
def testEditWithThreeKeywordArguments( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
|
||||
self.o.edit( a1 = 11, a4 = 44, a2 = 22 )
|
||||
|
||||
def testEditWithOnePositionalArgument( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( {} )
|
||||
self.o.edit( 11 )
|
||||
|
||||
def testEditWithRepeatedPositionalArgument( self ):
|
||||
with self.assertRaises( TypeError ):
|
||||
self.o.edit( 11, a1 = 11 )
|
||||
|
||||
def testEditWithTwoPositionalArguments( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
|
||||
self.o.edit( 11, 22 )
|
||||
|
||||
def testEditWithThreePositionalArguments( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
|
||||
self.o.edit( 11, 22, 44 )
|
||||
|
||||
def testEditWithMixedArguments_1( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
|
||||
self.o.edit( 11, a2 = 22 )
|
||||
|
||||
def testEditWithMixedArguments_2( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
|
||||
self.o.edit( 11, a2 = 22, a4 = 44 )
|
||||
|
||||
def testEditWithMixedArguments_3( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
|
||||
self.o.edit( 11, 22, a4 = 44 )
|
||||
|
||||
def testAcknoledgeUpdatesOfAttributes( self ):
|
||||
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( { "a2": 22, "a3": 3 } )
|
||||
self.o.edit( a1 = 11 )
|
||||
self.assertEqual( self.o.a1, 1 )
|
||||
self.assertEqual( self.o.a2, 22 )
|
||||
self.assertEqual( self.o.a3, 3 )
|
||||
self.expectDataGet( "/test" ).andReturn( {} )
|
||||
self.assertEqual( self.o.a4, None )
|
||||
|
||||
class DeletableGithubObject( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
|
||||
Deletable(),
|
||||
)
|
||||
|
||||
def testDelete( self ):
|
||||
self.expectStatusDelete( "/test" ).andReturn( 204 )
|
||||
self.o.delete()
|
||||
|
||||
class GithubObjectWithInternalObjectAttribute( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name", "desc" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
InternalObjectAttribute( "a3", ContainedObject )
|
||||
)
|
||||
|
||||
def testCompletion( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( { "a3": { "id": "id1", "name": "name1" } } )
|
||||
self.assertEqual( self.o.a3.id, "id1" )
|
||||
self.assertEqual( self.o.a3.name, "name1" )
|
||||
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "desc": "desc1" } )
|
||||
self.assertEqual( self.o.a3.desc, "desc1" )
|
||||
|
||||
def testCompletionWithNone( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( { "a3": None } )
|
||||
self.assertIsNone( self.o.a3 )
|
||||
|
||||
class GithubObjectWithListGetableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( [], [ "type" ] ) )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/test/a3s", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
|
||||
a3s = self.o.get_a3s()
|
||||
self.assertEqual( len( a3s ), 3 )
|
||||
self.assertEqual( a3s[ 0 ].id, "id1" )
|
||||
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } )
|
||||
self.assertEqual( a3s[ 0 ].name, "name1" )
|
||||
|
||||
def testGetListWithType( self ):
|
||||
self.expectDataGet( "/test/a3s", { "type": "foobar" } ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
|
||||
a3s = self.o.get_a3s( "foobar" )
|
||||
self.assertEqual( len( a3s ), 3 )
|
||||
|
||||
class GithubObjectWithListGetableExternalListOfObjectsWithOtherUrl( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/other/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( [], [ "type" ] ), url = "/other" )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/other", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
|
||||
a3s = self.o.get_a3s()
|
||||
self.assertEqual( len( a3s ), 3 )
|
||||
self.assertEqual( a3s[ 0 ].id, "id1" )
|
||||
self.expectDataGet( "/other/id1" ).andReturn( { "name": "name1" } )
|
||||
self.assertEqual( a3s[ 0 ].name, "name1" )
|
||||
|
||||
class GithubObjectWithListGetableExternalListOfObjectsWithAttributeModifier( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name", "_a" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( [], [ "type" ], { "_a": lambda obj: 42 } ) )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/test/a3s", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
|
||||
a3s = self.o.get_a3s()
|
||||
self.assertEqual( len( a3s ), 3 )
|
||||
self.assertEqual( a3s[ 0 ].id, "id1" )
|
||||
self.assertEqual( a3s[ 0 ]._a, 42 )
|
||||
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } )
|
||||
self.assertEqual( a3s[ 0 ].name, "name1" )
|
||||
|
||||
class GithubObjectWithElementAddableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" ),
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementAddable() )
|
||||
)
|
||||
|
||||
def testAddToList( self ):
|
||||
a3ToAdd = self.ContainedObject( self.g.object, { "id": "idAdd", "name": "nameAdd" }, lazy = True )
|
||||
self.expectStatusPut( "/test/a3s/idAdd" ).andReturn( 204 )
|
||||
self.o.add_to_a3s( a3ToAdd )
|
||||
|
||||
class GithubObjectWithElementRemovableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" ),
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementRemovable() )
|
||||
)
|
||||
|
||||
def testRemoveFromList( self ):
|
||||
a3ToRemove = self.ContainedObject( self.g.object, { "id": "idRemove", "name": "nameRemove" }, lazy = True )
|
||||
self.expectStatusDelete( "/test/a3s/idRemove" ).andReturn( 204 )
|
||||
self.o.remove_from_a3s( a3ToRemove )
|
||||
|
||||
class GithubObjectWithElementHasableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" ),
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementHasable() )
|
||||
)
|
||||
|
||||
def testHasInList( self ):
|
||||
a3ToQuery = self.ContainedObject( self.g.object, { "id": "idQuery", "name": "nameQuery" }, lazy = True )
|
||||
self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 204 )
|
||||
self.assertTrue( self.o.has_in_a3s( a3ToQuery ) )
|
||||
self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 404 )
|
||||
self.assertFalse( self.o.has_in_a3s( a3ToQuery ) )
|
||||
|
||||
class GithubObjectWithElementCreatableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" ),
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementCreatable( [ "name" ], [ "p1", "p2" ] ) )
|
||||
)
|
||||
|
||||
def testCreate( self ):
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate" } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( name = "nameCreate" ).id, "idCreate" )
|
||||
|
||||
def testCreateWithOptionalArguments( self ):
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( name = "nameCreate", p1 = 1 ).id, "idCreate" )
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p2": 2 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( name = "nameCreate", p2 = 2 ).id, "idCreate" )
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1, "p2": 2 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( name = "nameCreate", p2 = 2, p1 = 1 ).id, "idCreate" )
|
||||
|
||||
def testCreateWithPositionalArguments( self ):
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( "nameCreate", 1 ).id, "idCreate" )
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p2": 2 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( "nameCreate", p2 = 2 ).id, "idCreate" )
|
||||
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1, "p2": 2 } ).andReturn( { "id": "idCreate" } )
|
||||
self.assertEqual( self.o.create_a3( "nameCreate", 1, 2 ).id, "idCreate" )
|
||||
|
||||
def testCreateWithSillyArgument( self ):
|
||||
self.g.expect._dataRequest.andReturn( None )
|
||||
with self.assertRaises( TypeError ):
|
||||
self.o.create_a3( foobar = 42 )
|
||||
|
||||
class GithubObjectWithSeveralElementsAddableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, SeveralElementsAddable() )
|
||||
)
|
||||
|
||||
def testAddToList( self ):
|
||||
self.expectStatusPost( "/test/a3s", [ "id1", "id2" ] )
|
||||
self.o.add_to_a3s( self.ContainedObject( self.g, { "id": "id1" }, lazy = True ), self.ContainedObject( self.g, { "id": "id2" }, lazy = True ) )
|
||||
|
||||
class GithubObjectWithListSetableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
Identity( lambda obj: obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListSetable() )
|
||||
)
|
||||
|
||||
def testSetList( self ):
|
||||
self.expectStatusPut( "/test/a3s", [ "id1", "id2" ] )
|
||||
self.o.set_a3s( self.ContainedObject( self.g, { "id": "id1" }, lazy = True ), self.ContainedObject( self.g, { "id": "id2" }, lazy = True ) )
|
||||
|
||||
class GithubObjectWithListDeletableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListDeletable() )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectStatusDelete( "/test/a3s" )
|
||||
self.o.delete_a3s()
|
||||
|
||||
class GithubObjectWithElementGetableExternalListOfObjects( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementGetable( [ "id" ], [] ) )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/test/a3s/idGet" ).andReturn( { "id": "idGet" } )
|
||||
self.assertEqual( self.o.get_a3( "idGet" ).id, "idGet" )
|
||||
|
||||
class GithubObjectWithMultiCapacityExternalListOfSimpleTypes( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalListOfSimpleTypes( "a3s", "a3", "",
|
||||
ListGetable( [], [] ),
|
||||
SeveralElementsAddable(),
|
||||
SeveralElementsRemovable(),
|
||||
)
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/test/a3s", {} ).andReturn( [ "a", "b", "c" ] )
|
||||
a3s = self.o.get_a3s()
|
||||
self.assertEqual( len( a3s ), 3 )
|
||||
self.assertEqual( a3s[ 0 ], "a" )
|
||||
|
||||
def testAddToList( self ):
|
||||
self.expectStatusPost( "/test/a3s", [ "a", "b", "c" ] ).andReturn( 204 )
|
||||
a3s = self.o.add_to_a3s( "a", "b", "c" )
|
||||
|
||||
def testDeleteFromList( self ):
|
||||
self.expectStatusDelete( "/test/a3s", [ "a", "b", "c" ] ).andReturn( 204 )
|
||||
a3s = self.o.remove_from_a3s( "a", "b", "c" )
|
||||
|
||||
class GithubObjectWithExternalSimpleAttribute( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
ExternalSimpleAttribute( "a3", "" )
|
||||
)
|
||||
|
||||
def testGetAttribute( self ):
|
||||
self.expectDataGet( "/test/a3" ).andReturn( 72 )
|
||||
self.assertEqual( self.o.get_a3(), 72 )
|
||||
|
||||
def myCallable( obj, mock, arg ):
|
||||
return mock.call( arg )
|
||||
class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a1", "a2" ),
|
||||
MethodFromCallable( "myMethod", [ "mock", "arg" ], [], myCallable, SimpleTypePolicy( None ) )
|
||||
)
|
||||
|
||||
def testCallMethod( self ):
|
||||
mock = MockMockMock.Mock( "myCallable" )
|
||||
mock.expect.call( 42 ).andReturn( 72 )
|
||||
self.assertEqual( self.o.myMethod( mock.object, 42 ), 72 )
|
||||
mock.tearDown()
|
||||
|
||||
class GithubObjectWithSeveralInternalSimpleAttributesAndInternalObjectAttributes( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
InternalSimpleAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
InternalSimpleAttributes( "a2", "a4" ),
|
||||
InternalSimpleAttributes( "a1", "a3" ),
|
||||
InternalObjectAttribute( "a5", ContainedObject ),
|
||||
)
|
||||
|
||||
def testCompletionInOneCall_1( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( {} )
|
||||
self.assertIsNone( self.o.a3 )
|
||||
self.assertIsNone( self.o.a4 )
|
||||
self.assertIsNone( self.o.a5 )
|
||||
|
||||
def testCompletionInOneCall_2( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( {} )
|
||||
self.assertIsNone( self.o.a4 )
|
||||
self.assertIsNone( self.o.a3 )
|
||||
self.assertIsNone( self.o.a5 )
|
||||
|
||||
def testCompletionInOneCall_3( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( {} )
|
||||
self.assertIsNone( self.o.a5 )
|
||||
self.assertIsNone( self.o.a3 )
|
||||
self.assertIsNone( self.o.a4 )
|
||||
|
||||
def testCompletionInOneCall_4( self ):
|
||||
self.expectDataGet( "/test" ).andReturn( {} )
|
||||
self.assertIsNone( self.o.a5 )
|
||||
self.assertIsNone( self.o.a4 )
|
||||
self.assertIsNone( self.o.a3 )
|
||||
|
||||
unittest.main()
|
||||
@@ -0,0 +1,114 @@
|
||||
import itertools
|
||||
|
||||
from ObjectCapacities.ArgumentsChecker import *
|
||||
from ObjectCapacities.Basic import *
|
||||
from ObjectCapacities.List import *
|
||||
from ObjectCapacities.TypePolicies import *
|
||||
|
||||
class BadGithubObjectException( Exception ):
|
||||
pass
|
||||
|
||||
def InternalSimpleAttribute( attributeName ):
|
||||
return InternalAttribute( attributeName, SimpleTypePolicy( None ) )
|
||||
|
||||
def InternalSimpleAttributes( *attributeNames ):
|
||||
return SeveralAttributePolicies( [ InternalSimpleAttribute( attributeName ) for attributeName in attributeNames ], "Attributes" )
|
||||
|
||||
def InternalObjectAttribute( attributeName, type ):
|
||||
return InternalAttribute( attributeName, ObjectTypePolicy( type ) )
|
||||
|
||||
def ExternalSimpleAttribute( attributeName, type ):
|
||||
return ExternalAttribute( attributeName, SimpleTypePolicy( type ) )
|
||||
|
||||
def BaseUrl( baseUrl ):
|
||||
return MethodFromCallable( "_baseUrl", [], [], baseUrl, SimpleTypePolicy( None ) )
|
||||
|
||||
def Identity( identity ):
|
||||
return AttributeFromCallable( "_identity", identity )
|
||||
|
||||
def Editable( mandatoryParameters, optionalParameters ):
|
||||
def __execute( obj, **data ):
|
||||
attributes = obj._github._dataRequest( "PATCH", obj._baseUrl(), None, data )
|
||||
obj._updateAttributes( attributes )
|
||||
return SeveralAttributePolicies( [ MethodFromCallable( "edit", mandatoryParameters, optionalParameters, __execute, SimpleTypePolicy( None ) ) ], "Modification" )
|
||||
|
||||
def Deletable():
|
||||
def __execute( obj ):
|
||||
obj._github._statusRequest( "DELETE", obj._baseUrl(), None, None )
|
||||
return SeveralAttributePolicies( [ MethodFromCallable( "delete", [], [], __execute, SimpleTypePolicy( None ) ) ], "Deletion" )
|
||||
|
||||
def GithubObject( className, *attributePolicies ):
|
||||
class GithubObject:
|
||||
__attributeDefinitions = dict()
|
||||
__methodDefinitions = dict()
|
||||
__attributePolicies = list()
|
||||
|
||||
@staticmethod
|
||||
def _addAttributePolicy( attributePolicy ):
|
||||
GithubObject.__attributePolicies.append( attributePolicy )
|
||||
attributePolicy.apply( GithubObject )
|
||||
|
||||
@staticmethod
|
||||
def _addAttribute( attributeName, attributeDefinition ):
|
||||
GithubObject.__checkAttributeName( attributeName )
|
||||
GithubObject.__attributeDefinitions[ attributeName ] = attributeDefinition
|
||||
|
||||
@staticmethod
|
||||
def _addMethod( methodName, methodDefinition ):
|
||||
GithubObject.__checkAttributeName( methodName )
|
||||
GithubObject.__methodDefinitions[ methodName ] = methodDefinition
|
||||
|
||||
@staticmethod
|
||||
def __checkAttributeName( attributeName ):
|
||||
if attributeName in GithubObject.__attributeDefinitions or attributeName in GithubObject.__methodDefinitions:
|
||||
raise BadGithubObjectException( "Same attribute defined by two policies" )
|
||||
|
||||
def __init__( self, github, attributes, lazy ):
|
||||
self._github = github
|
||||
self.__attributes = dict()
|
||||
self._updateAttributes( attributes )
|
||||
if not lazy:
|
||||
for attributeName in GithubObject.__attributeDefinitions:
|
||||
if attributeName not in self.__attributes:
|
||||
self.__fetchAttribute( attributeName )
|
||||
|
||||
def __getattr__( self, attributeName ):
|
||||
if attributeName in GithubObject.__methodDefinitions:
|
||||
return lambda *args, **kwds: GithubObject.__methodDefinitions[ attributeName ]( self, *args, **kwds )
|
||||
elif attributeName in GithubObject.__attributeDefinitions:
|
||||
if attributeName not in self.__attributes:
|
||||
self.__fetchAttribute( attributeName )
|
||||
return self.__attributes[ attributeName ]
|
||||
else:
|
||||
raise AttributeError( attributeName )
|
||||
|
||||
def _updateAttributes( self, attributes ):
|
||||
for attributeName, attributeValue in attributes.iteritems():
|
||||
attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ]
|
||||
self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue )
|
||||
|
||||
def _markAsCompleted( self ):
|
||||
for attributeName, attributeDefinition in GithubObject.__attributeDefinitions.iteritems():
|
||||
if attributeDefinition.isLazy() and attributeName not in self.__attributes:
|
||||
self.__attributes[ attributeName ] = None
|
||||
|
||||
def __dir__( self ):
|
||||
return GithubObject.__attributeDefinitions.keys()
|
||||
|
||||
def __fetchAttribute( self, attributeName ):
|
||||
attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ]
|
||||
attributeDefinition.updateAttributes( self )
|
||||
|
||||
@classmethod
|
||||
def _autoDocument( cls ):
|
||||
doc = "Class `" + cls.__name__ + "`\n"
|
||||
doc += "=" * ( len( cls.__name__ ) + 8 ) + "\n"
|
||||
for attributePolicy in cls.__attributePolicies:
|
||||
doc += attributePolicy.autoDocument()
|
||||
doc += "\n"
|
||||
return doc
|
||||
|
||||
GithubObject.__name__ = className
|
||||
GithubObject._addAttributePolicy( SeveralAttributePolicies( attributePolicies ) )
|
||||
|
||||
return GithubObject
|
||||
@@ -0,0 +1,16 @@
|
||||
from GithubObject import *
|
||||
|
||||
def __testHook( hook ):
|
||||
hook._github._statusRequest( "POST", hook._baseUrl() + "/test", None, None )
|
||||
Hook = GithubObject(
|
||||
"Hook",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/hooks/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "updated_at", "created_at", "name", "events", "active", "config",
|
||||
"id", "last_response",
|
||||
"_repo",
|
||||
),
|
||||
Editable( [ "name", "config" ], [ "events", "add_events", "remove_events", "active" ] ),
|
||||
Deletable(),
|
||||
SeveralAttributePolicies( [ MethodFromCallable( "test", [], [], __testHook, SimpleTypePolicy( None ) ) ], "Testing" )
|
||||
)
|
||||
@@ -0,0 +1,39 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Milestone import Milestone
|
||||
from Label import Label
|
||||
from IssueComment import IssueComment
|
||||
from IssueEvent import IssueEvent
|
||||
|
||||
__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo }
|
||||
|
||||
Issue = GithubObject(
|
||||
"Issue",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/issues/" + str( obj.number ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "html_url", "number", "state", "title", "body", "labels",
|
||||
"comments", "closed_at", "created_at", "updated_at", "id", "closed_by",
|
||||
"pull_request",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
InternalObjectAttribute( "assignee", NamedUser ),
|
||||
InternalObjectAttribute( "milestone", Milestone ),
|
||||
Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ),
|
||||
ExternalListOfObjects( "labels", "label", Label,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
SeveralElementsAddable(),
|
||||
ListSetable(),
|
||||
ListDeletable(),
|
||||
ElementRemovable(),
|
||||
),
|
||||
ExternalListOfObjects( "comments", "comment", IssueComment,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
ElementCreatable( [ "body" ], [], __modifyAttributesForObjectsReferingReferedRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "events", "event", IssueEvent,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo )
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
|
||||
IssueComment = GithubObject(
|
||||
"IssueComment",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/issues/comments/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "body", "created_at", "updated_at", "id",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [ "body" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
|
||||
IssueEvent = GithubObject(
|
||||
"IssueEvent",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/issues/events/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"id", "url", "created_at", "issue", "event", "commit_id",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "actor", NamedUser ),
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
import urllib
|
||||
|
||||
from GithubObject import *
|
||||
|
||||
Label = GithubObject(
|
||||
"Label",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/labels/" + obj._identity ),
|
||||
Identity( lambda obj: urllib.quote( obj.name ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "name", "color",
|
||||
"_repo",
|
||||
),
|
||||
Editable( [ "name", "color" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Label import Label
|
||||
|
||||
__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo }
|
||||
|
||||
Milestone = GithubObject(
|
||||
"Milestone",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/milestones/" + str( obj.number ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "number", "state", "title", "description", "open_issues",
|
||||
"closed_issues", "created_at", "due_on",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "creator", NamedUser ),
|
||||
Editable( [ "title" ], [ "state", "description", "due_on" ] ),
|
||||
Deletable(),
|
||||
ExternalListOfObjects( "labels", "label", Label,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo )
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
from GithubObject import *
|
||||
|
||||
from Event import Event
|
||||
|
||||
def __getPublicEvents( user ):
|
||||
return [
|
||||
Event( user._github, attributes, lazy = True )
|
||||
for attributes
|
||||
in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None )
|
||||
]
|
||||
|
||||
def __getPublicReceivedEvents( user ):
|
||||
return [
|
||||
Event( user._github, attributes, lazy = True )
|
||||
for attributes
|
||||
in user._github._dataRequest( "GET", user._baseUrl() + "/received_events/public", None, None )
|
||||
]
|
||||
|
||||
NamedUser = GithubObject(
|
||||
"NamedUser",
|
||||
BaseUrl( lambda obj: "/users/" + obj.login ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
InternalSimpleAttributes(
|
||||
"login", "id", "avatar_url", "gravatar_id", "url", "name", "company",
|
||||
"blog", "location", "email", "hireable", "bio", "public_repos",
|
||||
"public_gists", "followers", "following", "html_url", "created_at",
|
||||
"type",
|
||||
# Only in Repository.get_contributors()
|
||||
"contributions",
|
||||
# Seen only by user herself
|
||||
"disk_usage", "collaborators", "plan", "total_private_repos",
|
||||
"owned_private_repos", "private_gists",
|
||||
),
|
||||
ExternalListOfObjects( "events", "event", Event,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ),
|
||||
ExternalListOfObjects( "received_events", "received_event", Event,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ),
|
||||
)
|
||||
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "followers", "follower", NamedUser,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "following", "following", NamedUser,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
import itertools
|
||||
|
||||
class ArgumentsChecker:
|
||||
def __init__( self, mandatoryParameters, optionalParameters ):
|
||||
self.__mandatoryParameters = mandatoryParameters
|
||||
self.__optionalParameters = optionalParameters
|
||||
|
||||
def check( self, args, kwds ):
|
||||
data = dict( kwds )
|
||||
for arg, argumentName in itertools.izip( args, itertools.chain( self.__mandatoryParameters, self.__optionalParameters ) ):
|
||||
if argumentName in kwds:
|
||||
raise TypeError()
|
||||
else:
|
||||
data[ argumentName ] = arg
|
||||
for argumentName in data:
|
||||
if argumentName not in itertools.chain( self.__mandatoryParameters, self.__optionalParameters ):
|
||||
raise TypeError()
|
||||
for argumentName in self.__mandatoryParameters:
|
||||
if argumentName not in data:
|
||||
raise TypeError()
|
||||
return data
|
||||
|
||||
def documentParameters( self ):
|
||||
mandatory = ", ".join( self.__mandatoryParameters )
|
||||
optional = "[" + ", ".join( self.__optionalParameters ) + "]"
|
||||
|
||||
if len( self.__mandatoryParameters ) == 0:
|
||||
if len( self.__optionalParameters ) == 0:
|
||||
return ""
|
||||
else:
|
||||
return " " + optional + " "
|
||||
else:
|
||||
if len( self.__optionalParameters ) == 0:
|
||||
return " " + mandatory + " "
|
||||
else:
|
||||
return " " + mandatory + ", " + optional + " "
|
||||
@@ -0,0 +1,120 @@
|
||||
from ArgumentsChecker import *
|
||||
|
||||
class AttributeFromCallable:
|
||||
class AttributeDefinition:
|
||||
def __init__( self, name, callable ):
|
||||
self.__name = name
|
||||
self.__callable = callable
|
||||
|
||||
def getValueFromRawValue( self, obj, rawValue ):
|
||||
return rawValue
|
||||
|
||||
def updateAttributes( self, obj ):
|
||||
obj._updateAttributes( { self.__name: self.__callable( obj ) } )
|
||||
|
||||
def isLazy( self ):
|
||||
return False
|
||||
|
||||
def __init__( self, name, callable ):
|
||||
self.__name = name
|
||||
self.__callable = callable
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addAttribute( self.__name, AttributeFromCallable.AttributeDefinition( self.__name, self.__callable ) )
|
||||
|
||||
def autoDocument( self ):
|
||||
return ""
|
||||
|
||||
class MethodFromCallable:
|
||||
def __init__( self, name, mandatoryParameters, optionalParameters, callable, returnTypePolicy ):
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
self.__name = name
|
||||
self.__callable = callable
|
||||
self.__returnTypePolicy = returnTypePolicy
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( self.__name, self.__execute )
|
||||
|
||||
def __execute( self, obj, *args, **kwds ):
|
||||
data = self.__argumentsChecker.check( args, kwds )
|
||||
return self.__callable( obj, **data )
|
||||
|
||||
def autoDocument( self ):
|
||||
if self.__name.startswith( "_" ):
|
||||
return ""
|
||||
else:
|
||||
doc = "* `" + self.__name + "(" + self.__argumentsChecker.documentParameters() + ")`"
|
||||
if self.__returnTypePolicy.hasMeaningfulDocumentation():
|
||||
doc += ": " + self.__returnTypePolicy.documentTypeName()
|
||||
doc += "\n"
|
||||
return doc
|
||||
|
||||
class InternalAttribute:
|
||||
class AttributeDefinition:
|
||||
def __init__( self, typePolicy ):
|
||||
self.__typePolicy = typePolicy
|
||||
|
||||
def getValueFromRawValue( self, obj, rawValue ):
|
||||
if rawValue is None:
|
||||
return None
|
||||
else:
|
||||
return self.__typePolicy.createLazy( obj, rawValue )
|
||||
|
||||
def updateAttributes( self, obj ):
|
||||
attributes = obj._github._dataRequest( "GET", obj._baseUrl(), None, None )
|
||||
obj._updateAttributes( attributes )
|
||||
obj._markAsCompleted()
|
||||
|
||||
def isLazy( self ):
|
||||
return True
|
||||
|
||||
def __init__( self, attributeName, typePolicy ):
|
||||
self.__attributeName = attributeName
|
||||
self.__typePolicy = typePolicy
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addAttribute( self.__attributeName, InternalAttribute.AttributeDefinition( self.__typePolicy ) )
|
||||
|
||||
def autoDocument( self ):
|
||||
if self.__attributeName.startswith( "_" ):
|
||||
return ""
|
||||
doc = "* `" + self.__attributeName + "`"
|
||||
if self.__typePolicy.hasMeaningfulDocumentation():
|
||||
doc += ": " + self.__typePolicy.documentTypeName()
|
||||
doc += "\n"
|
||||
return doc
|
||||
|
||||
class ExternalAttribute:
|
||||
def __init__( self, attributeName, typePolicy ):
|
||||
self.__attributeName = attributeName
|
||||
self.__typePolicy = typePolicy
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "get_" + self.__attributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj ):
|
||||
return self.__typePolicy.createLazy(
|
||||
obj,
|
||||
obj._github._dataRequest( "GET", obj._baseUrl() + "/" + self.__attributeName, None, None )
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `get_" + self.__attributeName + "()`: " + self.__typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class SeveralAttributePolicies:
|
||||
def __init__( self, attributePolicies, documentationSection = None ):
|
||||
self.__attributePolicies = attributePolicies
|
||||
self.__documentationSection = documentationSection
|
||||
|
||||
def apply( self, cls ):
|
||||
for attributePolicy in self.__attributePolicies:
|
||||
attributePolicy.apply( cls )
|
||||
|
||||
def autoDocument( self ):
|
||||
doc = ""
|
||||
if self.__documentationSection is not None:
|
||||
doc += "\n"
|
||||
doc += self.__documentationSection + "\n"
|
||||
doc += "-" * len( self.__documentationSection ) + "\n"
|
||||
doc += "".join( attributePolicy.autoDocument() for attributePolicy in self.__attributePolicies )
|
||||
return doc
|
||||
@@ -0,0 +1,224 @@
|
||||
import itertools
|
||||
|
||||
from Basic import *
|
||||
from TypePolicies import *
|
||||
from ArgumentsChecker import *
|
||||
|
||||
class ListCapacity:
|
||||
def setList( self, attributeName, singularName, typePolicy, url = None ):
|
||||
self.attributeName = attributeName
|
||||
self.singularName = singularName
|
||||
self.safeAttributeName = attributeName.replace( "/", "_" )
|
||||
self.safeSingularName = singularName.replace( "/", "_" )
|
||||
self.typePolicy = typePolicy
|
||||
self.__url = url
|
||||
|
||||
def baseUrl( self, obj ):
|
||||
if self.__url is None:
|
||||
return obj._baseUrl() + "/" + self.attributeName
|
||||
else:
|
||||
return self.__url
|
||||
|
||||
class ElementAddable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "add_to_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, toBeAdded ):
|
||||
obj._github._statusRequest(
|
||||
"PUT",
|
||||
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeAdded ),
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `add_to_" + self.safeAttributeName + "( " + self.singularName + " )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ElementRemovable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "remove_from_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, toBeDeleted ):
|
||||
obj._github._statusRequest(
|
||||
"DELETE",
|
||||
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeDeleted ),
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `remove_from_" + self.safeAttributeName + "( " + self.singularName + " )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ElementHasable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "has_in_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, toBeQueried ):
|
||||
return obj._github._statusRequest(
|
||||
"GET",
|
||||
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeQueried ),
|
||||
None,
|
||||
None
|
||||
) == 204
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `has_in_" + self.safeAttributeName + "( " + self.singularName + " )`: bool\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ListCapacityWithModifier( ListCapacity ):
|
||||
def __init__( self, attributeModifiers ):
|
||||
self.__attributeModifiers = attributeModifiers
|
||||
|
||||
def _modifyAttributes( self, obj, attributes ):
|
||||
for attributeName, attributeModifier in self.__attributeModifiers.iteritems():
|
||||
attributes[ attributeName ] = attributeModifier( obj )
|
||||
return attributes
|
||||
|
||||
class ElementCreatable( ListCapacityWithModifier ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ):
|
||||
ListCapacityWithModifier.__init__( self, attributeModifiers )
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "create_" + self.singularName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *args, **kwds ):
|
||||
return self.typePolicy.createLazy(
|
||||
obj,
|
||||
self._modifyAttributes(
|
||||
obj,
|
||||
obj._github._dataRequest(
|
||||
"POST",
|
||||
self.baseUrl( obj ),
|
||||
None,
|
||||
self.__argumentsChecker.check( args, kwds )
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `create_" + self.singularName + "(" + self.__argumentsChecker.documentParameters() + ")`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ElementGetable( ListCapacityWithModifier ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ):
|
||||
ListCapacityWithModifier.__init__( self, attributeModifiers )
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "get_" + self.singularName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *args, **kwds ):
|
||||
return self.typePolicy.createNonLazy(
|
||||
obj,
|
||||
self._modifyAttributes(
|
||||
obj,
|
||||
self.__argumentsChecker.check( args, kwds )
|
||||
)
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `get_" + self.singularName + "(" + self.__argumentsChecker.documentParameters() + ")`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class SeveralElementsAddable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "add_to_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *toBeAddeds ):
|
||||
obj._github._statusRequest(
|
||||
"POST",
|
||||
self.baseUrl( obj ),
|
||||
None,
|
||||
[
|
||||
self.typePolicy.getIdentity( toBeAdded )
|
||||
for toBeAdded in toBeAddeds
|
||||
]
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `add_to_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class SeveralElementsRemovable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "remove_from_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *toBeDeleteds ):
|
||||
obj._github._statusRequest(
|
||||
"DELETE",
|
||||
self.baseUrl( obj ),
|
||||
None,
|
||||
[
|
||||
self.typePolicy.getIdentity( toBeDeleted )
|
||||
for toBeDeleted in toBeDeleteds
|
||||
]
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `remove_from_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ListGetable( ListCapacityWithModifier ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ):
|
||||
ListCapacityWithModifier.__init__( self, attributeModifiers )
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "get_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *args, **kwds ):
|
||||
params = self.__argumentsChecker.check( args, kwds )
|
||||
return [
|
||||
self.typePolicy.createLazy(
|
||||
obj,
|
||||
self._modifyAttributes( obj, attributes )
|
||||
)
|
||||
for attributes in obj._github._dataRequest(
|
||||
"GET",
|
||||
self.baseUrl( obj ),
|
||||
params,
|
||||
None
|
||||
)
|
||||
]
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `get_" + self.safeAttributeName + "(" + self.__argumentsChecker.documentParameters() + ")`: list of " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ListSetable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "set_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj, *toBeSets ):
|
||||
obj._github._statusRequest(
|
||||
"PUT",
|
||||
self.baseUrl( obj ),
|
||||
None,
|
||||
[
|
||||
self.typePolicy.getIdentity( toBeSet )
|
||||
for toBeSet in toBeSets
|
||||
]
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `set_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
|
||||
|
||||
class ListDeletable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "delete_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
def __execute( self, obj ):
|
||||
obj._github._statusRequest(
|
||||
"DELETE",
|
||||
self.baseUrl( obj ),
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
def autoDocument( self ):
|
||||
return "* `delete_" + self.safeAttributeName + "()`\n"
|
||||
|
||||
def ExternalListOfObjects( attributeName, singularName, type, *capacities, **kwds ):
|
||||
for capacity in capacities:
|
||||
capacity.setList( attributeName, singularName, ObjectTypePolicy( type ), **kwds )
|
||||
return SeveralAttributePolicies( capacities, attributeName.capitalize().replace( "_", " " ).replace( "/", " " ) )
|
||||
|
||||
def ExternalListOfSimpleTypes( attributeName, singularName, type, *capacities ):
|
||||
for capacity in capacities:
|
||||
capacity.setList( attributeName, singularName, SimpleTypePolicy( type ) )
|
||||
return SeveralAttributePolicies( capacities, attributeName.capitalize().replace( "_", " " ).replace( "/", " " ) )
|
||||
@@ -0,0 +1,35 @@
|
||||
class SimpleTypePolicy:
|
||||
def __init__( self, type ):
|
||||
self.__type = type
|
||||
|
||||
def createLazy( self, obj, value ):
|
||||
return value
|
||||
|
||||
def getIdentity( self, value ):
|
||||
return value
|
||||
|
||||
def hasMeaningfulDocumentation( self ):
|
||||
return self.__type is not None
|
||||
|
||||
def documentTypeName( self ):
|
||||
return self.__type
|
||||
|
||||
class ObjectTypePolicy:
|
||||
def __init__( self, type ):
|
||||
self.__type = type
|
||||
|
||||
def createLazy( self, obj, attributes ):
|
||||
return self.__type( obj._github, attributes, lazy = True )
|
||||
|
||||
def createNonLazy( self, obj, attributes ):
|
||||
return self.__type( obj._github, attributes, lazy = False )
|
||||
|
||||
def getIdentity( self, obj ):
|
||||
assert isinstance( obj, self.__type )
|
||||
return obj._identity
|
||||
|
||||
def hasMeaningfulDocumentation( self ):
|
||||
return True
|
||||
|
||||
def documentTypeName( self ):
|
||||
return "`" + self.__type.__name__ + "`"
|
||||
@@ -0,0 +1,33 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Event import Event
|
||||
|
||||
Organization = GithubObject(
|
||||
"Organization",
|
||||
BaseUrl( lambda obj: "/orgs/" + obj.login ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
InternalSimpleAttributes(
|
||||
"login", "id", "url", "avatar_url", "name", "company", "blog",
|
||||
"location", "email", "public_repos", "public_gists", "followers",
|
||||
"following", "html_url", "created_at", "type", "gravatar_id",
|
||||
# Seen only by owners
|
||||
"disk_usage", "collaborators", "billing_email", "plan", "private_gists",
|
||||
"total_private_repos", "owned_private_repos",
|
||||
),
|
||||
Editable( [], [ "billing_email", "blog", "company", "email", "location", "name" ] ),
|
||||
ExternalListOfObjects( "public_members", "public_member", NamedUser,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
ExternalListOfObjects( "members", "member", NamedUser,
|
||||
ListGetable( [], [] ),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
ExternalListOfObjects( "events", "event", Event,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Commit import Commit
|
||||
from PullRequestFile import PullRequestFile
|
||||
from PullRequestComment import PullRequestComment
|
||||
|
||||
__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo }
|
||||
|
||||
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 ) ),
|
||||
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",
|
||||
),
|
||||
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 ),
|
||||
),
|
||||
MethodFromCallable( "is_merged", [], [], __pullRequestIsMerged, SimpleTypePolicy( "bool" ) ),
|
||||
MethodFromCallable( "merge", [], [ "commit_message" ], __mergePullRequest, SimpleTypePolicy( None ) ),
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
|
||||
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",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [ "body" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
from GithubObject import *
|
||||
|
||||
PullRequestFile = GithubObject(
|
||||
"PullRequestFile",
|
||||
InternalSimpleAttributes(
|
||||
"sha", "filename", "status", "additions", "deletions", "changes",
|
||||
"blob_url", "raw_url", "patch",
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,156 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Event import Event
|
||||
from IssueEvent import IssueEvent
|
||||
from RepositoryKey import RepositoryKey
|
||||
from Hook import Hook
|
||||
from GitBlob import GitBlob
|
||||
from GitCommit import GitCommit
|
||||
from GitRef import GitRef
|
||||
from GitTag import GitTag
|
||||
from GitTree import GitTree
|
||||
from Label import Label
|
||||
from Milestone import Milestone
|
||||
from Issue import Issue
|
||||
from Download import Download
|
||||
from CommitComment import CommitComment
|
||||
from Commit import Commit
|
||||
from Tag import Tag
|
||||
from Branch import Branch
|
||||
from PullRequest import PullRequest
|
||||
|
||||
__modifyAttributesForObjectsReferingRepo = { "_repo": lambda repo: repo }
|
||||
|
||||
Repository = GithubObject(
|
||||
"Repository",
|
||||
BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ),
|
||||
Identity( lambda obj: obj.owner.login + "/" + obj.name ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "html_url", "clone_url", "git_url", "ssh_url", "svn_url",
|
||||
"name", "description", "homepage", "language", "private",
|
||||
"fork", "forks", "watchers", "size", "master_branch", "open_issues",
|
||||
"pushed_at", "created_at", "organization",
|
||||
"has_issues", "has_wiki", "has_downloads",
|
||||
# Not documented
|
||||
"mirror_url", "updated_at", "id",
|
||||
),
|
||||
InternalObjectAttribute( "owner", NamedUser ),
|
||||
)
|
||||
Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) )
|
||||
Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) )
|
||||
Repository._addAttributePolicy(
|
||||
ExternalListOfObjects( "events", "event", Event,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
)
|
||||
def __getNetworkEvents( repo ):
|
||||
return [
|
||||
Event( repo._github, attributes, lazy = True )
|
||||
for attributes
|
||||
in repo._github._dataRequest( "GET", "/networks/" + repo.owner.login + "/" + repo.name + "/events", None, None )
|
||||
]
|
||||
Repository._addAttributePolicy(
|
||||
MethodFromCallable( "get_network_events", [], [], __getNetworkEvents, SimpleTypePolicy( "list of `Event`" ) )
|
||||
)
|
||||
Repository._addAttributePolicy(
|
||||
ExternalListOfObjects( "issues/events", "issues_event", IssueEvent,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
)
|
||||
)
|
||||
Repository._addAttributePolicy(
|
||||
ExternalListOfObjects( "forks", "fork", Repository,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
Repository._addAttributePolicy(
|
||||
Editable( [ "name" ], [ "description", "homepage", "public", "has_issues", "has_wiki", "has_downloads" ] )
|
||||
)
|
||||
Repository._addAttributePolicy(
|
||||
SeveralAttributePolicies( [ ExternalSimpleAttribute( "languages", "dictionary of strings to integers" ) ], "Languages" )
|
||||
)
|
||||
Repository._addAttributePolicy( SeveralAttributePolicies( [
|
||||
ExternalListOfObjects( "hooks", "hook", Hook,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "name", "config" ], [ "events", "active" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "keys", "key", RepositoryKey,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "title", "key" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "collaborators", "collaborator", NamedUser,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
ExternalListOfObjects( "contributors", "contributor", NamedUser,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
ExternalListOfObjects( "watchers", "watcher", NamedUser,
|
||||
ListGetable( [], [] )
|
||||
),
|
||||
ExternalListOfObjects( "git/refs", "git_ref", GitRef,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "ref" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "ref", "sha" ], [], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "git/commits", "git_commit", GitCommit,
|
||||
ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "message", "tree", "parents" ], [ "author", "committer" ], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "git/trees", "git_tree", GitTree,
|
||||
ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "tree" ], [], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "git/blobs", "git_blob", GitBlob,
|
||||
ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "content", "encoding" ], [], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "git/tags", "git_tag", GitTag,
|
||||
ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "tag", "message", "object", "type" ], [ "tagger" ], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "labels", "label", Label,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "name" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "name", "color" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "milestones", "milestone", Milestone,
|
||||
ListGetable( [], [ "state", "sort", "direction" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "title" ], [ "state", "description", "due_on" ], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "issues", "issue", Issue,
|
||||
ListGetable( [], [ "milestone", "state", "assignee", "mentioned", "labels", "sort", "direction", "since" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo )
|
||||
),
|
||||
ExternalListOfObjects( "downloads", "download", Download,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "name", "size" ], [ "description", "content_type" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "comments", "comment", CommitComment,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "commits", "commit", Commit,
|
||||
ListGetable( [], [ "sha", "path" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "tags", "tag", Tag,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "branches", "branch", Branch,
|
||||
ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
ExternalListOfObjects( "pulls", "pull", PullRequest,
|
||||
ListGetable( [], [ "state" ], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
ElementCreatable( [ "title", "body", "base", "head" ], [], __modifyAttributesForObjectsReferingRepo ),
|
||||
),
|
||||
] ) )
|
||||
@@ -0,0 +1,12 @@
|
||||
from GithubObject import *
|
||||
|
||||
RepositoryKey = GithubObject(
|
||||
"RepositoryKey",
|
||||
BaseUrl( lambda obj: obj._repo._baseUrl() + "/keys/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "id", "title", "key",
|
||||
"_repo",
|
||||
),
|
||||
Editable( [ "title", "key" ], [] ),
|
||||
Deletable()
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
from GithubObject import *
|
||||
|
||||
from Commit import Commit
|
||||
|
||||
Tag = GithubObject(
|
||||
"Tag",
|
||||
InternalSimpleAttributes(
|
||||
"name", "zipball_url", "tarball_url",
|
||||
"_repo",
|
||||
),
|
||||
InternalObjectAttribute( "commit", Commit )
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
from GithubObject import *
|
||||
|
||||
from NamedUser import NamedUser
|
||||
from Repository import Repository
|
||||
|
||||
Team = GithubObject(
|
||||
"Team",
|
||||
BaseUrl( lambda obj: "/teams/" + str( obj.id ) ),
|
||||
Identity( lambda obj: str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "name", "id", "permission", "members_count", "repos_count",
|
||||
),
|
||||
Editable( [ "name" ], [ "permission" ] ),
|
||||
Deletable(),
|
||||
ExternalListOfObjects( "members", "member", NamedUser,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
ExternalListOfObjects( "repos", "repo", Repository,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
from GithubObject import *
|
||||
|
||||
UserKey = GithubObject(
|
||||
"UserKey",
|
||||
BaseUrl( lambda obj: "/user/keys/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "id", "title", "key",
|
||||
),
|
||||
Editable( [], [ "title", "key" ] ),
|
||||
Deletable(),
|
||||
)
|
||||
@@ -0,0 +1,129 @@
|
||||
from GithubObject import *
|
||||
|
||||
from Event import Event
|
||||
from Hook import Hook
|
||||
from Authorization import Authorization
|
||||
from UserKey import UserKey
|
||||
from AuthenticatedUser import AuthenticatedUser
|
||||
from NamedUser import NamedUser
|
||||
from Organization import Organization
|
||||
from GitRef import GitRef
|
||||
from GitTree import GitTree
|
||||
from GitCommit import GitCommit
|
||||
from GitBlob import GitBlob
|
||||
from GitTag import GitTag
|
||||
from Label import Label
|
||||
from Milestone import Milestone
|
||||
from IssueComment import IssueComment
|
||||
from IssueEvent import IssueEvent
|
||||
from Issue import Issue
|
||||
from Download import Download
|
||||
from CommitComment import CommitComment
|
||||
from Commit import Commit
|
||||
from Tag import Tag
|
||||
from Branch import Branch
|
||||
from PullRequestFile import PullRequestFile
|
||||
from PullRequestComment import PullRequestComment
|
||||
from PullRequest import PullRequest
|
||||
from RepositoryKey import RepositoryKey
|
||||
from Repository import Repository
|
||||
from Team import Team
|
||||
from GistComment import GistComment
|
||||
from Gist import Gist
|
||||
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "orgs", "org", Organization,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
|
||||
__repoElementCreatable = ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )
|
||||
__repoElementGetable = ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } )
|
||||
__repoListGetable = ListGetable( [], [ "type" ] )
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "repos", "repo", Repository,
|
||||
__repoListGetable,
|
||||
__repoElementGetable,
|
||||
__repoElementCreatable
|
||||
)
|
||||
)
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "repos", "repo", Repository,
|
||||
__repoListGetable,
|
||||
__repoElementGetable
|
||||
)
|
||||
)
|
||||
Organization._addAttributePolicy(
|
||||
ExternalListOfObjects( "repos", "repo", Repository,
|
||||
__repoListGetable,
|
||||
__repoElementGetable,
|
||||
__repoElementCreatable
|
||||
)
|
||||
)
|
||||
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "watched", "watched", Repository,
|
||||
ListGetable( [], [] ),
|
||||
ElementAddable(),
|
||||
ElementRemovable(),
|
||||
ElementHasable()
|
||||
)
|
||||
)
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "watched", "watched", Repository,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
|
||||
def __createForkForUser( user, repo ):
|
||||
assert isinstance( repo, Repository )
|
||||
return Repository( user._github, user._github._dataRequest( "POST", repo._baseUrl() + "/forks", None, None ), lazy = True )
|
||||
AuthenticatedUser._addAttributePolicy( SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForUser, ObjectTypePolicy( Repository ) ) ], "Forking" ) )
|
||||
def __createForkForOrg( org, repo ):
|
||||
assert isinstance( repo, Repository )
|
||||
return Repository( org._github, org._github._dataRequest( "POST", repo._baseUrl() + "/forks", { "org": org.login }, None ), lazy = True )
|
||||
Organization._addAttributePolicy( SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) )
|
||||
|
||||
Organization._addAttributePolicy(
|
||||
ExternalListOfObjects( "teams", "team", Team,
|
||||
ListGetable( [], [] ),
|
||||
ElementCreatable( [ "name" ], [ "repo_names", "permission" ] )
|
||||
)
|
||||
)
|
||||
Repository._addAttributePolicy(
|
||||
ExternalListOfObjects( "teams", "team", Team,
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "gists", "gist", Gist,
|
||||
ListGetable( [], [] ),
|
||||
)
|
||||
)
|
||||
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "gists", "gist", Gist,
|
||||
ListGetable( [], [] ),
|
||||
ElementCreatable( [ "public", "files", ], [ "description" ] ),
|
||||
url = "/gists",
|
||||
)
|
||||
)
|
||||
def __getStaredGists( user ):
|
||||
return [
|
||||
Gist( user._github, attributes, lazy = True )
|
||||
for attributes in user._github._dataRequest( "GET", "/gists/starred", None, None )
|
||||
]
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
MethodFromCallable( "get_starred_gists", [], [], __getStaredGists, SimpleTypePolicy( "list of `Gist`" ) ),
|
||||
)
|
||||
|
||||
Event._addAttributePolicy(
|
||||
InternalObjectAttribute( "repo", Repository ),
|
||||
)
|
||||
Event._addAttributePolicy(
|
||||
InternalObjectAttribute( "actor", NamedUser ),
|
||||
)
|
||||
Event._addAttributePolicy(
|
||||
InternalObjectAttribute( "org", Organization ),
|
||||
)
|
||||
Reference in New Issue
Block a user