mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
101 lines
5.5 KiB
Python
101 lines
5.5 KiB
Python
from GithubObject import *
|
|
|
|
AuthenticatedUser = GithubObject(
|
|
"AuthenticatedUser",
|
|
BaseUrl( lambda obj: "/user" ),
|
|
Identity( lambda obj: obj.login ),
|
|
BasicAttributes(
|
|
"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" ] ),
|
|
)
|
|
|
|
NamedUser = GithubObject(
|
|
"NamedUser",
|
|
BaseUrl( lambda obj: "/users/" + obj.login ),
|
|
Identity( lambda obj: obj.login ),
|
|
BasicAttributes(
|
|
"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",
|
|
),
|
|
)
|
|
|
|
AuthenticatedUser._addAttributePolicy( ListOfObjects( "followers", NamedUser, ListGetable( [], [] ) ) )
|
|
NamedUser._addAttributePolicy( ListOfObjects( "followers", NamedUser, ListGetable( [], [] ) ) )
|
|
|
|
AuthenticatedUser._addAttributePolicy( ListOfObjects( "following", NamedUser, ListGetable( [], [] ), ElementAddable(), ElementRemovable(), ElementHasable() ) )
|
|
NamedUser._addAttributePolicy( ListOfObjects( "following", NamedUser, ListGetable( [], [] ) ) )
|
|
|
|
Organization = GithubObject(
|
|
"Organization",
|
|
BaseUrl( lambda obj: "/orgs/" + obj.login ),
|
|
Identity( lambda obj: obj.login ),
|
|
BasicAttributes(
|
|
"login", "id", "url", "avatar_url", "name", "company", "blog",
|
|
"location", "email", "public_repos", "public_gists", "followers",
|
|
"following", "html_url", "created_at", "type",
|
|
# Seen only by owners
|
|
"disk_usage", "collaborators", "billing_email", "plan", "private_gists",
|
|
"total_private_repos", "owned_private_repos",
|
|
),
|
|
ListOfObjects( "public_members", NamedUser, ListGetable( [], [] ), ElementAddable(), ElementRemovable(), ElementHasable() ),
|
|
ListOfObjects( "members", NamedUser, ListGetable( [], [] ), ElementRemovable(), ElementHasable() ),
|
|
Editable( [], [ "billing_email", "blog", "company", "email", "location", "name" ] ),
|
|
)
|
|
|
|
AuthenticatedUser._addAttributePolicy( ListOfObjects( "orgs", Organization, ListGetable( [], [] ) ) )
|
|
NamedUser._addAttributePolicy( ListOfObjects( "orgs", Organization, ListGetable( [], [] ) ) )
|
|
|
|
Repository = GithubObject(
|
|
"Repository",
|
|
BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ),
|
|
Identity( lambda obj: obj.owner.login + "/" + obj.name ),
|
|
BasicAttributes(
|
|
"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",
|
|
),
|
|
ComplexAttribute( "owner", NamedUser ),
|
|
ListOfObjects( "collaborators", NamedUser, ListGetable( [], [] ), ElementAddable(), ElementRemovable(), ElementHasable() ),
|
|
ListOfObjects( "contributors", NamedUser, ListGetable( [], [] ) ),
|
|
ListOfObjects( "watchers", NamedUser, ListGetable( [], [] ) ),
|
|
Editable( [ "name" ], [ "description", "homepage", "public", "has_issues", "has_wiki", "has_downloads" ] ),
|
|
)
|
|
Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) )
|
|
Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )
|
|
Repository._addAttributePolicy( ListOfObjects( "forks", Repository, ListGetable( [], [] ) ) )
|
|
|
|
__repoElementCreatable = ElementCreatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )
|
|
__repoElementGetable = ElementGetable( "repo", lambda obj, name: { "owner": { "login": obj.login }, "name": name } )
|
|
__repoListGetable = ListGetable( [], [] )
|
|
AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, __repoListGetable, __repoElementGetable, __repoElementCreatable ) )
|
|
NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository, __repoListGetable, __repoElementGetable ) )
|
|
Organization._addAttributePolicy( ListOfObjects( "repos", Repository, __repoListGetable, __repoElementGetable, __repoElementCreatable ) )
|
|
|
|
AuthenticatedUser._addAttributePolicy( ListOfObjects( "watched", Repository, ListGetable( [], [] ), ElementAddable(), ElementRemovable(), ElementHasable() ) )
|
|
NamedUser._addAttributePolicy( ListOfObjects( "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( MethodFromCallable( "create_fork", __createForkForUser ) )
|
|
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( MethodFromCallable( "create_fork", __createForkForOrg ) )
|