diff --git a/github/Organization.py b/github/Organization.py
index 2f84f415..a8d8b5e0 100644
--- a/github/Organization.py
+++ b/github/Organization.py
@@ -39,351 +39,297 @@
# along with PyGithub. If not, see . #
# #
################################################################################
-
from __future__ import annotations
from datetime import datetime
-from typing import Any
+from typing import TYPE_CHECKING, Any
import github.Event
import github.GithubObject
+import github.HookDelivery
import github.NamedUser
import github.OrganizationSecret
import github.OrganizationVariable
-import github.PaginatedList
import github.Plan
import github.Project
import github.Repository
import github.Team
+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.Event import Event
+ from github.Hook import Hook
+ from github.Installation import Installation
+ from github.Issue import Issue
+ from github.Label import Label
+ from github.Migration import Migration
+ from github.NamedUser import NamedUser
+ from github.OrganizationSecret import OrganizationSecret
+ from github.OrganizationVariable import OrganizationVariable
+ from github.Plan import Plan
+ from github.Project import Project
+ from github.PublicKey import PublicKey
+ from github.Repository import Repository
+ from github.Team import Team
-class Organization(github.GithubObject.CompletableGithubObject):
+class Organization(CompletableGithubObject):
"""
This class represents Organizations. The reference can be found here https://docs.github.com/en/rest/reference/orgs
"""
+ def _initAttributes(self) -> None:
+ self._default_repository_permission: Attribute[str] = NotSet
+ self._has_organization_projects: Attribute[bool] = NotSet
+ self._has_repository_projects: Attribute[bool] = NotSet
+ self._hooks_url: Attribute[str] = NotSet
+ self._issues_url: Attribute[str] = NotSet
+ self._members_can_create_repositories: Attribute[bool] = NotSet
+ self._two_factor_requirement_enabled: Attribute[bool] = NotSet
+ self._avatar_url: Attribute[str] = NotSet
+ self._billing_email: Attribute[str] = NotSet
+ self._blog: Attribute[str | None] = NotSet
+ self._collaborators: Attribute[int] = NotSet
+ self._company: Attribute[str] = NotSet
+ self._created_at: Attribute[datetime] = NotSet
+ self._description: Attribute[str] = NotSet
+ self._disk_usage: Attribute[int] = NotSet
+ self._email: Attribute[str] = NotSet
+ self._events_url: Attribute[str] = NotSet
+ self._followers: Attribute[int] = NotSet
+ self._following: Attribute[int] = NotSet
+ self._gravatar_id: Attribute[str] = NotSet
+ self._html_url: Attribute[str] = NotSet
+ self._id: Attribute[int] = NotSet
+ self._location: Attribute[str] = NotSet
+ self._login: Attribute[str] = NotSet
+ self._members_url: Attribute[str] = NotSet
+ self._name: Attribute[str] = NotSet
+ self._owned_private_repos: Attribute[int] = NotSet
+ self._plan: Attribute[Plan] = NotSet
+ self._private_gists: Attribute[int] = NotSet
+ self._public_gists: Attribute[int] = NotSet
+ self._public_members_url: Attribute[str] = NotSet
+ self._public_repos: Attribute[int] = NotSet
+ self._repos_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
+
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 billing_email(self):
- """
- :type: string
- """
+ def billing_email(self) -> str:
self._completeIfNotSet(self._billing_email)
return self._billing_email.value
@property
- def blog(self):
- """
- :type: string
- """
+ def blog(self) -> str | None:
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 | None:
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 default_repository_permission(self):
- """
- :type: string
- """
+ def default_repository_permission(self) -> str:
self._completeIfNotSet(self._default_repository_permission)
return self._default_repository_permission.value
@property
- def description(self):
- """
- :type: string
- """
+ def description(self) -> str:
self._completeIfNotSet(self._description)
return self._description.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 | None:
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 following(self):
- """
- :type: integer
- """
+ def following(self) -> int:
self._completeIfNotSet(self._following)
return self._following.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 has_organization_projects(self):
- """
- :type: bool
- """
+ def has_organization_projects(self) -> bool:
self._completeIfNotSet(self._has_organization_projects)
return self._has_organization_projects.value
@property
- def has_repository_projects(self):
- """
- :type: bool
- """
+ def has_repository_projects(self) -> bool:
self._completeIfNotSet(self._has_repository_projects)
return self._has_repository_projects.value
@property
- def hooks_url(self):
- """
- :type: string
- """
+ def hooks_url(self) -> str:
self._completeIfNotSet(self._hooks_url)
return self._hooks_url.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 issues_url(self):
- """
- :type: string
- """
+ def issues_url(self) -> str:
self._completeIfNotSet(self._issues_url)
return self._issues_url.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 members_can_create_repositories(self):
- """
- :type: bool
- """
+ def members_can_create_repositories(self) -> bool:
self._completeIfNotSet(self._members_can_create_repositories)
return self._members_can_create_repositories.value
@property
- def members_url(self):
- """
- :type: string
- """
+ def members_url(self) -> str:
self._completeIfNotSet(self._members_url)
return self._members_url.value
@property
- def name(self):
- """
- :type: string
- """
+ def name(self) -> str | None:
self._completeIfNotSet(self._name)
return self._name.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_members_url(self):
- """
- :type: string
- """
+ def public_members_url(self) -> str:
self._completeIfNotSet(self._public_members_url)
return self._public_members_url.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 repos_url(self):
- """
- :type: string
- """
+ def repos_url(self) -> str:
self._completeIfNotSet(self._repos_url)
return self._repos_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 two_factor_requirement_enabled(self):
- """
- :type: bool
- """
+ def two_factor_requirement_enabled(self) -> bool:
self._completeIfNotSet(self._two_factor_requirement_enabled)
return self._two_factor_requirement_enabled.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
- def add_to_members(self, member, role=github.GithubObject.NotSet):
+ def add_to_members(self, member: NamedUser, role: Opt[str] = NotSet) -> None:
"""
:calls: `PUT /orgs/{org}/memberships/{user} `_
- :param member: :class:`github.NamedUser.NamedUser`
- :param role: string
- :rtype: None
"""
- assert role is github.GithubObject.NotSet or isinstance(role, str), role
+ assert is_optional(role, str), role
assert isinstance(member, github.NamedUser.NamedUser), member
- put_parameters = {}
- if role is not github.GithubObject.NotSet:
- put_parameters["role"] = role
+ put_parameters = NotSet.remove_unset_items({"role": role})
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/memberships/{member._identity}", input=put_parameters
)
- def add_to_public_members(self, public_member):
+ def add_to_public_members(self, public_member: NamedUser) -> None:
"""
:calls: `PUT /orgs/{org}/public_members/{user} `_
- :param public_member: :class:`github.NamedUser.NamedUser`
- :rtype: None
"""
assert isinstance(public_member, github.NamedUser.NamedUser), public_member
headers, data = self._requester.requestJsonAndCheck(
@@ -392,16 +338,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_fork(
self,
- 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(
@@ -412,31 +354,22 @@ class Organization(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:
"""self.name
: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",
@@ -447,11 +380,11 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_hook(
self,
- name,
- config,
- events=github.GithubObject.NotSet,
- active=github.GithubObject.NotSet,
- ):
+ name: str,
+ config: dict[str, str],
+ events: Opt[list[str]] = NotSet,
+ active: Opt[bool] = NotSet,
+ ) -> Hook:
"""
:calls: `POST /orgs/{owner}/hooks `_
:param name: string
@@ -462,31 +395,27 @@ class Organization(github.GithubObject.CompletableGithubObject):
"""
assert isinstance(name, str), name
assert isinstance(config, dict), config
- assert events is github.GithubObject.NotSet or all(isinstance(element, str) for element in events), events
- assert active is github.GithubObject.NotSet or isinstance(active, bool), active
- post_parameters = {
- "name": name,
- "config": config,
- }
- if events is not github.GithubObject.NotSet:
- post_parameters["events"] = events
- if active is not github.GithubObject.NotSet:
- post_parameters["active"] = active
+ assert is_optional_list(events, str), events
+ assert is_optional(active, bool), active
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {
+ "name": name,
+ "config": config,
+ "events": events,
+ "active": active,
+ }
+ )
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/hooks", input=post_parameters)
return github.Hook.Hook(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) -> github.Project.Project:
"""
:calls: `POST /orgs/{org}/projects `_
- :param name: string
- :param body: string
- :rtype: :class:`github.Project.Project`
"""
assert isinstance(name, str), name
- assert body is github.GithubObject.NotSet or isinstance(body, str), body
- post_parameters = {"name": name}
- if body is not github.GithubObject.NotSet:
- post_parameters["body"] = body
+ assert is_optional(body, str), body
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items({"name": name, "body": body})
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/projects",
@@ -497,113 +426,69 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_repo(
self,
- name,
- description=github.GithubObject.NotSet,
- homepage=github.GithubObject.NotSet,
- private=github.GithubObject.NotSet,
- visibility=github.GithubObject.NotSet,
- has_issues=github.GithubObject.NotSet,
- has_wiki=github.GithubObject.NotSet,
- has_downloads=github.GithubObject.NotSet,
- has_projects=github.GithubObject.NotSet,
- team_id=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,
- allow_update_branch=github.GithubObject.NotSet,
- ):
+ name: str,
+ description: Opt[str] = NotSet,
+ homepage: Opt[str] = NotSet,
+ private: Opt[bool] = NotSet,
+ visibility: Opt[str] = NotSet,
+ has_issues: Opt[bool] = NotSet,
+ has_wiki: Opt[bool] = NotSet,
+ has_downloads: Opt[bool] = NotSet,
+ has_projects: Opt[bool] = NotSet,
+ team_id: Opt[int] = 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,
+ allow_update_branch: Opt[bool] = NotSet,
+ ) -> github.Repository.Repository:
"""
:calls: `POST /orgs/{org}/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 team_id: : int
- :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
- :param allow_update_branch: 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 visibility is github.GithubObject.NotSet or isinstance(visibility, str), visibility
- 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 team_id is github.GithubObject.NotSet or isinstance(team_id, int), team_id
- 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
- assert allow_update_branch is github.GithubObject.NotSet or isinstance(
- allow_update_branch, bool
- ), allow_update_branch
- 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 visibility is not github.GithubObject.NotSet:
- post_parameters["visibility"] = visibility
- 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 team_id is not github.GithubObject.NotSet:
- post_parameters["team_id"] = team_id
- 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
- if allow_update_branch is not github.GithubObject.NotSet:
- post_parameters["allow_update_branch"] = allow_update_branch
+ assert is_optional(description, str), description
+ assert is_optional(homepage, str), homepage
+ assert is_optional(private, bool), private
+ assert is_optional(visibility, str), visibility
+ 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(team_id, int), team_id
+ 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
+ assert is_optional(allow_update_branch, bool), allow_update_branch
+ post_parameters = NotSet.remove_unset_items(
+ {
+ "name": name,
+ "description": description,
+ "homepage": homepage,
+ "private": private,
+ "visibility": visibility,
+ "has_issues": has_issues,
+ "has_wiki": has_wiki,
+ "has_downloads": has_downloads,
+ "has_projects": has_projects,
+ "team_id": team_id,
+ "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,
+ "allow_update_branch": allow_update_branch,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/repos",
@@ -614,18 +499,13 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_secret(
self,
- secret_name,
- unencrypted_value,
- visibility="all",
- selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
- ):
+ secret_name: str,
+ unencrypted_value: str,
+ visibility: str = "all",
+ selected_repositories: Opt[list[github.Repository.Repository]] = NotSet,
+ ) -> github.OrganizationSecret.OrganizationSecret:
"""
:calls: `PUT /orgs/{org}/actions/secrets/{secret_name} `_
- :param secret_name: string
- :param unencrypted_value: string
- :param visibility: string
- :param selected_repositories: Optional list of :class:`github.Repository.Repository`
- :rtype: github.OrganizationSecret.OrganizationSecret
"""
assert isinstance(secret_name, str), secret_name
assert isinstance(unencrypted_value, str), unencrypted_value
@@ -635,16 +515,16 @@ class Organization(github.GithubObject.CompletableGithubObject):
isinstance(element, github.Repository.Repository) for element in selected_repositories
), selected_repositories
else:
- assert selected_repositories is github.GithubObject.NotSet
+ assert selected_repositories is NotSet
public_key = self.get_public_key()
payload = public_key.encrypt(unencrypted_value)
- put_parameters = {
+ put_parameters: dict[str, Any] = {
"key_id": public_key.key_id,
"encrypted_value": payload,
"visibility": visibility,
}
- if selected_repositories is not github.GithubObject.NotSet:
+ if is_defined(selected_repositories):
put_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
self._requester.requestJsonAndCheck("PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters)
@@ -661,12 +541,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
completed=False,
)
- def get_secrets(self):
+ def get_secrets(self) -> PaginatedList[OrganizationSecret]:
"""
Gets all organization secrets
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.OrganizationSecret.OrganizationSecret`
+ :rtype: :class:`PaginatedList` of :class:`github.OrganizationSecret.OrganizationSecret`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.OrganizationSecret.OrganizationSecret,
self._requester,
f"{self.url}/actions/secrets",
@@ -674,7 +554,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
list_item="secrets",
)
- def get_secret(self, secret_name: str):
+ def get_secret(self, secret_name: str) -> OrganizationSecret:
"""
:calls: 'GET /orgs/{org}/actions/secrets/{secret_name} `_
:param secret_name: string
@@ -690,12 +570,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_team(
self,
- name,
- repo_names=github.GithubObject.NotSet,
- permission=github.GithubObject.NotSet,
- privacy=github.GithubObject.NotSet,
- description=github.GithubObject.NotSet,
- ):
+ name: str,
+ repo_names: Opt[list[Repository]] = NotSet,
+ permission: Opt[str] = NotSet,
+ privacy: Opt[str] = NotSet,
+ description: Opt[str] = NotSet,
+ ) -> Team:
"""
:calls: `POST /orgs/{org}/teams `_
:param name: string
@@ -706,23 +586,15 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Team.Team`
"""
assert isinstance(name, str), name
- assert repo_names is github.GithubObject.NotSet or all(
- isinstance(element, github.Repository.Repository) for element in repo_names
- ), repo_names
- assert permission is github.GithubObject.NotSet or isinstance(permission, str), permission
- assert privacy is github.GithubObject.NotSet or isinstance(privacy, str), privacy
- assert description is github.GithubObject.NotSet or isinstance(description, str), description
- post_parameters = {
- "name": name,
- }
- if repo_names is not github.GithubObject.NotSet:
+ assert is_optional_list(repo_names, github.Repository.Repository), repo_names
+ assert is_optional(permission, str), permission
+ assert is_optional(privacy, str), privacy
+ assert is_optional(description, str), description
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {"name": name, "permission": permission, "privacy": privacy, "description": description}
+ )
+ if is_defined(repo_names):
post_parameters["repo_names"] = [element._identity for element in repo_names]
- if permission is not github.GithubObject.NotSet:
- post_parameters["permission"] = permission
- if privacy is not github.GithubObject.NotSet:
- post_parameters["privacy"] = privacy
- if description is not github.GithubObject.NotSet:
- post_parameters["description"] = description
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/teams", input=post_parameters)
return github.Team.Team(self._requester, headers, data, completed=True)
@@ -731,7 +603,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
variable_name: str,
value: str,
visibility: str = "all",
- selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
+ selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = NotSet,
) -> github.OrganizationVariable.OrganizationVariable:
"""
:calls: `POST /orgs/{org}/actions/variables/ `_
@@ -749,14 +621,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
isinstance(element, github.Repository.Repository) for element in selected_repositories
), selected_repositories
else:
- assert selected_repositories is github.GithubObject.NotSet
+ assert selected_repositories is NotSet
- post_parameters = {
+ post_parameters: dict[str, Any] = {
"name": variable_name,
"value": value,
"visibility": visibility,
}
- if selected_repositories is not github.GithubObject.NotSet:
+ if is_defined(selected_repositories):
post_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
self._requester.requestJsonAndCheck("POST", f"{self.url}/actions/variables", input=post_parameters)
@@ -774,12 +646,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
completed=False,
)
- def get_variables(self):
+ def get_variables(self) -> PaginatedList[OrganizationVariable]:
"""
Gets all organization variables
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.OrganizationVariable.OrganizationVariable`
+ :rtype: :class:`PaginatedList` of :class:`github.OrganizationVariable.OrganizationVariable`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.OrganizationVariable.OrganizationVariable,
self._requester,
f"{self.url}/actions/variables",
@@ -787,7 +659,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
list_item="variables",
)
- def get_variable(self, variable_name: str):
+ def get_variable(self, variable_name: str) -> OrganizationVariable:
"""
:calls: 'GET /orgs/{org}/actions/variables/{variable_name} `_
:param variable_name: string
@@ -801,7 +673,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
completed=False,
)
- def delete_hook(self, id):
+ def delete_hook(self, id: int) -> None:
"""
:calls: `DELETE /orgs/{owner}/hooks/{id} `_
:param id: integer
@@ -812,106 +684,82 @@ class Organization(github.GithubObject.CompletableGithubObject):
def edit(
self,
- billing_email=github.GithubObject.NotSet,
- blog=github.GithubObject.NotSet,
- company=github.GithubObject.NotSet,
- description=github.GithubObject.NotSet,
- email=github.GithubObject.NotSet,
- location=github.GithubObject.NotSet,
- name=github.GithubObject.NotSet,
- ):
+ billing_email: Opt[str] = NotSet,
+ blog: Opt[str] = NotSet,
+ company: Opt[str] = NotSet,
+ description: Opt[str] = NotSet,
+ email: Opt[str] = NotSet,
+ location: Opt[str] = NotSet,
+ name: Opt[str] = NotSet,
+ ) -> None:
"""
:calls: `PATCH /orgs/{org} `_
- :param billing_email: string
- :param blog: string
- :param company: string
- :param description: string
- :param email: string
- :param location: string
- :param name: string
- :rtype: None
"""
- assert billing_email is github.GithubObject.NotSet or isinstance(billing_email, str), billing_email
- assert blog is github.GithubObject.NotSet or isinstance(blog, str), blog
- assert company is github.GithubObject.NotSet or isinstance(company, str), company
- assert description is github.GithubObject.NotSet or isinstance(description, str), description
- assert email is github.GithubObject.NotSet or isinstance(email, str), email
- assert location is github.GithubObject.NotSet or isinstance(location, str), location
- assert name is github.GithubObject.NotSet or isinstance(name, str), name
- post_parameters = dict()
- if billing_email is not github.GithubObject.NotSet:
- post_parameters["billing_email"] = billing_email
- if blog is not github.GithubObject.NotSet:
- post_parameters["blog"] = blog
- if company is not github.GithubObject.NotSet:
- post_parameters["company"] = company
- if description is not github.GithubObject.NotSet:
- post_parameters["description"] = description
- if email is not github.GithubObject.NotSet:
- post_parameters["email"] = email
- if location is not github.GithubObject.NotSet:
- post_parameters["location"] = location
- if name is not github.GithubObject.NotSet:
- post_parameters["name"] = name
+ assert is_optional(billing_email, str), billing_email
+ assert is_optional(blog, str), blog
+ assert is_optional(company, str), company
+ assert is_optional(description, str), description
+ assert is_optional(email, str), email
+ assert is_optional(location, str), location
+ assert is_optional(name, str), name
+ post_parameters = NotSet.remove_unset_items(
+ {
+ "billing_email": billing_email,
+ "blog": blog,
+ "company": company,
+ "description": description,
+ "email": email,
+ "location": location,
+ "name": name,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def edit_hook(
self,
- id,
- name,
- config,
- events=github.GithubObject.NotSet,
- active=github.GithubObject.NotSet,
- ):
+ id: int,
+ name: str,
+ config: dict[str, str],
+ events: Opt[list[str]] = NotSet,
+ active: Opt[bool] = NotSet,
+ ) -> Hook:
"""
:calls: `PATCH /orgs/{owner}/hooks/{id} `_
- :param id: integer
- :param name: string
- :param config: dict
- :param events: list of string
- :param active: bool
- :rtype: :class:`github.Hook.Hook`
"""
assert isinstance(id, int), id
assert isinstance(name, str), name
assert isinstance(config, dict), config
- assert events is github.GithubObject.NotSet or all(isinstance(element, str) for element in events), events
- assert active is github.GithubObject.NotSet or isinstance(active, bool), active
- post_parameters = {
- "name": name,
- "config": config,
- }
- if events is not github.GithubObject.NotSet:
- post_parameters["events"] = events
- if active is not github.GithubObject.NotSet:
- post_parameters["active"] = active
+ assert is_optional_list(events, str), events
+ assert is_optional(active, bool), active
+ post_parameters: dict[str, Any] = NotSet.remove_unset_items(
+ {"name": name, "config": config, "events": events, "active": active}
+ )
+
headers, data = self._requester.requestJsonAndCheck("PATCH", f"{self.url}/hooks/{id}", input=post_parameters)
return github.Hook.Hook(self._requester, headers, data, completed=True)
- def get_events(self):
+ def get_events(self) -> PaginatedList[Event]:
"""
:calls: `GET /orgs/{org}/events `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
+ :rtype: :class:`PaginatedList` of :class:`github.Event.Event`
"""
- return github.PaginatedList.PaginatedList(github.Event.Event, self._requester, f"{self.url}/events", None)
+ return PaginatedList(github.Event.Event, self._requester, f"{self.url}/events", None)
- def get_hook(self, id):
+ def get_hook(self, id: int) -> github.Hook.Hook:
"""
:calls: `GET /orgs/{owner}/hooks/{id} `_
- :param id: integer
- :rtype: :class:`github.Hook.Hook`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/hooks/{id}")
return github.Hook.Hook(self._requester, headers, data, completed=True)
- def get_hooks(self):
+ def get_hooks(self) -> PaginatedList[Hook]:
"""
:calls: `GET /orgs/{owner}/hooks `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook`
"""
- return github.PaginatedList.PaginatedList(github.Hook.Hook, self._requester, f"{self.url}/hooks", None)
+ return PaginatedList(github.Hook.Hook, self._requester, f"{self.url}/hooks", None)
def get_hook_delivery(self, hook_id: int, delivery_id: int) -> github.HookDelivery.HookDelivery:
"""
@@ -927,16 +775,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
)
return github.HookDelivery.HookDelivery(self._requester, headers, data, completed=True)
- def get_hook_deliveries(
- self, hook_id: int
- ) -> github.PaginatedList.PaginatedList[github.HookDelivery.HookDeliverySummary]:
+ def get_hook_deliveries(self, hook_id: int) -> PaginatedList[github.HookDelivery.HookDeliverySummary]:
"""
:calls: `GET /orgs/{owner}/hooks/{hook_id}/deliveries `_
:param hook_id: integer
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.HookDelivery.HookDeliverySummary`
+ :rtype: :class:`PaginatedList` of :class:`github.HookDelivery.HookDeliverySummary`
"""
assert isinstance(hook_id, int), hook_id
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.HookDelivery.HookDeliverySummary,
self._requester,
f"{self.url}/hooks/{hook_id}/deliveries",
@@ -945,83 +791,67 @@ class Organization(github.GithubObject.CompletableGithubObject):
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 /orgs/{org}/issues `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
+ :rtype: :class:`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`
+ :rtype: :class:`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:
- url_parameters["filter"] = filter
- if state is not github.GithubObject.NotSet:
- url_parameters["state"] = state
- if labels is not github.GithubObject.NotSet:
- url_parameters["labels"] = ",".join(label.name for label in labels)
- if sort is not github.GithubObject.NotSet:
- url_parameters["sort"] = sort
- if direction is not github.GithubObject.NotSet:
- url_parameters["direction"] = direction
- if since is not github.GithubObject.NotSet:
- url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
- return github.PaginatedList.PaginatedList(
- github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters
+ 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] = NotSet.remove_unset_items(
+ {"filter": filter, "state": state, "sort": sort, "direction": direction}
)
+ if is_defined(labels):
+ url_parameters["labels"] = ",".join(label.name for label in labels)
+ if is_defined(since):
+ url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
+ return PaginatedList(github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters)
- def get_members(self, filter_=github.GithubObject.NotSet, role=github.GithubObject.NotSet):
+ def get_members(
+ self,
+ filter_: Opt[str] = NotSet,
+ role: Opt[str] = NotSet,
+ ) -> PaginatedList[NamedUser]:
"""
:calls: `GET /orgs/{org}/members `_
- :param filter_: string
- :param role: string
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- assert filter_ is github.GithubObject.NotSet or isinstance(filter_, str), filter_
- assert role is github.GithubObject.NotSet or isinstance(role, str), role
+ assert is_optional(filter_, str), filter_
+ assert is_optional(role, str), role
- url_parameters = {}
- if filter_ is not github.GithubObject.NotSet:
- url_parameters["filter"] = filter_
- if role is not github.GithubObject.NotSet:
- url_parameters["role"] = role
- return github.PaginatedList.PaginatedList(
+ url_parameters = NotSet.remove_unset_items({"filter": filter_, "role": role})
+
+ return PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/members",
url_parameters,
)
- def get_projects(self, state=github.GithubObject.NotSet):
+ def get_projects(self, state: Opt[str] = NotSet) -> PaginatedList[Project]:
"""
:calls: `GET /orgs/{org}/projects `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project`
- :param state: string
"""
- url_parameters = dict()
- if state is not github.GithubObject.NotSet:
- url_parameters["state"] = state
+ url_parameters = NotSet.remove_unset_items({"state": state})
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Project.Project,
self._requester,
f"{self.url}/projects",
@@ -1029,37 +859,33 @@ class Organization(github.GithubObject.CompletableGithubObject):
{"Accept": Consts.mediaTypeProjectsPreview},
)
- def get_public_members(self):
+ def get_public_members(self) -> PaginatedList[NamedUser]:
"""
:calls: `GET /orgs/{org}/public_members `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
+ :rtype: :class:`PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/public_members",
None,
)
- def get_outside_collaborators(self, filter_=github.GithubObject.NotSet):
+ def get_outside_collaborators(self, filter_: Opt[str] = NotSet) -> PaginatedList[NamedUser]:
"""
:calls: `GET /orgs/{org}/outside_collaborators `_
- :param filter_: string
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- assert filter_ is github.GithubObject.NotSet or isinstance(filter_, str), filter_
+ assert is_optional(filter_, str), filter_
- url_parameters = {}
- if filter_ is not github.GithubObject.NotSet:
- url_parameters["filter"] = filter_
- return github.PaginatedList.PaginatedList(
+ url_parameters = NotSet.remove_unset_items({"filter": filter_})
+ return PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/outside_collaborators",
url_parameters,
)
- def remove_outside_collaborator(self, collaborator):
+ def remove_outside_collaborator(self, collaborator: NamedUser) -> None:
"""
:calls: `DELETE /orgs/{org}/outside_collaborators/{username} `_
:param collaborator: :class:`github.NamedUser.NamedUser`
@@ -1070,7 +896,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"DELETE", f"{self.url}/outside_collaborators/{collaborator._identity}"
)
- def convert_to_outside_collaborator(self, member):
+ def convert_to_outside_collaborator(self, member: NamedUser) -> None:
"""
:calls: `PUT /orgs/{org}/outside_collaborators/{username} `_
:param member: :class:`github.NamedUser.NamedUser`
@@ -1081,7 +907,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"PUT", f"{self.url}/outside_collaborators/{member._identity}"
)
- def get_public_key(self):
+ def get_public_key(self) -> PublicKey:
"""
:calls: `GET /orgs/{org}/actions/secrets/public-key `_
:rtype: :class:`github.PublicKey.PublicKey`
@@ -1089,7 +915,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/secrets/public-key")
return github.PublicKey.PublicKey(self._requester, headers, data, completed=True)
- def get_repo(self, name):
+ def get_repo(self, name: str) -> Repository:
"""
:calls: `GET /repos/{owner}/{repo} `_
:param name: string
@@ -1105,29 +931,23 @@ class Organization(github.GithubObject.CompletableGithubObject):
def get_repos(
self,
- type=github.GithubObject.NotSet,
- sort=github.GithubObject.NotSet,
- direction=github.GithubObject.NotSet,
- ):
+ type: Opt[str] = NotSet,
+ sort: Opt[str] = NotSet,
+ direction: Opt[str] = NotSet,
+ ) -> PaginatedList[Repository]:
"""
:calls: `GET /orgs/{org}/repos `_
:param type: string ('all', 'public', 'private', 'forks', 'sources', 'member')
:param sort: string ('created', 'updated', 'pushed', 'full_name')
:param direction: string ('asc', desc')
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
- 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
+ assert is_optional(type, str), type
+ assert is_optional(sort, str), sort
+ assert is_optional(direction, str), direction
- url_parameters = dict()
- 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(
+ url_parameters = NotSet.remove_unset_items({"type": type, "sort": sort, "direction": direction})
+
+ return PaginatedList(
github.Repository.Repository,
self._requester,
f"{self.url}/repos",
@@ -1135,39 +955,33 @@ class Organization(github.GithubObject.CompletableGithubObject):
headers={"Accept": Consts.repoVisibilityPreview},
)
- def get_team(self, id):
+ def get_team(self, id: int) -> Team:
"""
:calls: `GET /teams/{id} `_
- :param id: integer
- :rtype: :class:`github.Team.Team`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck("GET", f"/teams/{id}")
return github.Team.Team(self._requester, headers, data, completed=True)
- def get_team_by_slug(self, slug):
+ def get_team_by_slug(self, slug: str) -> Team:
"""
:calls: `GET /orgs/{org}/teams/{team_slug} `_
- :param slug: string
- :rtype: :class:`github.Team.Team`
"""
assert isinstance(slug, str), slug
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/teams/{slug}")
return github.Team.Team(self._requester, headers, data, completed=True)
- def get_teams(self):
+ def get_teams(self) -> PaginatedList[Team]:
"""
:calls: `GET /orgs/{org}/teams `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
- return github.PaginatedList.PaginatedList(github.Team.Team, self._requester, f"{self.url}/teams", None)
+ return PaginatedList(github.Team.Team, self._requester, f"{self.url}/teams", None)
- def invitations(self):
+ def invitations(self) -> PaginatedList[NamedUser]:
"""
:calls: `GET /orgs/{org}/invitations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.NamedUser.NamedUser,
self._requester,
f"{self.url}/invitations",
@@ -1177,11 +991,11 @@ class Organization(github.GithubObject.CompletableGithubObject):
def invite_user(
self,
- user=github.GithubObject.NotSet,
- email=github.GithubObject.NotSet,
- role=github.GithubObject.NotSet,
- teams=github.GithubObject.NotSet,
- ):
+ user: Opt[NamedUser] = NotSet,
+ email: Opt[str] = NotSet,
+ role: Opt[str] = NotSet,
+ teams: Opt[list[Team]] = NotSet,
+ ) -> None:
"""
:calls: `POST /orgs/{org}/invitations `_
:param user: :class:`github.NamedUser.NamedUser`
@@ -1190,23 +1004,20 @@ class Organization(github.GithubObject.CompletableGithubObject):
:param teams: array of :class:`github.Team.Team`
:rtype: None
"""
- assert user is github.GithubObject.NotSet or isinstance(user, github.NamedUser.NamedUser), user
- assert email is github.GithubObject.NotSet or isinstance(email, str), email
- assert (email is github.GithubObject.NotSet) ^ (
- user is github.GithubObject.NotSet
- ), "specify only one of email or user"
- parameters = {}
- if user is not github.GithubObject.NotSet:
+ assert is_optional(user, github.NamedUser.NamedUser), user
+ assert is_optional(email, str), email
+ assert is_defined(email) != is_defined(user), "specify only one of email or user"
+
+ assert is_undefined(role) or role in ["admin", "direct_member", "billing_manager"], role
+ assert is_optional_list(teams, github.Team.Team), teams
+
+ parameters: dict[str, Any] = NotSet.remove_unset_items({"email": email, "role": role})
+
+ if is_defined(user):
parameters["invitee_id"] = user.id
- elif email is not github.GithubObject.NotSet:
- parameters["email"] = email
- if role is not github.GithubObject.NotSet:
- assert isinstance(role, str), role
- assert role in ["admin", "direct_member", "billing_manager"]
- parameters["role"] = role
- if teams is not github.GithubObject.NotSet:
- assert all(isinstance(team, github.Team.Team) for team in teams)
+ if is_defined(teams):
parameters["team_ids"] = [t.id for t in teams]
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/invitations",
@@ -1214,7 +1025,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
input=parameters,
)
- def cancel_invitation(self, invitee):
+ def cancel_invitation(self, invitee: NamedUser) -> bool:
"""
:calls: `DELETE /orgs/{org}/invitations/{invitation_id} `_
:param invitee: :class:`github.NamedUser.NamedUser`
@@ -1224,7 +1035,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/invitations/{invitee.id}")
return status == 204
- def has_in_members(self, member):
+ def has_in_members(self, member: NamedUser) -> bool:
"""
:calls: `GET /orgs/{org}/members/{user} `_
:param member: :class:`github.NamedUser.NamedUser`
@@ -1236,7 +1047,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
status, headers, data = self._requester.requestJson("GET", headers["location"])
return status == 204
- def has_in_public_members(self, public_member):
+ def has_in_public_members(self, public_member: NamedUser) -> bool:
"""
:calls: `GET /orgs/{org}/public_members/{user} `_
:param public_member: :class:`github.NamedUser.NamedUser`
@@ -1248,7 +1059,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
)
return status == 204
- def remove_from_membership(self, member):
+ def remove_from_membership(self, member: NamedUser) -> None:
"""
:calls: `DELETE /orgs/{org}/memberships/{user} `_
:param member: :class:`github.NamedUser.NamedUser`
@@ -1257,7 +1068,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/memberships/{member._identity}")
- def remove_from_members(self, member):
+ def remove_from_members(self, member: NamedUser) -> None:
"""
:calls: `DELETE /orgs/{org}/members/{user} `_
:param member: :class:`github.NamedUser.NamedUser`
@@ -1266,7 +1077,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/members/{member._identity}")
- def remove_from_public_members(self, public_member):
+ def remove_from_public_members(self, public_member: NamedUser) -> None:
"""
:calls: `DELETE /orgs/{org}/public_members/{user} `_
:param public_member: :class:`github.NamedUser.NamedUser`
@@ -1279,10 +1090,10 @@ class Organization(github.GithubObject.CompletableGithubObject):
def create_migration(
self,
- repos,
- lock_repositories=github.GithubObject.NotSet,
- exclude_attachments=github.GithubObject.NotSet,
- ):
+ repos: list[str],
+ lock_repositories: Opt[bool] = NotSet,
+ exclude_attachments: Opt[bool] = NotSet,
+ ) -> Migration:
"""
:calls: `POST /orgs/{org}/migrations `_
:param repos: list or tuple of str
@@ -1292,15 +1103,16 @@ class Organization(github.GithubObject.CompletableGithubObject):
"""
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 = NotSet.remove_unset_items(
+ {
+ "repositories": repos,
+ "lock_repositories": lock_repositories,
+ "exclude_attachments": exclude_attachments,
+ }
+ )
+
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"/orgs/{self.login}/migrations",
@@ -1309,12 +1121,12 @@ class Organization(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 /orgs/{org}/migrations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Migration.Migration`
+ :rtype: :class:`PaginatedList` of :class:`github.Migration.Migration`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Migration.Migration,
self._requester,
f"/orgs/{self.login}/migrations",
@@ -1322,13 +1134,13 @@ class Organization(github.GithubObject.CompletableGithubObject):
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
- def get_installations(self):
+ def get_installations(self) -> PaginatedList[Installation]:
"""
:calls: `GET /orgs/{org}/installations `_
- :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Installation.Installation`
+ :rtype: :class:`PaginatedList` of :class:`github.Installation.Installation`
"""
- return github.PaginatedList.PaginatedList(
+ return PaginatedList(
github.Installation.Installation,
self._requester,
f"{self.url}/installations",
@@ -1337,45 +1149,6 @@ class Organization(github.GithubObject.CompletableGithubObject):
list_item="installations",
)
- def _initAttributes(self) -> None:
- self._default_repository_permission = github.GithubObject.NotSet
- self._has_organization_projects = github.GithubObject.NotSet
- self._has_repository_projects = github.GithubObject.NotSet
- self._hooks_url = github.GithubObject.NotSet
- self._issues_url = github.GithubObject.NotSet
- self._members_can_create_repositories = github.GithubObject.NotSet
- self._two_factor_requirement_enabled = github.GithubObject.NotSet
- self._avatar_url = github.GithubObject.NotSet
- self._billing_email = 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._description = 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._following = github.GithubObject.NotSet
- self._gravatar_id = 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._members_url = github.GithubObject.NotSet
- self._name = 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_members_url = github.GithubObject.NotSet
- self._public_repos = github.GithubObject.NotSet
- self._repos_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
-
def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "avatar_url" in attributes: # pragma no branch
self._avatar_url = self._makeStringAttribute(attributes["avatar_url"])
diff --git a/github/Organization.pyi b/github/Organization.pyi
deleted file mode 100644
index 6f6aa5be..00000000
--- a/github/Organization.pyi
+++ /dev/null
@@ -1,241 +0,0 @@
-from datetime import datetime
-from typing import Any, Dict, List, Optional, Union
-
-from github.Event import Event
-from github.GithubObject import CompletableGithubObject, _NotSetType
-from github.Hook import Hook
-from github.Installation import Installation
-from github.Issue import Issue
-from github.Label import Label
-from github.Migration import Migration
-from github.NamedUser import NamedUser
-from github.OrganizationSecret import OrganizationSecret
-from github.OrganizationVariable import OrganizationVariable
-from github.PaginatedList import PaginatedList
-from github.Plan import Plan
-from github.Project import Project
-from github.PublicKey import PublicKey
-from github.Repository import Repository
-from github.Team import Team
-
-class Organization(CompletableGithubObject):
- def __repr__(self) -> str: ...
- def _initAttributes(self) -> None: ...
- def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
- def add_to_members(self, member: NamedUser, role: Union[_NotSetType, str] = ...) -> None: ...
- def add_to_public_members(self, public_member: NamedUser) -> None: ...
- @property
- def avatar_url(self) -> str: ...
- @property
- def billing_email(self) -> str: ...
- @property
- def blog(self) -> Optional[str]: ...
- @property
- def collaborators(self) -> int: ...
- @property
- def company(self) -> Optional[str]: ...
- def convert_to_outside_collaborator(self, member: NamedUser) -> None: ...
- def create_fork(
- self,
- repo: Repository,
- name: Union[str, _NotSetType] = ...,
- default_branch_only: Union[str, _NotSetType] = ...,
- ) -> Repository: ...
- def create_hook(
- self,
- name: str,
- config: Dict[str, str],
- events: Union[_NotSetType, List[str]] = ...,
- active: Union[bool, _NotSetType] = ...,
- ) -> Hook: ...
- 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] = ...,
- team_id: Union[int, _NotSetType] = ...,
- auto_init: Union[bool, _NotSetType] = ...,
- license_template: Union[str, _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: ...
- def get_secrets(
- self,
- ) -> PaginatedList[OrganizationSecret]: ...
- def get_secret(
- self,
- secret_name: str,
- ) -> OrganizationSecret: ...
- def create_secret(
- self,
- secret_name: str,
- unencrypted_value: str,
- visibility: str = ...,
- selected_repositories: Union[List[Repository], _NotSetType] = ...,
- ) -> OrganizationSecret: ...
- def create_team(
- self,
- name: str,
- repo_names: Union[List[Repository], _NotSetType] = ...,
- permission: Union[str, _NotSetType] = ...,
- privacy: Union[str, _NotSetType] = ...,
- description: Union[str, _NotSetType] = ...,
- ) -> Team: ...
- def get_variables(
- self,
- ) -> PaginatedList[OrganizationVariable]: ...
- def get_variable(
- self,
- variable_name: str,
- ) -> OrganizationVariable: ...
- def create_variable(
- self,
- variable_name: str,
- value: str,
- visibility: str = ...,
- selected_repositories: Union[List[Repository], _NotSetType] = ...,
- ) -> OrganizationVariable: ...
- @property
- def created_at(self) -> datetime: ...
- def delete_hook(self, id: int) -> None: ...
- @property
- def default_repository_permission(self) -> str: ...
- @property
- def description(self) -> str: ...
- @property
- def disk_usage(self) -> int: ...
- def edit(
- self,
- billing_email: Union[str, _NotSetType] = ...,
- blog: Union[str, _NotSetType] = ...,
- company: Union[str, _NotSetType] = ...,
- description: Union[str, _NotSetType] = ...,
- email: Union[str, _NotSetType] = ...,
- location: Union[str, _NotSetType] = ...,
- name: Union[str, _NotSetType] = ...,
- ) -> None: ...
- def edit_hook(
- self,
- id: int,
- name: str,
- config: Dict[str, str],
- events: Union[_NotSetType, List[str]] = ...,
- active: Union[bool, _NotSetType] = ...,
- ) -> Hook: ...
- @property
- def email(self) -> Optional[str]: ...
- @property
- def events_url(self) -> str: ...
- @property
- def followers(self) -> int: ...
- @property
- def following(self) -> int: ...
- def get_events(self) -> PaginatedList[Event]: ...
- def get_hooks(self) -> PaginatedList[Hook]: ...
- 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_members(
- self,
- filter_: Union[str, _NotSetType] = ...,
- role: Union[str, _NotSetType] = ...,
- ) -> PaginatedList[NamedUser]: ...
- def get_migrations(self) -> PaginatedList[Migration]: ...
- def get_installations(self) -> PaginatedList[Installation]: ...
- def get_outside_collaborators(self, filter_: Union[str, _NotSetType] = ...) -> PaginatedList[NamedUser]: ...
- def get_projects(self, state: Union[_NotSetType, str] = ...) -> PaginatedList[Project]: ...
- def get_public_key(self) -> PublicKey: ...
- def get_public_members(self) -> PaginatedList[NamedUser]: ...
- def get_repo(self, name: str) -> Repository: ...
- def get_repos(
- self,
- type: Union[str, _NotSetType] = ...,
- sort: Union[str, _NotSetType] = ...,
- direction: Union[str, _NotSetType] = ...,
- ) -> PaginatedList[Repository]: ...
- def get_team(self, id: int) -> Team: ...
- def get_team_by_slug(self, slug: str) -> Team: ...
- def get_teams(self) -> PaginatedList[Team]: ...
- @property
- def gravatar_id(self) -> str: ...
- def has_in_members(self, member: NamedUser) -> bool: ...
- def has_in_public_members(self, public_member: NamedUser) -> bool: ...
- @property
- def has_organization_projects(self) -> bool: ...
- @property
- def has_repository_projects(self) -> bool: ...
- @property
- def hooks_url(self) -> str: ...
- @property
- def html_url(self) -> str: ...
- @property
- def id(self) -> int: ...
- @property
- def issues_url(self) -> str: ...
- def invitations(self) -> PaginatedList[NamedUser]: ...
- def invite_user(
- self,
- user: Union[_NotSetType, NamedUser] = ...,
- email: Union[str, _NotSetType] = ...,
- role: Union[str, _NotSetType] = ...,
- teams: Union[List[Team], _NotSetType] = ...,
- ) -> None: ...
- def cancel_invitation(self, invitee: NamedUser) -> bool: ...
- @property
- def location(self) -> str: ...
- @property
- def login(self) -> str: ...
- @property
- def members_can_create_repositories(self) -> bool: ...
- @property
- def members_url(self) -> str: ...
- @property
- def name(self) -> Optional[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_members_url(self) -> str: ...
- @property
- def public_repos(self) -> int: ...
- def remove_from_members(self, member: NamedUser) -> None: ...
- def remove_from_membership(self, member: NamedUser) -> None: ...
- def remove_from_public_members(self, public_member: NamedUser) -> None: ...
- def remove_outside_collaborator(self, collaborator: NamedUser) -> None: ...
- def create_project(self, param: str, body: _NotSetType) -> None: ...
- @property
- def repos_url(self) -> str: ...
- @property
- def total_private_repos(self) -> int: ...
- @property
- def two_factor_requirement_enabled(self) -> bool: ...
- @property
- def type(self) -> str: ...
- @property
- def updated_at(self) -> datetime: ...
- @property
- def url(self) -> str: ...