diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py
index e8bbcb5c..2c672960 100644
--- a/github/AuthenticatedUser.py
+++ b/github/AuthenticatedUser.py
@@ -38,10 +38,10 @@
# along with PyGithub. If not, see . #
# #
################################################################################
+from __future__ import annotations
-from collections import namedtuple
from datetime import datetime, timezone
-from typing import Any, Dict
+from typing import TYPE_CHECKING, Any, NamedTuple
import github.Authorization
import github.Event
@@ -54,370 +54,322 @@ import github.Migration
import github.NamedUser
import github.Notification
import github.Organization
-import github.PaginatedList
import github.Plan
import github.Repository
import github.UserKey
+from github import Consts
+from github.GithubObject import (
+ Attribute,
+ CompletableGithubObject,
+ NotSet,
+ Opt,
+ is_defined,
+ is_optional,
+ is_optional_list,
+ is_undefined,
+)
+from github.PaginatedList import PaginatedList
-from . import Consts
+if TYPE_CHECKING:
+ from github.Authorization import Authorization
+ from github.Event import Event
+ from github.Gist import Gist
+ from github.InputFileContent import InputFileContent
+ from github.Installation import Installation
+ from github.Invitation import Invitation
+ from github.Issue import Issue
+ from github.Label import Label
+ from github.Membership import Membership
+ from github.Migration import Migration
+ from github.NamedUser import NamedUser
+ from github.Notification import Notification
+ from github.Organization import Organization
+ from github.Plan import Plan
+ from github.Project import Project
+ from github.Repository import Repository
+ from github.Team import Team
+ from github.UserKey import UserKey
-class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
+class EmailData(NamedTuple):
+ email: str
+ primary: bool
+ verified: bool
+ visibility: str
+
+
+class AuthenticatedUser(CompletableGithubObject):
"""
This class represents AuthenticatedUsers as returned by https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
An AuthenticatedUser object can be created by calling ``get_user()`` on a Github object.
"""
+ def _initAttributes(self) -> None:
+ self._avatar_url: Attribute[str] = NotSet
+ self._bio: Attribute[str] = NotSet
+ self._blog: Attribute[str] = NotSet
+ self._collaborators: Attribute[int] = NotSet
+ self._company: Attribute[str] = NotSet
+ self._created_at: Attribute[datetime] = NotSet
+ self._disk_usage: Attribute[int] = NotSet
+ self._email: Attribute[str] = NotSet
+ self._events_url: Attribute[str] = NotSet
+ self._followers: Attribute[int] = NotSet
+ self._followers_url: Attribute[str] = NotSet
+ self._following: Attribute[int] = NotSet
+ self._following_url: Attribute[str] = NotSet
+ self._gists_url: Attribute[str] = NotSet
+ self._gravatar_id: Attribute[str] = NotSet
+ self._hireable: Attribute[bool] = NotSet
+ self._html_url: Attribute[str] = NotSet
+ self._id: Attribute[int] = NotSet
+ self._location: Attribute[str] = NotSet
+ self._login: Attribute[str] = NotSet
+ self._name: Attribute[str] = NotSet
+ self._node_id: Attribute[str] = NotSet
+ self._organizations_url: Attribute[str] = NotSet
+ self._owned_private_repos: Attribute[int] = NotSet
+ self._plan: Attribute[github.Plan.Plan] = NotSet
+ self._private_gists: Attribute[int] = NotSet
+ self._public_gists: Attribute[int] = NotSet
+ self._public_repos: Attribute[int] = NotSet
+ self._received_events_url: Attribute[str] = NotSet
+ self._repos_url: Attribute[str] = NotSet
+ self._site_admin: Attribute[bool] = NotSet
+ self._starred_url: Attribute[str] = NotSet
+ self._subscriptions_url: Attribute[str] = NotSet
+ self._total_private_repos: Attribute[int] = NotSet
+ self._type: Attribute[str] = NotSet
+ self._updated_at: Attribute[datetime] = NotSet
+ self._url: Attribute[str] = NotSet
+ self._two_factor_authentication: Attribute[bool] = NotSet
+
def __repr__(self) -> str:
return self.get__repr__({"login": self._login.value})
@property
- def avatar_url(self):
- """
- :type: string
- """
+ def avatar_url(self) -> str:
self._completeIfNotSet(self._avatar_url)
return self._avatar_url.value
@property
- def bio(self):
- """
- :type: string
- """
+ def bio(self) -> str:
self._completeIfNotSet(self._bio)
return self._bio.value
@property
- def blog(self):
- """
- :type: string
- """
+ def blog(self) -> str:
self._completeIfNotSet(self._blog)
return self._blog.value
@property
- def collaborators(self):
- """
- :type: integer
- """
+ def collaborators(self) -> int:
self._completeIfNotSet(self._collaborators)
return self._collaborators.value
@property
- def company(self):
- """
- :type: string
- """
+ def company(self) -> str:
self._completeIfNotSet(self._company)
return self._company.value
@property
- def created_at(self):
- """
- :type: datetime
- """
+ def created_at(self) -> datetime:
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
- def disk_usage(self):
- """
- :type: integer
- """
+ def disk_usage(self) -> int:
self._completeIfNotSet(self._disk_usage)
return self._disk_usage.value
@property
- def email(self):
- """
- :type: string
- """
+ def email(self) -> str:
self._completeIfNotSet(self._email)
return self._email.value
@property
- def events_url(self):
- """
- :type: string
- """
+ def events_url(self) -> str:
self._completeIfNotSet(self._events_url)
return self._events_url.value
@property
- def followers(self):
- """
- :type: integer
- """
+ def followers(self) -> int:
self._completeIfNotSet(self._followers)
return self._followers.value
@property
- def followers_url(self):
- """
- :type: string
- """
+ def followers_url(self) -> str:
self._completeIfNotSet(self._followers_url)
return self._followers_url.value
@property
- def following(self):
- """
- :type: integer
- """
+ def following(self) -> int:
self._completeIfNotSet(self._following)
return self._following.value
@property
- def following_url(self):
- """
- :type: string
- """
+ def following_url(self) -> str:
self._completeIfNotSet(self._following_url)
return self._following_url.value
@property
- def gists_url(self):
- """
- :type: string
- """
+ def gists_url(self) -> str:
self._completeIfNotSet(self._gists_url)
return self._gists_url.value
@property
- def gravatar_id(self):
- """
- :type: string
- """
+ def gravatar_id(self) -> str:
self._completeIfNotSet(self._gravatar_id)
return self._gravatar_id.value
@property
- def hireable(self):
- """
- :type: bool
- """
+ def hireable(self) -> bool:
self._completeIfNotSet(self._hireable)
return self._hireable.value
@property
- def html_url(self):
- """
- :type: string
- """
+ def html_url(self) -> str:
self._completeIfNotSet(self._html_url)
return self._html_url.value
@property
- def id(self):
- """
- :type: integer
- """
+ def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value
@property
- def location(self):
- """
- :type: string
- """
+ def location(self) -> str:
self._completeIfNotSet(self._location)
return self._location.value
@property
- def login(self):
- """
- :type: string
- """
+ def login(self) -> str:
self._completeIfNotSet(self._login)
return self._login.value
@property
- def name(self):
- """
- :type: string
- """
+ def name(self) -> str:
self._completeIfNotSet(self._name)
return self._name.value
@property
- def node_id(self):
- """
- :type: string
- """
+ def node_id(self) -> str:
self._completeIfNotSet(self._node_id)
return self._node_id.value
@property
- def organizations_url(self):
- """
- :type: string
- """
+ def organizations_url(self) -> str:
self._completeIfNotSet(self._organizations_url)
return self._organizations_url.value
@property
- def owned_private_repos(self):
- """
- :type: integer
- """
+ def owned_private_repos(self) -> int:
self._completeIfNotSet(self._owned_private_repos)
return self._owned_private_repos.value
@property
- def plan(self):
- """
- :type: :class:`github.Plan.Plan`
- """
+ def plan(self) -> Plan:
self._completeIfNotSet(self._plan)
return self._plan.value
@property
- def private_gists(self):
- """
- :type: integer
- """
+ def private_gists(self) -> int:
self._completeIfNotSet(self._private_gists)
return self._private_gists.value
@property
- def public_gists(self):
- """
- :type: integer
- """
+ def public_gists(self) -> int:
self._completeIfNotSet(self._public_gists)
return self._public_gists.value
@property
- def public_repos(self):
- """
- :type: integer
- """
+ def public_repos(self) -> int:
self._completeIfNotSet(self._public_repos)
return self._public_repos.value
@property
- def received_events_url(self):
- """
- :type: string
- """
+ def received_events_url(self) -> str:
self._completeIfNotSet(self._received_events_url)
return self._received_events_url.value
@property
- def repos_url(self):
- """
- :type: string
- """
+ def repos_url(self) -> str:
self._completeIfNotSet(self._repos_url)
return self._repos_url.value
@property
- def site_admin(self):
- """
- :type: bool
- """
+ def site_admin(self) -> bool:
self._completeIfNotSet(self._site_admin)
return self._site_admin.value
@property
- def starred_url(self):
- """
- :type: string
- """
+ def starred_url(self) -> str:
self._completeIfNotSet(self._starred_url)
return self._starred_url.value
@property
- def subscriptions_url(self):
- """
- :type: string
- """
+ def subscriptions_url(self) -> str:
self._completeIfNotSet(self._subscriptions_url)
return self._subscriptions_url.value
@property
- def total_private_repos(self):
- """
- :type: integer
- """
+ def total_private_repos(self) -> int:
self._completeIfNotSet(self._total_private_repos)
return self._total_private_repos.value
@property
- def type(self):
- """
- :type: string
- """
+ def type(self) -> str:
self._completeIfNotSet(self._type)
return self._type.value
@property
- def updated_at(self):
- """
- :type: datetime
- """
+ def updated_at(self) -> datetime:
self._completeIfNotSet(self._updated_at)
return self._updated_at.value
@property
- def url(self):
- """
- :type: string
- """
+ def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value
@property
- def two_factor_authentication(self):
- """
- :type: bool
- """
+ def two_factor_authentication(self) -> bool:
self._completeIfNotSet(self._two_factor_authentication)
return self._two_factor_authentication.value
- def add_to_emails(self, *emails):
+ def add_to_emails(self, *emails: str) -> None:
"""
:calls: `POST /user/emails `_
- :param email: string
- :rtype: None
"""
assert all(isinstance(element, str) for element in emails), emails
post_parameters = {"emails": emails}
headers, data = self._requester.requestJsonAndCheck("POST", "/user/emails", input=post_parameters)
- def add_to_following(self, following):
+ def add_to_following(self, following: NamedUser) -> None:
"""
:calls: `PUT /user/following/{user} `_
- :param following: :class:`github.NamedUser.NamedUser`
- :rtype: None
"""
assert isinstance(following, github.NamedUser.NamedUser), following
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/following/{following._identity}")
- def add_to_starred(self, starred):
+ def add_to_starred(self, starred: Repository) -> None:
"""
:calls: `PUT /user/starred/{owner}/{repo} `_
- :param starred: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(starred, github.Repository.Repository), starred
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/starred/{starred._identity}")
- def add_to_subscriptions(self, subscription):
+ def add_to_subscriptions(self, subscription: Repository) -> None:
"""
:calls: `PUT /user/subscriptions/{owner}/{repo} `_
- :param subscription: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(subscription, github.Repository.Repository), subscription
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/subscriptions/{subscription._identity}")
- def add_to_watched(self, watched):
+ def add_to_watched(self, watched: Repository) -> None:
"""
:calls: `PUT /repos/{owner}/{repo}/subscription `_
- :param watched: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(watched, github.Repository.Repository), watched
headers, data = self._requester.requestJsonAndCheck(
@@ -428,40 +380,32 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def create_authorization(
self,
- scopes=github.GithubObject.NotSet,
- note=github.GithubObject.NotSet,
- note_url=github.GithubObject.NotSet,
- client_id=github.GithubObject.NotSet,
- client_secret=github.GithubObject.NotSet,
- onetime_password=None,
- ):
+ scopes: Opt[list[str]] = NotSet,
+ note: Opt[str] = NotSet,
+ note_url: Opt[str] = NotSet,
+ client_id: Opt[str] = NotSet,
+ client_secret: Opt[str] = NotSet,
+ onetime_password: str | None = None,
+ ) -> Authorization:
"""
:calls: `POST /authorizations `_
- :param scopes: list of string
- :param note: string
- :param note_url: string
- :param client_id: string
- :param client_secret: string
- :param onetime_password: string
- :rtype: :class:`github.Authorization.Authorization`
"""
- assert scopes is github.GithubObject.NotSet or all(isinstance(element, str) for element in scopes), scopes
- assert note is github.GithubObject.NotSet or isinstance(note, str), note
- assert note_url is github.GithubObject.NotSet or isinstance(note_url, str), note_url
- assert client_id is github.GithubObject.NotSet or isinstance(client_id, str), client_id
- assert client_secret is github.GithubObject.NotSet or isinstance(client_secret, str), client_secret
+ assert is_optional_list(scopes, str), scopes
+ assert is_optional(note, str), note
+ assert is_optional(note_url, str), note_url
+ assert is_optional(client_id, str), client_id
+ assert is_optional(client_secret, str), client_secret
assert onetime_password is None or isinstance(onetime_password, str), onetime_password
- post_parameters = dict()
- if scopes is not github.GithubObject.NotSet:
- post_parameters["scopes"] = scopes
- if note is not github.GithubObject.NotSet:
- post_parameters["note"] = note
- if note_url is not github.GithubObject.NotSet:
- post_parameters["note_url"] = note_url
- if client_id is not github.GithubObject.NotSet:
- post_parameters["client_id"] = client_id
- if client_secret is not github.GithubObject.NotSet:
- post_parameters["client_secret"] = client_secret
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "scopes": scopes,
+ "note": note,
+ "note_url": note_url,
+ "client_id": client_id,
+ "client_secret": client_secret,
+ }
+ )
+
if onetime_password is not None:
request_header = {Consts.headerOTP: onetime_password} # pragma no cover (Should be covered)
else:
@@ -476,16 +420,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
@staticmethod
def create_fork(
- repo,
- name=github.GithubObject.NotSet,
- default_branch_only=github.GithubObject.NotSet,
- ):
+ repo: Repository,
+ name: Opt[str] = NotSet,
+ default_branch_only: Opt[bool] = NotSet,
+ ) -> Repository:
"""
:calls: `POST /repos/{owner}/{repo}/forks `_
- :param repo: :class:`github.Repository.Repository`
- :param name: string
- :param default_branch_only: bool
- :rtype: :class:`github.Repository.Repository`
"""
assert isinstance(repo, github.Repository.Repository), repo
return repo.create_fork(
@@ -496,31 +436,27 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def create_repo_from_template(
self,
- name,
- repo,
- description=github.GithubObject.NotSet,
- private=github.GithubObject.NotSet,
- ):
+ name: str,
+ repo: Repository,
+ description: Opt[str] = NotSet,
+ private: Opt[bool] = NotSet,
+ ) -> Repository:
"""
:calls: `POST /repos/{template_owner}/{template_repo}/generate `_
- :param name: string
- :param repo :class:`github.Repository.Repository`
- :param description: string
- :param private: bool
- :rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
assert isinstance(repo, github.Repository.Repository), repo
- assert description is github.GithubObject.NotSet or isinstance(description, str), description
- assert private is github.GithubObject.NotSet or isinstance(private, bool), private
- post_parameters = {
- "name": name,
- "owner": self.login,
- }
- if description is not github.GithubObject.NotSet:
- post_parameters["description"] = description
- if private is not github.GithubObject.NotSet:
- post_parameters["private"] = private
+ assert is_optional(description, str), description
+ assert is_optional(private, bool), private
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "name": name,
+ "owner": self.login,
+ "description": description,
+ "private": private,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"/repos/{repo.owner.login}/{repo.name}/generate",
@@ -529,27 +465,28 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
)
return github.Repository.Repository(self._requester, headers, data, completed=True)
- def create_gist(self, public, files, description=github.GithubObject.NotSet):
+ def create_gist(
+ self,
+ public: bool,
+ files: dict[str, InputFileContent],
+ description: Opt[str] = NotSet,
+ ) -> Gist:
"""
:calls: `POST /gists `_
- :param public: bool
- :param files: dict of string to :class:`github.InputFileContent.InputFileContent`
- :param description: string
- :rtype: :class:`github.Gist.Gist`
"""
assert isinstance(public, bool), public
assert all(isinstance(element, github.InputFileContent) for element in files.values()), files
- assert description is github.GithubObject.NotSet or isinstance(description, str), description
+ assert is_undefined(description) or isinstance(description, str), description
post_parameters = {
"public": public,
"files": {key: value._identity for key, value in files.items()},
}
- if description is not github.GithubObject.NotSet:
+ if is_defined(description):
post_parameters["description"] = description
headers, data = self._requester.requestJsonAndCheck("POST", "/gists", input=post_parameters)
return github.Gist.Gist(self._requester, headers, data, completed=True)
- def create_key(self, title, key):
+ def create_key(self, title: str, key: str) -> UserKey:
"""
:calls: `POST /user/keys `_
:param title: string
@@ -565,7 +502,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck("POST", "/user/keys", input=post_parameters)
return github.UserKey.UserKey(self._requester, headers, data, completed=True)
- def create_project(self, name, body=github.GithubObject.NotSet):
+ def create_project(self, name: str, body: Opt[str] = NotSet) -> Project:
"""
:calls: `POST /user/projects `_
:param name: string
@@ -573,7 +510,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Project.Project`
"""
assert isinstance(name, str), name
- assert body is github.GithubObject.NotSet or isinstance(body, str), body
+ assert is_undefined(body) or isinstance(body, str), body
post_parameters = {
"name": name,
"body": body,
@@ -588,314 +525,232 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def create_repo(
self,
- name,
- description=github.GithubObject.NotSet,
- homepage=github.GithubObject.NotSet,
- private=github.GithubObject.NotSet,
- has_issues=github.GithubObject.NotSet,
- has_wiki=github.GithubObject.NotSet,
- has_downloads=github.GithubObject.NotSet,
- has_projects=github.GithubObject.NotSet,
- auto_init=github.GithubObject.NotSet,
- license_template=github.GithubObject.NotSet,
- gitignore_template=github.GithubObject.NotSet,
- allow_squash_merge=github.GithubObject.NotSet,
- allow_merge_commit=github.GithubObject.NotSet,
- allow_rebase_merge=github.GithubObject.NotSet,
- delete_branch_on_merge=github.GithubObject.NotSet,
- ):
+ name: str,
+ description: Opt[str] = NotSet,
+ homepage: Opt[str] = NotSet,
+ private: Opt[bool] = NotSet,
+ has_issues: Opt[bool] = NotSet,
+ has_wiki: Opt[bool] = NotSet,
+ has_downloads: Opt[bool] = NotSet,
+ has_projects: Opt[bool] = NotSet,
+ auto_init: Opt[bool] = NotSet,
+ license_template: Opt[str] = NotSet,
+ gitignore_template: Opt[str] = NotSet,
+ allow_squash_merge: Opt[bool] = NotSet,
+ allow_merge_commit: Opt[bool] = NotSet,
+ allow_rebase_merge: Opt[bool] = NotSet,
+ delete_branch_on_merge: Opt[bool] = NotSet,
+ ) -> Repository:
"""
:calls: `POST /user/repos `_
- :param name: string
- :param description: string
- :param homepage: string
- :param private: bool
- :param has_issues: bool
- :param has_wiki: bool
- :param has_downloads: bool
- :param has_projects: bool
- :param auto_init: bool
- :param license_template: string
- :param gitignore_template: string
- :param allow_squash_merge: bool
- :param allow_merge_commit: bool
- :param allow_rebase_merge: bool
- :param delete_branch_on_merge: bool
- :rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
- assert description is github.GithubObject.NotSet or isinstance(description, str), description
- assert homepage is github.GithubObject.NotSet or isinstance(homepage, str), homepage
- assert private is github.GithubObject.NotSet or isinstance(private, bool), private
- assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues
- assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki
- assert has_downloads is github.GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads
- assert has_projects is github.GithubObject.NotSet or isinstance(has_projects, bool), has_projects
- assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init
- assert license_template is github.GithubObject.NotSet or isinstance(license_template, str), license_template
- assert gitignore_template is github.GithubObject.NotSet or isinstance(
- gitignore_template, str
- ), gitignore_template
- assert allow_squash_merge is github.GithubObject.NotSet or isinstance(
- allow_squash_merge, bool
- ), allow_squash_merge
- assert allow_merge_commit is github.GithubObject.NotSet or isinstance(
- allow_merge_commit, bool
- ), allow_merge_commit
- assert allow_rebase_merge is github.GithubObject.NotSet or isinstance(
- allow_rebase_merge, bool
- ), allow_rebase_merge
- assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance(
- delete_branch_on_merge, bool
- ), delete_branch_on_merge
- post_parameters = {
- "name": name,
- }
- if description is not github.GithubObject.NotSet:
- post_parameters["description"] = description
- if homepage is not github.GithubObject.NotSet:
- post_parameters["homepage"] = homepage
- if private is not github.GithubObject.NotSet:
- post_parameters["private"] = private
- if has_issues is not github.GithubObject.NotSet:
- post_parameters["has_issues"] = has_issues
- if has_wiki is not github.GithubObject.NotSet:
- post_parameters["has_wiki"] = has_wiki
- if has_downloads is not github.GithubObject.NotSet:
- post_parameters["has_downloads"] = has_downloads
- if has_projects is not github.GithubObject.NotSet:
- post_parameters["has_projects"] = has_projects
- if auto_init is not github.GithubObject.NotSet:
- post_parameters["auto_init"] = auto_init
- if license_template is not github.GithubObject.NotSet:
- post_parameters["license_template"] = license_template
- if gitignore_template is not github.GithubObject.NotSet:
- post_parameters["gitignore_template"] = gitignore_template
- if allow_squash_merge is not github.GithubObject.NotSet:
- post_parameters["allow_squash_merge"] = allow_squash_merge
- if allow_merge_commit is not github.GithubObject.NotSet:
- post_parameters["allow_merge_commit"] = allow_merge_commit
- if allow_rebase_merge is not github.GithubObject.NotSet:
- post_parameters["allow_rebase_merge"] = allow_rebase_merge
- if delete_branch_on_merge is not github.GithubObject.NotSet:
- post_parameters["delete_branch_on_merge"] = delete_branch_on_merge
+ assert is_optional(description, str), description
+ assert is_optional(homepage, str), homepage
+ assert is_optional(private, bool), private
+ assert is_optional(has_issues, bool), has_issues
+ assert is_optional(has_wiki, bool), has_wiki
+ assert is_optional(has_downloads, bool), has_downloads
+ assert is_optional(has_projects, bool), has_projects
+ assert is_optional(auto_init, bool), auto_init
+ assert is_optional(license_template, str), license_template
+ assert is_optional(gitignore_template, str), gitignore_template
+ assert is_optional(allow_squash_merge, bool), allow_squash_merge
+ assert is_optional(allow_merge_commit, bool), allow_merge_commit
+ assert is_optional(allow_rebase_merge, bool), allow_rebase_merge
+ assert is_optional(delete_branch_on_merge, bool), delete_branch_on_merge
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "name": name,
+ "description": description,
+ "homepage": homepage,
+ "private": private,
+ "has_issues": has_issues,
+ "has_wiki": has_wiki,
+ "has_downloads": has_downloads,
+ "has_projects": has_projects,
+ "auto_init": auto_init,
+ "license_template": license_template,
+ "gitignore_template": gitignore_template,
+ "allow_squash_merge": allow_squash_merge,
+ "allow_merge_commit": allow_merge_commit,
+ "allow_rebase_merge": allow_rebase_merge,
+ "delete_branch_on_merge": delete_branch_on_merge,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck("POST", "/user/repos", input=post_parameters)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def edit(
self,
- name=github.GithubObject.NotSet,
- email=github.GithubObject.NotSet,
- blog=github.GithubObject.NotSet,
- company=github.GithubObject.NotSet,
- location=github.GithubObject.NotSet,
- hireable=github.GithubObject.NotSet,
- bio=github.GithubObject.NotSet,
- ):
+ name: Opt[str] = NotSet,
+ email: Opt[str] = NotSet,
+ blog: Opt[str] = NotSet,
+ company: Opt[str] = NotSet,
+ location: Opt[str] = NotSet,
+ hireable: Opt[bool] = NotSet,
+ bio: Opt[str] = NotSet,
+ ) -> None:
"""
:calls: `PATCH /user `_
- :param name: string
- :param email: string
- :param blog: string
- :param company: string
- :param location: string
- :param hireable: bool
- :param bio: string
- :rtype: None
"""
- assert name is github.GithubObject.NotSet or isinstance(name, str), name
- assert email is github.GithubObject.NotSet or isinstance(email, str), email
- assert blog is github.GithubObject.NotSet or isinstance(blog, str), blog
- assert company is github.GithubObject.NotSet or isinstance(company, str), company
- assert location is github.GithubObject.NotSet or isinstance(location, str), location
- assert hireable is github.GithubObject.NotSet or isinstance(hireable, bool), hireable
- assert bio is github.GithubObject.NotSet or isinstance(bio, str), bio
- post_parameters = dict()
- if name is not github.GithubObject.NotSet:
- post_parameters["name"] = name
- if email is not github.GithubObject.NotSet:
- post_parameters["email"] = email
- if blog is not github.GithubObject.NotSet:
- post_parameters["blog"] = blog
- if company is not github.GithubObject.NotSet:
- post_parameters["company"] = company
- if location is not github.GithubObject.NotSet:
- post_parameters["location"] = location
- if hireable is not github.GithubObject.NotSet:
- post_parameters["hireable"] = hireable
- if bio is not github.GithubObject.NotSet:
- post_parameters["bio"] = bio
+ assert is_optional(name, str), name
+ assert is_optional(email, str), email
+ assert is_optional(blog, str), blog
+ assert is_optional(company, str), company
+ assert is_optional(location, str), location
+ assert is_optional(hireable, bool), hireable
+ assert is_optional(bio, str), bio
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "name": name,
+ "email": email,
+ "blog": blog,
+ "company": company,
+ "location": location,
+ "hireable": hireable,
+ "bio": bio,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck("PATCH", "/user", input=post_parameters)
self._useAttributes(data)
- def get_authorization(self, id):
+ def get_authorization(self, id: int) -> Authorization:
"""
:calls: `GET /authorizations/{id} `_
- :param id: integer
- :rtype: :class:`github.Authorization.Authorization`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck("GET", f"/authorizations/{id}")
return github.Authorization.Authorization(self._requester, headers, data, completed=True)
- def get_authorizations(self):
+ def get_authorizations(self) -> PaginatedList[Authorization]:
"""
:calls: `GET /authorizations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Authorization.Authorization`
"""
- return github.PaginatedList.PaginatedList(
- github.Authorization.Authorization, self._requester, "/authorizations", None
- )
+ return PaginatedList(github.Authorization.Authorization, self._requester, "/authorizations", None)
- def get_emails(self):
+ def get_emails(self) -> list[EmailData]:
"""
:calls: `GET /user/emails `_
- :rtype: list of namedtuples with members email, primary, verified and visibility
"""
headers, data = self._requester.requestJsonAndCheck("GET", "/user/emails")
- itemdata = namedtuple("EmailData", data[0].keys())
- return [itemdata._make(item.values()) for item in data]
+ return [EmailData(**item) for item in data]
- def get_events(self):
+ def get_events(self) -> PaginatedList[Event]:
"""
:calls: `GET /events `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
- return github.PaginatedList.PaginatedList(github.Event.Event, self._requester, "/events", None)
+ return PaginatedList(github.Event.Event, self._requester, "/events", None)
- def get_followers(self):
+ def get_followers(self) -> PaginatedList[NamedUser]:
"""
:calls: `GET /user/followers `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- return github.PaginatedList.PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/followers", None)
+ return PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/followers", None)
- def get_following(self):
+ def get_following(self) -> PaginatedList[NamedUser]:
"""
:calls: `GET /user/following `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- return github.PaginatedList.PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/following", None)
+ return PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/following", None)
- def get_gists(self, since=github.GithubObject.NotSet):
+ def get_gists(self, since: Opt[datetime] = NotSet) -> PaginatedList[Gist]:
"""
:calls: `GET /gists `_
:param since: datetime format YYYY-MM-DDTHH:MM:SSZ
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`
+ :rtype: :class:`PaginatedList` of :class:`github.Gist.Gist`
"""
- assert since is github.GithubObject.NotSet or isinstance(since, datetime), since
- url_parameters = dict()
- if since is not github.GithubObject.NotSet:
+ assert is_optional(since, datetime), since
+ url_parameters: dict[str, Any] = {}
+ if is_defined(since):
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
- return github.PaginatedList.PaginatedList(github.Gist.Gist, self._requester, "/gists", url_parameters)
+ return PaginatedList(github.Gist.Gist, self._requester, "/gists", url_parameters)
def get_issues(
self,
- filter=github.GithubObject.NotSet,
- state=github.GithubObject.NotSet,
- labels=github.GithubObject.NotSet,
- sort=github.GithubObject.NotSet,
- direction=github.GithubObject.NotSet,
- since=github.GithubObject.NotSet,
- ):
+ filter: Opt[str] = NotSet,
+ state: Opt[str] = NotSet,
+ labels: Opt[list[Label]] = NotSet,
+ sort: Opt[str] = NotSet,
+ direction: Opt[str] = NotSet,
+ since: Opt[datetime] = NotSet,
+ ) -> PaginatedList[Issue]:
"""
:calls: `GET /issues `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
- :param filter: string
- :param state: string
- :param labels: list of :class:`github.Label.Label`
- :param sort: string
- :param direction: string
- :param since: datetime
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
"""
- assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter
- assert state is github.GithubObject.NotSet or isinstance(state, str), state
- assert labels is github.GithubObject.NotSet or all(
- isinstance(element, github.Label.Label) for element in labels
- ), labels
- assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
- assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction
- assert since is github.GithubObject.NotSet or isinstance(since, datetime), since
- url_parameters = dict()
- if filter is not github.GithubObject.NotSet:
+ assert is_optional(filter, str), filter
+ assert is_optional(state, str), state
+ assert is_optional_list(labels, github.Label.Label), labels
+ assert is_optional(sort, str), sort
+ assert is_optional(direction, str), direction
+ assert is_optional(since, datetime), since
+ url_parameters: dict[str, Any] = {}
+ if is_defined(filter):
url_parameters["filter"] = filter
- if state is not github.GithubObject.NotSet:
+ if is_defined(state):
url_parameters["state"] = state
- if labels is not github.GithubObject.NotSet:
+ if is_defined(labels):
url_parameters["labels"] = ",".join(label.name for label in labels)
- if sort is not github.GithubObject.NotSet:
+ if is_defined(sort):
url_parameters["sort"] = sort
- if direction is not github.GithubObject.NotSet:
+ if is_defined(direction):
url_parameters["direction"] = direction
- if since is not github.GithubObject.NotSet:
+ if is_defined(since):
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
- return github.PaginatedList.PaginatedList(github.Issue.Issue, self._requester, "/issues", url_parameters)
+ return PaginatedList(github.Issue.Issue, self._requester, "/issues", url_parameters)
def get_user_issues(
self,
- filter=github.GithubObject.NotSet,
- state=github.GithubObject.NotSet,
- labels=github.GithubObject.NotSet,
- sort=github.GithubObject.NotSet,
- direction=github.GithubObject.NotSet,
- since=github.GithubObject.NotSet,
- ):
+ filter: Opt[str] = NotSet,
+ state: Opt[str] = NotSet,
+ labels: Opt[list[Label]] = NotSet,
+ sort: Opt[str] = NotSet,
+ direction: Opt[str] = NotSet,
+ since: Opt[datetime] = NotSet,
+ ) -> PaginatedList[Issue]:
"""
:calls: `GET /user/issues `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
- :param filter: string
- :param state: string
- :param labels: list of :class:`github.Label.Label`
- :param sort: string
- :param direction: string
- :param since: datetime
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
"""
- assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter
- assert state is github.GithubObject.NotSet or isinstance(state, str), state
- assert labels is github.GithubObject.NotSet or all(
- isinstance(element, github.Label.Label) for element in labels
- ), labels
- assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
- assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction
- assert since is github.GithubObject.NotSet or isinstance(since, datetime), since
- url_parameters = dict()
- if filter is not github.GithubObject.NotSet:
+ assert is_optional(filter, str), filter
+ assert is_optional(state, str), state
+ assert is_optional_list(labels, github.Label.Label), labels
+ assert is_optional(sort, str), sort
+ assert is_optional(direction, str), direction
+ assert is_optional(since, datetime), since
+ url_parameters: dict[str, Any] = {}
+ if is_defined(filter):
url_parameters["filter"] = filter
- if state is not github.GithubObject.NotSet:
+ if is_defined(state):
url_parameters["state"] = state
- if labels is not github.GithubObject.NotSet:
+ if is_defined(labels):
url_parameters["labels"] = ",".join(label.name for label in labels)
- if sort is not github.GithubObject.NotSet:
+ if is_defined(sort):
url_parameters["sort"] = sort
- if direction is not github.GithubObject.NotSet:
+ if is_defined(direction):
url_parameters["direction"] = direction
- if since is not github.GithubObject.NotSet:
+ if is_defined(since):
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
- return github.PaginatedList.PaginatedList(github.Issue.Issue, self._requester, "/user/issues", url_parameters)
+ return PaginatedList(github.Issue.Issue, self._requester, "/user/issues", url_parameters)
- def get_key(self, id):
+ def get_key(self, id: int) -> UserKey:
"""
:calls: `GET /user/keys/{id} `_
- :param id: integer
- :rtype: :class:`github.UserKey.UserKey`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck("GET", f"/user/keys/{id}")
return github.UserKey.UserKey(self._requester, headers, data, completed=True)
- def get_keys(self):
+ def get_keys(self) -> PaginatedList[UserKey]:
"""
:calls: `GET /user/keys `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey`
"""
- return github.PaginatedList.PaginatedList(github.UserKey.UserKey, self._requester, "/user/keys", None)
+ return PaginatedList(github.UserKey.UserKey, self._requester, "/user/keys", None)
- def get_notification(self, id):
+ def get_notification(self, id: str) -> Notification:
"""
:calls: `GET /notifications/threads/{id} `_
- :rtype: :class:`github.Notification.Notification`
"""
assert isinstance(id, str), id
@@ -904,67 +759,55 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def get_notifications(
self,
- all=github.GithubObject.NotSet,
- participating=github.GithubObject.NotSet,
- since=github.GithubObject.NotSet,
- before=github.GithubObject.NotSet,
- ):
+ all: Opt[bool] = NotSet,
+ participating: Opt[bool] = NotSet,
+ since: Opt[datetime] = NotSet,
+ before: Opt[datetime] = NotSet,
+ ) -> PaginatedList[Notification]:
"""
:calls: `GET /notifications `_
- :param all: bool
- :param participating: bool
- :param since: datetime
- :param before: datetime
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification`
"""
- assert all is github.GithubObject.NotSet or isinstance(all, bool), all
- assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating
- assert since is github.GithubObject.NotSet or isinstance(since, datetime), since
- assert before is github.GithubObject.NotSet or isinstance(before, datetime), before
+ assert is_optional(all, bool), all
+ assert is_optional(participating, bool), participating
+ assert is_optional(since, datetime), since
+ assert is_optional(before, datetime), before
- params = dict()
- if all is not github.GithubObject.NotSet:
+ params: dict[str, Any] = {}
+ if is_defined(all):
# convert True, False to true, false for api parameters
params["all"] = "true" if all else "false"
- if participating is not github.GithubObject.NotSet:
+ if is_defined(participating):
# convert True, False to true, false for api parameters
params["participating"] = "true" if participating else "false"
- if since is not github.GithubObject.NotSet:
+ if is_defined(since):
params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
- if before is not github.GithubObject.NotSet:
+ if is_defined(before):
params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ")
- return github.PaginatedList.PaginatedList(
- github.Notification.Notification, self._requester, "/notifications", params
- )
+ return PaginatedList(github.Notification.Notification, self._requester, "/notifications", params)
- def get_organization_events(self, org):
+ def get_organization_events(self, org: Organization) -> PaginatedList[Event]:
"""
:calls: `GET /users/{user}/events/orgs/{org} `_
- :param org: :class:`github.Organization.Organization`
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
assert isinstance(org, github.Organization.Organization), org
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Event.Event,
self._requester,
f"/users/{self.login}/events/orgs/{org.login}",
None,
)
- def get_orgs(self):
+ def get_orgs(self) -> PaginatedList[Organization]:
"""
:calls: `GET /user/orgs `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization`
"""
- return github.PaginatedList.PaginatedList(github.Organization.Organization, self._requester, "/user/orgs", None)
+ return PaginatedList(github.Organization.Organization, self._requester, "/user/orgs", None)
- def get_repo(self, name):
+ def get_repo(self, name: str) -> Repository:
"""
:calls: `GET /repos/{owner}/{repo} `_
- :param name: string
- :rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
headers, data = self._requester.requestJsonAndCheck("GET", f"/repos/{self.login}/{name}")
@@ -972,86 +815,66 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def get_repos(
self,
- visibility=github.GithubObject.NotSet,
- affiliation=github.GithubObject.NotSet,
- type=github.GithubObject.NotSet,
- sort=github.GithubObject.NotSet,
- direction=github.GithubObject.NotSet,
- ):
+ visibility: Opt[str] = NotSet,
+ affiliation: Opt[str] = NotSet,
+ type: Opt[str] = NotSet,
+ sort: Opt[str] = NotSet,
+ direction: Opt[str] = NotSet,
+ ) -> PaginatedList[Repository]:
"""
:calls: `GET /user/repos `_
- :param visibility: string
- :param affiliation: string
- :param type: string
- :param sort: string
- :param direction: string
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
- assert visibility is github.GithubObject.NotSet or isinstance(visibility, str), visibility
- assert affiliation is github.GithubObject.NotSet or isinstance(affiliation, str), affiliation
- assert type is github.GithubObject.NotSet or isinstance(type, str), type
- assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
- assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction
- url_parameters = dict()
- if visibility is not github.GithubObject.NotSet:
- url_parameters["visibility"] = visibility
- if affiliation is not github.GithubObject.NotSet:
- url_parameters["affiliation"] = affiliation
- if type is not github.GithubObject.NotSet:
- url_parameters["type"] = type
- if sort is not github.GithubObject.NotSet:
- url_parameters["sort"] = sort
- if direction is not github.GithubObject.NotSet:
- url_parameters["direction"] = direction
- return github.PaginatedList.PaginatedList(
- github.Repository.Repository, self._requester, "/user/repos", url_parameters
+ assert is_optional(visibility, str), visibility
+ assert is_optional(affiliation, str), affiliation
+ assert is_optional(type, str), type
+ assert is_optional(sort, str), sort
+ assert is_optional(direction, str), direction
+ url_parameters = NotSet.remove_unset_items(
+ {
+ "visibility": visibility,
+ "affiliation": affiliation,
+ "type": type,
+ "sort": sort,
+ "direction": direction,
+ }
)
+ return PaginatedList(github.Repository.Repository, self._requester, "/user/repos", url_parameters)
- def get_starred(self):
+ def get_starred(self) -> PaginatedList[Repository]:
"""
:calls: `GET /user/starred `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
- return github.PaginatedList.PaginatedList(github.Repository.Repository, self._requester, "/user/starred", None)
+ return PaginatedList(github.Repository.Repository, self._requester, "/user/starred", None)
- def get_starred_gists(self):
+ def get_starred_gists(self) -> PaginatedList[Gist]:
"""
:calls: `GET /gists/starred `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`
"""
- return github.PaginatedList.PaginatedList(github.Gist.Gist, self._requester, "/gists/starred", None)
+ return PaginatedList(github.Gist.Gist, self._requester, "/gists/starred", None)
- def get_subscriptions(self):
+ def get_subscriptions(self) -> PaginatedList[Repository]:
"""
:calls: `GET /user/subscriptions `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
- return github.PaginatedList.PaginatedList(
- github.Repository.Repository, self._requester, "/user/subscriptions", None
- )
+ return PaginatedList(github.Repository.Repository, self._requester, "/user/subscriptions", None)
- def get_teams(self):
+ def get_teams(self) -> PaginatedList[Team]:
"""
:calls: `GET /user/teams `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
- return github.PaginatedList.PaginatedList(github.Team.Team, self._requester, "/user/teams", None)
+ return PaginatedList(github.Team.Team, self._requester, "/user/teams", None)
- def get_watched(self):
+ def get_watched(self) -> PaginatedList[Repository]:
"""
:calls: `GET /user/subscriptions `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
- return github.PaginatedList.PaginatedList(
- github.Repository.Repository, self._requester, "/user/subscriptions", None
- )
+ return PaginatedList(github.Repository.Repository, self._requester, "/user/subscriptions", None)
- def get_installations(self):
+ def get_installations(self) -> PaginatedList[Installation]:
"""
:calls: `GET /user/installations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Installation.Installation`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Installation.Installation,
self._requester,
"/user/installations",
@@ -1060,107 +883,88 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
list_item="installations",
)
- def has_in_following(self, following):
+ def has_in_following(self, following: NamedUser) -> bool:
"""
:calls: `GET /user/following/{user} `_
- :param following: :class:`github.NamedUser.NamedUser`
- :rtype: bool
"""
assert isinstance(following, github.NamedUser.NamedUser), following
status, headers, data = self._requester.requestJson("GET", f"/user/following/{following._identity}")
return status == 204
- def has_in_starred(self, starred):
+ def has_in_starred(self, starred: Repository) -> bool:
"""
:calls: `GET /user/starred/{owner}/{repo} `_
- :param starred: :class:`github.Repository.Repository`
- :rtype: bool
"""
assert isinstance(starred, github.Repository.Repository), starred
status, headers, data = self._requester.requestJson("GET", f"/user/starred/{starred._identity}")
return status == 204
- def has_in_subscriptions(self, subscription):
+ def has_in_subscriptions(self, subscription: Repository) -> bool:
"""
:calls: `GET /user/subscriptions/{owner}/{repo} `_
- :param subscription: :class:`github.Repository.Repository`
- :rtype: bool
"""
assert isinstance(subscription, github.Repository.Repository), subscription
status, headers, data = self._requester.requestJson("GET", f"/user/subscriptions/{subscription._identity}")
return status == 204
- def has_in_watched(self, watched):
+ def has_in_watched(self, watched: Repository) -> bool:
"""
:calls: `GET /repos/{owner}/{repo}/subscription `_
- :param watched: :class:`github.Repository.Repository`
- :rtype: bool
"""
assert isinstance(watched, github.Repository.Repository), watched
status, headers, data = self._requester.requestJson("GET", f"/repos/{watched._identity}/subscription")
return status == 200
- def mark_notifications_as_read(self, last_read_at=datetime.now(timezone.utc)):
+ def mark_notifications_as_read(self, last_read_at: datetime | None = None) -> None:
"""
:calls: `PUT /notifications `_
- :param last_read_at: datetime
"""
+ if last_read_at is None:
+ last_read_at = datetime.now(timezone.utc)
assert isinstance(last_read_at, datetime)
put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")}
headers, data = self._requester.requestJsonAndCheck("PUT", "/notifications", input=put_parameters)
- def remove_from_emails(self, *emails):
+ def remove_from_emails(self, *emails: str) -> None:
"""
:calls: `DELETE /user/emails `_
- :param email: string
- :rtype: None
"""
assert all(isinstance(element, str) for element in emails), emails
post_parameters = {"emails": emails}
headers, data = self._requester.requestJsonAndCheck("DELETE", "/user/emails", input=post_parameters)
- def remove_from_following(self, following):
+ def remove_from_following(self, following: NamedUser) -> None:
"""
:calls: `DELETE /user/following/{user} `_
- :param following: :class:`github.NamedUser.NamedUser`
- :rtype: None
"""
assert isinstance(following, github.NamedUser.NamedUser), following
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/following/{following._identity}")
- def remove_from_starred(self, starred):
+ def remove_from_starred(self, starred: Repository) -> None:
"""
:calls: `DELETE /user/starred/{owner}/{repo} `_
- :param starred: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(starred, github.Repository.Repository), starred
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/starred/{starred._identity}")
- def remove_from_subscriptions(self, subscription):
+ def remove_from_subscriptions(self, subscription: Repository) -> None:
"""
:calls: `DELETE /user/subscriptions/{owner}/{repo} `_
- :param subscription: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(subscription, github.Repository.Repository), subscription
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/subscriptions/{subscription._identity}")
- def remove_from_watched(self, watched):
+ def remove_from_watched(self, watched: Repository) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/subscription `_
- :param watched: :class:`github.Repository.Repository`
- :rtype: None
"""
assert isinstance(watched, github.Repository.Repository), watched
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/repos/{watched._identity}/subscription")
- def accept_invitation(self, invitation):
+ def accept_invitation(self, invitation: Invitation | int) -> None:
"""
:calls: `PATCH /user/repository_invitations/{invitation_id} `_
- :param invitation: :class:`github.Invitation.Invitation` or int
- :rtype: None
"""
assert isinstance(invitation, github.Invitation.Invitation) or isinstance(invitation, int)
@@ -1171,12 +975,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"PATCH", f"/user/repository_invitations/{invitation}", input={}
)
- def get_invitations(self):
+ def get_invitations(self) -> PaginatedList[Invitation]:
"""
:calls: `GET /user/repository_invitations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Invitation.Invitation,
self._requester,
"/user/repository_invitations",
@@ -1185,28 +988,25 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
def create_migration(
self,
- repos,
- lock_repositories=github.GithubObject.NotSet,
- exclude_attachments=github.GithubObject.NotSet,
- ):
+ repos: list[Repository] | tuple[Repository],
+ lock_repositories: Opt[bool] = NotSet,
+ exclude_attachments: Opt[bool] = NotSet,
+ ) -> Migration:
"""
:calls: `POST /user/migrations `_
- :param repos: list or tuple of str
- :param lock_repositories: bool
- :param exclude_attachments: bool
- :rtype: :class:`github.Migration.Migration`
"""
assert isinstance(repos, (list, tuple)), repos
assert all(isinstance(repo, str) for repo in repos), repos
- assert lock_repositories is github.GithubObject.NotSet or isinstance(lock_repositories, bool), lock_repositories
- assert exclude_attachments is github.GithubObject.NotSet or isinstance(
- exclude_attachments, bool
- ), exclude_attachments
- post_parameters = {"repositories": repos}
- if lock_repositories is not github.GithubObject.NotSet:
- post_parameters["lock_repositories"] = lock_repositories
- if exclude_attachments is not github.GithubObject.NotSet:
- post_parameters["exclude_attachments"] = exclude_attachments
+ assert is_optional(lock_repositories, bool), lock_repositories
+ assert is_optional(exclude_attachments, bool), exclude_attachments
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "repositories": repos,
+ "lock_repositories": lock_repositories,
+ "exclude_attachments": exclude_attachments,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
"/user/migrations",
@@ -1215,12 +1015,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
)
return github.Migration.Migration(self._requester, headers, data, completed=True)
- def get_migrations(self):
+ def get_migrations(self) -> PaginatedList[Migration]:
"""
:calls: `GET /user/migrations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Migration.Migration`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Migration.Migration,
self._requester,
"/user/migrations",
@@ -1228,56 +1027,15 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
- def get_organization_membership(self, org):
+ def get_organization_membership(self, org: str) -> Membership:
"""
:calls: `GET /user/memberships/orgs/{org} `_
- :rtype: :class:`github.Membership.Membership`
"""
assert isinstance(org, str)
headers, data = self._requester.requestJsonAndCheck("GET", f"/user/memberships/orgs/{org}")
return github.Membership.Membership(self._requester, headers, data, completed=True)
- def _initAttributes(self) -> None:
- self._avatar_url = github.GithubObject.NotSet
- self._bio = github.GithubObject.NotSet
- self._blog = github.GithubObject.NotSet
- self._collaborators = github.GithubObject.NotSet
- self._company = github.GithubObject.NotSet
- self._created_at = github.GithubObject.NotSet
- self._disk_usage = github.GithubObject.NotSet
- self._email = github.GithubObject.NotSet
- self._events_url = github.GithubObject.NotSet
- self._followers = github.GithubObject.NotSet
- self._followers_url = github.GithubObject.NotSet
- self._following = github.GithubObject.NotSet
- self._following_url = github.GithubObject.NotSet
- self._gists_url = github.GithubObject.NotSet
- self._gravatar_id = github.GithubObject.NotSet
- self._hireable = github.GithubObject.NotSet
- self._html_url = github.GithubObject.NotSet
- self._id = github.GithubObject.NotSet
- self._location = github.GithubObject.NotSet
- self._login = github.GithubObject.NotSet
- self._name = github.GithubObject.NotSet
- self._node_id = github.GithubObject.NotSet
- self._organizations_url = github.GithubObject.NotSet
- self._owned_private_repos = github.GithubObject.NotSet
- self._plan = github.GithubObject.NotSet
- self._private_gists = github.GithubObject.NotSet
- self._public_gists = github.GithubObject.NotSet
- self._public_repos = github.GithubObject.NotSet
- self._received_events_url = github.GithubObject.NotSet
- self._repos_url = github.GithubObject.NotSet
- self._site_admin = github.GithubObject.NotSet
- self._starred_url = github.GithubObject.NotSet
- self._subscriptions_url = github.GithubObject.NotSet
- self._total_private_repos = github.GithubObject.NotSet
- self._type = github.GithubObject.NotSet
- self._updated_at = github.GithubObject.NotSet
- self._url = github.GithubObject.NotSet
- self._two_factor_authentication = github.GithubObject.NotSet
-
- def _useAttributes(self, attributes: Dict[str, Any]) -> None:
+ def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "avatar_url" in attributes: # pragma no branch
self._avatar_url = self._makeStringAttribute(attributes["avatar_url"])
if "bio" in attributes: # pragma no branch
diff --git a/github/AuthenticatedUser.pyi b/github/AuthenticatedUser.pyi
deleted file mode 100644
index c4355a94..00000000
--- a/github/AuthenticatedUser.pyi
+++ /dev/null
@@ -1,233 +0,0 @@
-from datetime import datetime
-from typing import Any, Dict, List, Optional, Union, NamedTuple
-
-from github.Authorization import Authorization
-from github.Event import Event
-from github.Gist import Gist
-from github.GithubObject import CompletableGithubObject, _NotSetType
-from github.InputFileContent import InputFileContent
-from github.Invitation import Invitation
-from github.Issue import Issue
-from github.Label import Label
-from github.Membership import Membership
-from github.Migration import Migration
-from github.NamedUser import NamedUser
-from github.Notification import Notification
-from github.Organization import Organization
-from github.PaginatedList import PaginatedList
-from github.Plan import Plan
-from github.Repository import Repository
-from github.Team import Team
-from github.UserKey import UserKey
-
-class EmailData(NamedTuple):
- email: str
- primary: bool
- verified: bool
- visibility: str
-
-class AuthenticatedUser(CompletableGithubObject):
- def __repr__(self) -> str: ...
- def _initAttributes(self) -> None: ...
- def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
- def accept_invitation(self, invitation: Union[int, Invitation]) -> None: ...
- def add_to_emails(self, *emails: List[str]) -> None: ...
- def add_to_following(self, following: NamedUser) -> None: ...
- def add_to_starred(self, starred: Repository) -> None: ...
- def add_to_subscriptions(self, subscription: Repository) -> None: ...
- def add_to_watched(self, watched: Repository) -> None: ...
- @property
- def avatar_url(self) -> str: ...
- @property
- def bio(self) -> str: ...
- @property
- def blog(self) -> str: ...
- @property
- def collaborators(self) -> int: ...
- @property
- def company(self) -> str: ...
- def create_authorization(
- self,
- scopes: Union[List[str], _NotSetType] = ...,
- note: Union[str, _NotSetType] = ...,
- note_url: Union[str, _NotSetType] = ...,
- client_id: Union[str, _NotSetType] = ...,
- client_secret: Union[str, _NotSetType] = ...,
- onetime_password: Union[str, None] = ...,
- ) -> Authorization: ...
- @staticmethod
- def create_fork(
- repo: Repository,
- name: Union[str, _NotSetType] = ...,
- default_branch_only: Union[str, _NotSetType] = ...,
- ) -> Repository: ...
- def create_gist(
- self,
- public: bool,
- files: Dict[str, InputFileContent],
- description: Union[str, _NotSetType] = ...,
- ) -> Gist: ...
- def create_key(self, title: str, key: str) -> UserKey: ...
- def create_migration(
- self,
- repos: List[str],
- lock_repositories: Union[bool, _NotSetType] = ...,
- exclude_attachments: Union[bool, _NotSetType] = ...,
- ) -> Migration: ...
- def create_repo(
- self,
- name: str,
- description: Union[str, _NotSetType] = ...,
- homepage: Union[str, _NotSetType] = ...,
- private: Union[bool, _NotSetType] = ...,
- has_issues: Union[bool, _NotSetType] = ...,
- has_wiki: Union[bool, _NotSetType] = ...,
- has_downloads: Union[bool, _NotSetType] = ...,
- has_projects: Union[bool, _NotSetType] = ...,
- auto_init: Union[bool, _NotSetType] = ...,
- license_template: _NotSetType = ...,
- gitignore_template: Union[str, _NotSetType] = ...,
- allow_squash_merge: Union[bool, _NotSetType] = ...,
- allow_merge_commit: Union[bool, _NotSetType] = ...,
- allow_rebase_merge: Union[bool, _NotSetType] = ...,
- ) -> Repository: ...
- @property
- def created_at(self) -> datetime: ...
- @property
- def disk_usage(self) -> int: ...
- def edit(
- self,
- name: Union[str, _NotSetType] = ...,
- email: Union[str, _NotSetType] = ...,
- blog: Union[str, _NotSetType] = ...,
- company: Union[str, _NotSetType] = ...,
- location: Union[str, _NotSetType] = ...,
- hireable: Union[bool, _NotSetType] = ...,
- bio: Union[str, _NotSetType] = ...,
- ) -> None: ...
- @property
- def email(self) -> str: ...
- @property
- def events_url(self) -> str: ...
- @property
- def followers(self) -> int: ...
- @property
- def followers_url(self) -> str: ...
- @property
- def following(self) -> int: ...
- @property
- def following_url(self) -> str: ...
- def get_authorization(self, id: int) -> Authorization: ...
- def get_authorizations(self) -> PaginatedList[Authorization]: ...
- def get_emails(self) -> List[EmailData]: ...
- def get_events(self) -> PaginatedList[Event]: ...
- def get_followers(self) -> PaginatedList[NamedUser]: ...
- def get_following(self) -> PaginatedList[NamedUser]: ...
- def get_gists(self, since: Union[datetime, _NotSetType] = ...) -> PaginatedList[Gist]: ...
- def get_invitations(self) -> PaginatedList[Invitation]: ...
- def get_issues(
- self,
- filter: Union[str, _NotSetType] = ...,
- state: Union[str, _NotSetType] = ...,
- labels: Union[List[Label], _NotSetType] = ...,
- sort: Union[str, _NotSetType] = ...,
- direction: Union[str, _NotSetType] = ...,
- since: Union[_NotSetType, datetime] = ...,
- ) -> PaginatedList[Issue]: ...
- def get_key(self, id: int) -> UserKey: ...
- def get_keys(self) -> PaginatedList[UserKey]: ...
- def get_migrations(self) -> PaginatedList[Migration]: ...
- def get_notification(self, id: str) -> Notification: ...
- def get_notifications(
- self,
- all: Union[bool, _NotSetType] = ...,
- participating: Union[bool, _NotSetType] = ...,
- since: Union[datetime, _NotSetType] = ...,
- before: Union[datetime, _NotSetType] = ...,
- ) -> PaginatedList[Notification]: ...
- def get_organization_events(self, org: Organization) -> PaginatedList[Event]: ...
- def get_organization_membership(self, org: int) -> Membership: ...
- def get_orgs(self) -> PaginatedList[Organization]: ...
- def get_repo(self, name: str) -> Repository: ...
- def get_repos(
- self,
- visibility: Union[str, _NotSetType] = ...,
- affiliation: Union[str, _NotSetType] = ...,
- type: Union[str, _NotSetType] = ...,
- sort: Union[str, _NotSetType] = ...,
- direction: Union[str, _NotSetType] = ...,
- ) -> PaginatedList[Repository]: ...
- def get_starred(self) -> PaginatedList[Repository]: ...
- def get_starred_gists(self) -> PaginatedList[Gist]: ...
- def get_subscriptions(self) -> PaginatedList[Repository]: ...
- def get_teams(self) -> PaginatedList[Team]: ...
- def get_user_issues(
- self,
- filter: Union[str, _NotSetType] = ...,
- state: Union[str, _NotSetType] = ...,
- labels: Union[List[Label], _NotSetType] = ...,
- sort: Union[str, _NotSetType] = ...,
- direction: Union[str, _NotSetType] = ...,
- since: Union[_NotSetType, datetime] = ...,
- ) -> PaginatedList[Issue]: ...
- def get_watched(self) -> PaginatedList[Repository]: ...
- @property
- def gists_url(self) -> str: ...
- @property
- def gravatar_id(self) -> str: ...
- def has_in_following(self, following: NamedUser) -> bool: ...
- def has_in_starred(self, starred: Repository) -> bool: ...
- def has_in_subscriptions(self, subscription: Repository) -> bool: ...
- def has_in_watched(self, watched: Repository) -> bool: ...
- @property
- def hireable(self) -> bool: ...
- @property
- def html_url(self) -> str: ...
- @property
- def id(self) -> int: ...
- @property
- def location(self) -> str: ...
- @property
- def login(self) -> str: ...
- def mark_notifications_as_read(self, last_read_at: datetime = ...) -> None: ...
- @property
- def name(self) -> str: ...
- @property
- def node_id(self) -> str: ...
- @property
- def organizations_url(self) -> str: ...
- @property
- def owned_private_repos(self) -> int: ...
- @property
- def plan(self) -> Plan: ...
- @property
- def private_gists(self) -> int: ...
- @property
- def public_gists(self) -> int: ...
- @property
- def public_repos(self) -> int: ...
- @property
- def received_events_url(self) -> str: ...
- def remove_from_emails(self, *emails: str) -> None: ...
- def remove_from_following(self, following: NamedUser) -> None: ...
- def remove_from_starred(self, starred: Repository) -> None: ...
- def remove_from_subscriptions(self, subscription: Repository) -> None: ...
- def remove_from_watched(self, watched: Repository) -> None: ...
- @property
- def repos_url(self) -> str: ...
- @property
- def site_admin(self) -> bool: ...
- @property
- def starred_url(self) -> str: ...
- @property
- def subscriptions_url(self) -> str: ...
- @property
- def total_private_repos(self) -> int: ...
- @property
- def type(self) -> str: ...
- @property
- def updated_at(self) -> datetime: ...
- @property
- def url(self) -> str: ...
- @property
- def two_factor_authentication(self) -> bool: ...
diff --git a/github/Repository.pyi b/github/Repository.pyi
index 4598b5cc..7701c266 100644
--- a/github/Repository.pyi
+++ b/github/Repository.pyi
@@ -399,7 +399,7 @@ class Repository(CompletableGithubObject):
self,
organization: Union[Organization, str, _NotSetType] = ...,
name: Union[str, _NotSetType] = ...,
- default_branch_only: Union[str, _NotSetType] = ...,
+ default_branch_only: Union[bool, _NotSetType] = ...,
) -> Repository: ...
def get_git_blob(self, sha: str) -> GitBlob: ...
def get_git_commit(self, sha: str) -> GitCommit: ...