diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index b050afdf..5c47e16d 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -549,16 +549,6 @@ Attributes * `owned_private_repos` * `private_gists` -Events ------- -* `get_events()`: list of `Event` -* `get_public_events()`: list of `Event` - -Received events ---------------- -* `get_received_events()`: list of `Event` -* `get_public_received_events()`: list of `Event` - Followers --------- * `get_followers()`: list of `NamedUser` @@ -571,6 +561,16 @@ Orgs ---- * `get_orgs()`: list of `Organization` +Events +------ +* `get_events()`: list of `Event` +* `get_public_events()`: list of `Event` + +Received events +--------------- +* `get_received_events()`: list of `Event` +* `get_public_received_events()`: list of `Event` + Repos ----- * `get_repos( [type] )`: list of `Repository` @@ -636,10 +636,6 @@ Members * `has_in_members( member )`: bool * `member`: `NamedUser` -Events ------- -* `get_events()`: list of `Event` - Repos ----- * `get_repos( [type] )`: list of `Repository` @@ -655,6 +651,10 @@ Teams * `get_teams()`: list of `Team` * `create_team( name, [repo_names, permission] )`: `Team` +Events +------ +* `get_events()`: list of `Event` + Class `PullRequest` =================== @@ -782,11 +782,6 @@ Attributes * `parent`: `Repository` * `source`: `Repository` -Events ------- -* `get_events()`: list of `Event` -* `get_network_events()`: list of `Event` - Issues events ------------- * `get_issues_events()`: list of `IssueEvent` @@ -912,6 +907,11 @@ Teams ----- * `get_teams()`: list of `Team` +Events +------ +* `get_events()`: list of `Event` +* `get_network_events()`: list of `Event` + Class `RepositoryKey` ===================== diff --git a/github/GenerateDocumentation.py b/github/GenerateDocumentation.py index 3c784671..eff4441b 100644 --- a/github/GenerateDocumentation.py +++ b/github/GenerateDocumentation.py @@ -1,6 +1,5 @@ #!/bin/env python -import GithubObject import GithubObjects def generateDocumentation(): diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index c7762ed1..0826c8ff 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -5,6 +5,8 @@ from UserKey import UserKey from Event import Event from NamedUser import NamedUser from Organization import Organization +from Repository import Repository +from Gist import Gist def __getOrganizationEvents( user, org ): return [ @@ -13,6 +15,16 @@ def __getOrganizationEvents( user, org ): in user._github._dataRequest( "GET", "/users/" + user.login + "/events/orgs/" + org.login, None, None ) ] +def __createFork( user, repo ): + assert isinstance( repo, Repository ) + return Repository( user._github, user._github._dataRequest( "POST", repo._baseUrl() + "/forks", None, None ), lazy = True ) + +def __getStaredGists( user ): + return [ + Gist( user._github, attributes, lazy = True ) + for attributes in user._github._dataRequest( "GET", "/gists/starred", None, None ) + ] + AuthenticatedUser = GithubObject( "AuthenticatedUser", BaseUrl( lambda obj: "/user" ), @@ -58,4 +70,22 @@ AuthenticatedUser = GithubObject( ListGetable( [], [] ) ), MethodFromCallable( "get_organization_events", [ "org" ], [], __getOrganizationEvents, SimpleTypePolicy( "list of `Event`" ) ), + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), + ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) + ), + ExternalListOfObjects( "watched", "watched", Repository, + ListGetable( [], [] ), + ElementAddable(), + ElementRemovable(), + ElementHasable() + ), + SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createFork, ObjectTypePolicy( Repository ) ) ], "Forking" ), + ExternalListOfObjects( "gists", "gist", Gist, + ListGetable( [], [] ), + ElementCreatable( [ "public", "files", ], [ "description" ] ), + url = "/gists", + ), + MethodFromCallable( "get_starred_gists", [], [], __getStaredGists, SimpleTypePolicy( "list of `Gist`" ) ), ) diff --git a/github/GithubObjects/Event.py b/github/GithubObjects/Event.py index ba568058..f2f80853 100644 --- a/github/GithubObjects/Event.py +++ b/github/GithubObjects/Event.py @@ -1,9 +1,16 @@ from GithubObject import * +from Repository import Repository +from NamedUser import NamedUser +from Organization import Organization + Event = GithubObject( "Event", InternalSimpleAttributes( "type", "public", "payload", "created_at", "id", "commit_id", "url", "event", "issue", ), -) + InternalObjectAttribute( "repo", Repository ), + InternalObjectAttribute( "actor", NamedUser ), + InternalObjectAttribute( "org", Organization ), +) \ No newline at end of file diff --git a/github/GithubObjects/NamedUser.py b/github/GithubObjects/NamedUser.py index 0d28b88c..335f8be0 100644 --- a/github/GithubObjects/NamedUser.py +++ b/github/GithubObjects/NamedUser.py @@ -1,20 +1,5 @@ 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", @@ -31,14 +16,6 @@ NamedUser = GithubObject( "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( diff --git a/github/GithubObjects/Organization.py b/github/GithubObjects/Organization.py index 5be8e67b..c257c10b 100644 --- a/github/GithubObjects/Organization.py +++ b/github/GithubObjects/Organization.py @@ -1,7 +1,6 @@ from GithubObject import * from NamedUser import NamedUser -from Event import Event Organization = GithubObject( "Organization", @@ -27,7 +26,4 @@ Organization = GithubObject( ElementRemovable(), ElementHasable() ), - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), ) diff --git a/github/GithubObjects/Repository.py b/github/GithubObjects/Repository.py index c5d702db..80f73920 100644 --- a/github/GithubObjects/Repository.py +++ b/github/GithubObjects/Repository.py @@ -1,7 +1,6 @@ from GithubObject import * from NamedUser import NamedUser -from Event import Event from IssueEvent import IssueEvent from RepositoryKey import RepositoryKey from Hook import Hook @@ -39,20 +38,6 @@ Repository = GithubObject( ) 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 ), diff --git a/github/GithubObjects/__init__.py b/github/GithubObjects/__init__.py index 01619561..35af54f2 100644 --- a/github/GithubObjects/__init__.py +++ b/github/GithubObjects/__init__.py @@ -31,58 +31,109 @@ from Team import Team from GistComment import GistComment from Gist import Gist +#### Complete NamedUser + 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 + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) ) ) -AuthenticatedUser._addAttributePolicy( - ExternalListOfObjects( "watched", "watched", Repository, - ListGetable( [], [] ), - ElementAddable(), - ElementRemovable(), - ElementHasable() +def __getPublicEvents( user ): + return [ + Event( user._github, attributes, lazy = True ) + for attributes + in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None ) + ] + +NamedUser._addAttributePolicy( + MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "received_events", "received_event", Event, + ListGetable( [], [] ) ) ) + +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._addAttributePolicy( + MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ) + ) +) + 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" ) ) +NamedUser._addAttributePolicy( + ExternalListOfObjects( "gists", "gist", Gist, + ListGetable( [], [] ), + ) +) + +#### Complete Repository + +Repository._addAttributePolicy( + ExternalListOfObjects( "teams", "team", Team, + ListGetable( [], [] ) + ) +) + +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`" ) ) +) + +#### Complete Organization + +Organization._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), + ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) + ) +) + 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( + SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) +) Organization._addAttributePolicy( ExternalListOfObjects( "teams", "team", Team, @@ -90,40 +141,9 @@ Organization._addAttributePolicy( ElementCreatable( [ "name" ], [ "repo_names", "permission" ] ) ) ) -Repository._addAttributePolicy( - ExternalListOfObjects( "teams", "team", Team, + +Organization._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, 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 ), + ), )