Set line length to 120 characters (#2599)

This commit is contained in:
Jirka Borovec
2023-07-13 17:37:20 +02:00
committed by GitHub
parent de80ff4b91
commit 13e178a3ab
192 changed files with 1455 additions and 4433 deletions
+1 -1
View File
@@ -3,6 +3,6 @@ multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
line_length=120
known_third_party=dateutil,deprecated,httpretty,jwt,nacl,pytest,requests,setuptools,typing_extensions,urllib3
known_first_party=github
+1 -3
View File
@@ -362,7 +362,5 @@ with open("apis.rst", "w") as apis:
apis.write("\n")
for verb in ["GET", "PATCH", "POST", "PUT", "DELETE"]:
if verb in verbs:
apis.write(
" * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n"
)
apis.write(" * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n")
apis.write("\n")
+2 -6
View File
@@ -48,9 +48,7 @@ class AccessToken(NonCompletableGithubObject):
"scope": self.scope,
"type": self.type,
"expires_in": self.expires_in,
"refresh_token": (
f"{self.refresh_token[:5]}..." if self.refresh_token else None
),
"refresh_token": (f"{self.refresh_token[:5]}..." if self.refresh_token else None),
"refresh_token_expires_in": self.refresh_expires_in,
}
)
@@ -137,6 +135,4 @@ class AccessToken(NonCompletableGithubObject):
if "refresh_token" in attributes: # pragma no branch
self._refresh_token = self._makeStringAttribute(attributes["refresh_token"])
if "refresh_token_expires_in" in attributes: # pragma no branch
self._refresh_expires_in = self._makeIntAttribute(
attributes["refresh_token_expires_in"]
)
self._refresh_expires_in = self._makeIntAttribute(attributes["refresh_token_expires_in"])
+11 -15
View File
@@ -110,20 +110,18 @@ class Artifact(NonCompletableGithubObject):
def _useAttributes(self, attributes):
if "archive_download_url" in attributes: # pragma no branch
self._archive_download_url = self._makeStringAttribute(
attributes["archive_download_url"]
)
self._archive_download_url = self._makeStringAttribute(attributes["archive_download_url"])
if "created_at" in attributes: # pragma no branch
assert attributes["created_at"] is None or isinstance(
attributes["created_at"], (str,)
), attributes["created_at"]
assert attributes["created_at"] is None or isinstance(attributes["created_at"], (str,)), attributes[
"created_at"
]
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "expired" in attributes: # pragma no branch
self._expired = self._makeBoolAttribute(attributes["expired"])
if "expires_at" in attributes: # pragma no branch
assert attributes["expires_at"] is None or isinstance(
attributes["expires_at"], (str,)
), attributes["expires_at"]
assert attributes["expires_at"] is None or isinstance(attributes["expires_at"], (str,)), attributes[
"expires_at"
]
self._expires_at = self._makeDatetimeAttribute(attributes["expires_at"])
if "head_sha" in attributes: # pragma no branch
self._head_sha = self._makeStringAttribute(attributes["head_sha"])
@@ -136,13 +134,11 @@ class Artifact(NonCompletableGithubObject):
if "size_in_bytes" in attributes: # pragma no branch
self._size_in_bytes = self._makeIntAttribute(attributes["size_in_bytes"])
if "updated_at" in attributes: # pragma no branch
assert attributes["updated_at"] is None or isinstance(
attributes["updated_at"], (str,)
), attributes["updated_at"]
assert attributes["updated_at"] is None or isinstance(attributes["updated_at"], (str,)), attributes[
"updated_at"
]
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "workflow_run" in attributes: # pragma no branch
self._workflow_run = self._makeClassAttribute(
github.WorkflowRun.WorkflowRun, attributes["workflow_run"]
)
self._workflow_run = self._makeClassAttribute(github.WorkflowRun.WorkflowRun, attributes["workflow_run"])
+11 -37
View File
@@ -34,9 +34,7 @@ from github.Requester import Requester, WithRequester
# For App authentication, time remaining before token expiration to request a new one
ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS = 20
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(
seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS
)
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS)
class Auth(abc.ABC):
@@ -91,11 +89,7 @@ class Login(Auth):
@property
def token(self) -> str:
return (
base64.b64encode(f"{self.login}:{self.password}".encode())
.decode("utf-8")
.replace("\n", "")
)
return base64.b64encode(f"{self.login}:{self.password}".encode()).decode("utf-8").replace("\n", "")
class Token(Auth):
@@ -192,9 +186,7 @@ class AppAuth(JWT):
"""
if expiration is not None:
assert isinstance(expiration, int), expiration
assert (
Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY
), expiration
assert Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY, expiration
now = int(time.time())
payload = {
@@ -202,9 +194,7 @@ class AppAuth(JWT):
"exp": now + (expiration if expiration is not None else self._jwt_expiry),
"iss": self._app_id,
}
encrypted = jwt.encode(
payload, key=self.private_key, algorithm=self._jwt_algorithm
)
encrypted = jwt.encode(payload, key=self.private_key, algorithm=self._jwt_algorithm)
if isinstance(encrypted, bytes):
return encrypted.decode("utf-8")
@@ -251,9 +241,7 @@ class AppInstallationAuth(Auth, WithRequester["AppInstallationAuth"]):
assert isinstance(app_auth, AppAuth), app_auth
assert isinstance(installation_id, int), installation_id
assert token_permissions is None or isinstance(
token_permissions, dict
), token_permissions
assert token_permissions is None or isinstance(token_permissions, dict), token_permissions
self._app_auth = app_auth
self._installation_id = installation_id
@@ -303,16 +291,11 @@ class AppInstallationAuth(Auth, WithRequester["AppInstallationAuth"]):
@property
def _is_expired(self) -> bool:
assert self.__installation_authorization is not None
token_expires_at = (
self.__installation_authorization.expires_at
- TOKEN_REFRESH_THRESHOLD_TIMEDELTA
)
token_expires_at = self.__installation_authorization.expires_at - TOKEN_REFRESH_THRESHOLD_TIMEDELTA
return token_expires_at < datetime.now(timezone.utc)
def _get_installation_authorization(self) -> InstallationAuthorization:
assert (
self.__integration is not None
), "Method withRequester(Requester) must be called first"
assert self.__integration is not None, "Method withRequester(Requester) must be called first"
return self.__integration.get_access_token(
self._installation_id,
permissions=self._token_permissions,
@@ -413,22 +396,13 @@ class AppUserAuth(Auth, WithRequester["AppUserAuth"]):
@property
def _is_expired(self) -> bool:
return self._expires_at is not None and self._expires_at < datetime.now(
timezone.utc
)
return self._expires_at is not None and self._expires_at < datetime.now(timezone.utc)
def _refresh(self):
if self._refresh_token is None:
raise RuntimeError(
"Cannot refresh expired token because no refresh token has been provided"
)
if (
self._refresh_expires_at is not None
and self._refresh_expires_at < datetime.now(timezone.utc)
):
raise RuntimeError(
"Cannot refresh expired token because refresh token also expired"
)
raise RuntimeError("Cannot refresh expired token because no refresh token has been provided")
if self._refresh_expires_at is not None and self._refresh_expires_at < datetime.now(timezone.utc):
raise RuntimeError("Cannot refresh expired token because refresh token also expired")
# refresh token
token = self.__app.refresh_access_token(self._refresh_token)
+78 -234
View File
@@ -383,9 +383,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"""
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
)
headers, data = self._requester.requestJsonAndCheck("POST", "/user/emails", input=post_parameters)
def add_to_following(self, following):
"""
@@ -394,9 +392,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(following, github.NamedUser.NamedUser), following
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"/user/following/{following._identity}"
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/following/{following._identity}")
def add_to_starred(self, starred):
"""
@@ -405,9 +401,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(starred, github.Repository.Repository), starred
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"/user/starred/{starred._identity}"
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/starred/{starred._identity}")
def add_to_subscriptions(self, subscription):
"""
@@ -416,9 +410,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(subscription, github.Repository.Repository), subscription
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"/user/subscriptions/{subscription._identity}"
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"/user/subscriptions/{subscription._identity}")
def add_to_watched(self, watched):
"""
@@ -452,22 +444,12 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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 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 onetime_password is None or isinstance(
onetime_password, str
), onetime_password
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 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
@@ -480,9 +462,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
if client_secret is not github.GithubObject.NotSet:
post_parameters["client_secret"] = client_secret
if onetime_password is not None:
request_header = {
Consts.headerOTP: onetime_password
} # pragma no cover (Should be covered)
request_header = {Consts.headerOTP: onetime_password} # pragma no cover (Should be covered)
else:
request_header = None
headers, data = self._requester.requestJsonAndCheck(
@@ -491,9 +471,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers=request_header,
)
return github.Authorization.Authorization(
self._requester, headers, data, completed=True
)
return github.Authorization.Authorization(self._requester, headers, data, completed=True)
@staticmethod
def create_fork(
@@ -532,12 +510,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"""
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
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,
@@ -552,9 +526,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": "application/vnd.github.v3+json"},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def create_gist(self, public, files, description=github.GithubObject.NotSet):
"""
@@ -565,21 +537,15 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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 all(isinstance(element, github.InputFileContent) for element in files.values()), files
assert description is github.GithubObject.NotSet 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:
post_parameters["description"] = description
headers, data = self._requester.requestJsonAndCheck(
"POST", "/gists", input=post_parameters
)
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):
@@ -595,9 +561,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"title": title,
"key": key,
}
headers, data = self._requester.requestJsonAndCheck(
"POST", "/user/keys", input=post_parameters
)
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):
@@ -659,33 +623,15 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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 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
@@ -732,12 +678,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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
headers, data = self._requester.requestJsonAndCheck(
"POST", "/user/repos", input=post_parameters
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", "/user/repos", input=post_parameters)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def edit(
self,
@@ -763,15 +705,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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 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:
@@ -788,9 +724,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
post_parameters["hireable"] = hireable
if bio is not github.GithubObject.NotSet:
post_parameters["bio"] = bio
headers, data = self._requester.requestJsonAndCheck(
"PATCH", "/user", input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", "/user", input=post_parameters)
self._useAttributes(data)
def get_authorization(self, id):
@@ -800,12 +734,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/authorizations/{id}")
return github.Authorization.Authorization(self._requester, headers, data, completed=True)
def get_authorizations(self):
"""
@@ -830,27 +760,21 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /events <http://docs.github.com/en/rest/reference/activity#events>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
return github.PaginatedList.PaginatedList(
github.Event.Event, self._requester, "/events", None
)
return github.PaginatedList.PaginatedList(github.Event.Event, self._requester, "/events", None)
def get_followers(self):
"""
:calls: `GET /user/followers <http://docs.github.com/en/rest/reference/users#followers>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser, self._requester, "/user/followers", None
)
return github.PaginatedList.PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/followers", None)
def get_following(self):
"""
:calls: `GET /user/following <http://docs.github.com/en/rest/reference/users#followers>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser, self._requester, "/user/following", None
)
return github.PaginatedList.PaginatedList(github.NamedUser.NamedUser, self._requester, "/user/following", None)
def get_gists(self, since=github.GithubObject.NotSet):
"""
@@ -862,9 +786,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
url_parameters = dict()
if since is not github.GithubObject.NotSet:
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
return github.PaginatedList.PaginatedList(
github.Gist.Gist, self._requester, "/gists", url_parameters
)
return github.PaginatedList.PaginatedList(github.Gist.Gist, self._requester, "/gists", url_parameters)
def get_issues(
self,
@@ -892,9 +814,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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 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:
@@ -909,9 +829,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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, "/issues", url_parameters
)
return github.PaginatedList.PaginatedList(github.Issue.Issue, self._requester, "/issues", url_parameters)
def get_user_issues(
self,
@@ -939,9 +857,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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 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:
@@ -956,9 +872,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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, "/user/issues", url_parameters
)
return github.PaginatedList.PaginatedList(github.Issue.Issue, self._requester, "/user/issues", url_parameters)
def get_key(self, id):
"""
@@ -975,9 +889,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /user/keys <http://docs.github.com/en/rest/reference/users#git-ssh-keys>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey`
"""
return github.PaginatedList.PaginatedList(
github.UserKey.UserKey, self._requester, "/user/keys", None
)
return github.PaginatedList.PaginatedList(github.UserKey.UserKey, self._requester, "/user/keys", None)
def get_notification(self, id):
"""
@@ -986,12 +898,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"""
assert isinstance(id, str), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/notifications/threads/{id}"
)
return github.Notification.Notification(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/notifications/threads/{id}")
return github.Notification.Notification(self._requester, headers, data, completed=True)
def get_notifications(
self,
@@ -1010,13 +918,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"""
assert all is github.GithubObject.NotSet or isinstance(all, bool), all
assert participating is github.GithubObject.NotSet or isinstance(
participating, bool
), participating
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 before is github.GithubObject.NotSet or isinstance(before, datetime), before
params = dict()
if all is not github.GithubObject.NotSet:
@@ -1053,9 +957,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /user/orgs <http://docs.github.com/en/rest/reference/orgs>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization`
"""
return github.PaginatedList.PaginatedList(
github.Organization.Organization, self._requester, "/user/orgs", None
)
return github.PaginatedList.PaginatedList(github.Organization.Organization, self._requester, "/user/orgs", None)
def get_repo(self, name):
"""
@@ -1064,12 +966,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/repos/{self.login}/{name}"
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/repos/{self.login}/{name}")
return github.Repository.Repository(self._requester, headers, data, completed=True)
def get_repos(
self,
@@ -1088,17 +986,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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 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
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
@@ -1119,18 +1011,14 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /user/starred <http://docs.github.com/en/rest/reference/activity#starring>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
"""
return github.PaginatedList.PaginatedList(
github.Repository.Repository, self._requester, "/user/starred", None
)
return github.PaginatedList.PaginatedList(github.Repository.Repository, self._requester, "/user/starred", None)
def get_starred_gists(self):
"""
:calls: `GET /gists/starred <http://docs.github.com/en/rest/reference/gists>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`
"""
return github.PaginatedList.PaginatedList(
github.Gist.Gist, self._requester, "/gists/starred", None
)
return github.PaginatedList.PaginatedList(github.Gist.Gist, self._requester, "/gists/starred", None)
def get_subscriptions(self):
"""
@@ -1146,9 +1034,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /user/teams <http://docs.github.com/en/rest/reference/teams>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
return github.PaginatedList.PaginatedList(
github.Team.Team, self._requester, "/user/teams", None
)
return github.PaginatedList.PaginatedList(github.Team.Team, self._requester, "/user/teams", None)
def get_watched(self):
"""
@@ -1180,9 +1066,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(following, github.NamedUser.NamedUser), following
status, headers, data = self._requester.requestJson(
"GET", f"/user/following/{following._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"/user/following/{following._identity}")
return status == 204
def has_in_starred(self, starred):
@@ -1192,9 +1076,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(starred, github.Repository.Repository), starred
status, headers, data = self._requester.requestJson(
"GET", f"/user/starred/{starred._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"/user/starred/{starred._identity}")
return status == 204
def has_in_subscriptions(self, subscription):
@@ -1204,9 +1086,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(subscription, github.Repository.Repository), subscription
status, headers, data = self._requester.requestJson(
"GET", f"/user/subscriptions/{subscription._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"/user/subscriptions/{subscription._identity}")
return status == 204
def has_in_watched(self, watched):
@@ -1216,9 +1096,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(watched, github.Repository.Repository), watched
status, headers, data = self._requester.requestJson(
"GET", f"/repos/{watched._identity}/subscription"
)
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)):
@@ -1229,9 +1107,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
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
)
headers, data = self._requester.requestJsonAndCheck("PUT", "/notifications", input=put_parameters)
def remove_from_emails(self, *emails):
"""
@@ -1241,9 +1117,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
"""
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
)
headers, data = self._requester.requestJsonAndCheck("DELETE", "/user/emails", input=post_parameters)
def remove_from_following(self, following):
"""
@@ -1252,9 +1126,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(following, github.NamedUser.NamedUser), following
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"/user/following/{following._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/following/{following._identity}")
def remove_from_starred(self, starred):
"""
@@ -1263,9 +1135,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(starred, github.Repository.Repository), starred
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"/user/starred/{starred._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/starred/{starred._identity}")
def remove_from_subscriptions(self, subscription):
"""
@@ -1274,9 +1144,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(subscription, github.Repository.Repository), subscription
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"/user/subscriptions/{subscription._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/user/subscriptions/{subscription._identity}")
def remove_from_watched(self, watched):
"""
@@ -1285,9 +1153,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(watched, github.Repository.Repository), watched
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"/repos/{watched._identity}/subscription"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"/repos/{watched._identity}/subscription")
def accept_invitation(self, invitation):
"""
@@ -1295,9 +1161,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
:param invitation: :class:`github.Invitation.Invitation` or int
:rtype: None
"""
assert isinstance(invitation, github.Invitation.Invitation) or isinstance(
invitation, int
)
assert isinstance(invitation, github.Invitation.Invitation) or isinstance(invitation, int)
if isinstance(invitation, github.Invitation.Invitation):
invitation = invitation.id
@@ -1333,9 +1197,7 @@ class AuthenticatedUser(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 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
@@ -1350,9 +1212,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
return github.Migration.Migration(
self._requester, headers, data, completed=True
)
return github.Migration.Migration(self._requester, headers, data, completed=True)
def get_migrations(self):
"""
@@ -1373,12 +1233,8 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
: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
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/user/memberships/orgs/{org}")
return github.Membership.Membership(self._requester, headers, data, completed=True)
def _initAttributes(self):
self._avatar_url = github.GithubObject.NotSet
@@ -1466,13 +1322,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "organizations_url" in attributes: # pragma no branch
self._organizations_url = self._makeStringAttribute(
attributes["organizations_url"]
)
self._organizations_url = self._makeStringAttribute(attributes["organizations_url"])
if "owned_private_repos" in attributes: # pragma no branch
self._owned_private_repos = self._makeIntAttribute(
attributes["owned_private_repos"]
)
self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"])
if "plan" in attributes: # pragma no branch
self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"])
if "private_gists" in attributes: # pragma no branch
@@ -1482,9 +1334,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
if "public_repos" in attributes: # pragma no branch
self._public_repos = self._makeIntAttribute(attributes["public_repos"])
if "received_events_url" in attributes: # pragma no branch
self._received_events_url = self._makeStringAttribute(
attributes["received_events_url"]
)
self._received_events_url = self._makeStringAttribute(attributes["received_events_url"])
if "repos_url" in attributes: # pragma no branch
self._repos_url = self._makeStringAttribute(attributes["repos_url"])
if "site_admin" in attributes: # pragma no branch
@@ -1492,13 +1342,9 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
if "starred_url" in attributes: # pragma no branch
self._starred_url = self._makeStringAttribute(attributes["starred_url"])
if "subscriptions_url" in attributes: # pragma no branch
self._subscriptions_url = self._makeStringAttribute(
attributes["subscriptions_url"]
)
self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"])
if "total_private_repos" in attributes: # pragma no branch
self._total_private_repos = self._makeIntAttribute(
attributes["total_private_repos"]
)
self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "updated_at" in attributes: # pragma no branch
@@ -1506,6 +1352,4 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "two_factor_authentication" in attributes:
self._two_factor_authentication = self._makeBoolAttribute(
attributes["two_factor_authentication"]
)
self._two_factor_authentication = self._makeBoolAttribute(attributes["two_factor_authentication"])
+1 -3
View File
@@ -123,9 +123,7 @@ class AuthenticatedUser(CompletableGithubObject):
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_gists(self, since: Union[datetime, _NotSetType] = ...) -> PaginatedList[Gist]: ...
def get_invitations(self) -> PaginatedList[Invitation]: ...
def get_issues(
self,
+2 -6
View File
@@ -127,9 +127,7 @@ class Authorization(github.GithubObject.CompletableGithubObject):
:param note_url: string
:rtype: None
"""
assert isinstance(scopes, _NotSetType) or all(
isinstance(element, str) for element in scopes
), scopes
assert isinstance(scopes, _NotSetType) or all(isinstance(element, str) for element in scopes), scopes
assert isinstance(add_scopes, _NotSetType) or all(
isinstance(element, str) for element in add_scopes
), add_scopes
@@ -149,9 +147,7 @@ class Authorization(github.GithubObject.CompletableGithubObject):
}
)
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def _initAttributes(self):
+22 -66
View File
@@ -92,15 +92,11 @@ class Branch(NonCompletableGithubObject):
def _useAttributes(self, attributes) -> None:
if "commit" in attributes: # pragma no branch
self._commit = self._makeClassAttribute(
github.Commit.Commit, attributes["commit"]
)
self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"])
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "protection_url" in attributes: # pragma no branch
self._protection_url = self._makeStringAttribute(
attributes["protection_url"]
)
self._protection_url = self._makeStringAttribute(attributes["protection_url"])
if "protected" in attributes: # pragma no branch
self._protected = self._makeBoolAttribute(attributes["protected"])
@@ -113,9 +109,7 @@ class Branch(NonCompletableGithubObject):
self.protection_url,
headers={"Accept": Consts.mediaTypeRequireMultipleApprovingReviews},
)
return github.BranchProtection.BranchProtection(
self._requester, headers, data, completed=True
)
return github.BranchProtection.BranchProtection(self._requester, headers, data, completed=True)
def edit_protection(
self,
@@ -156,25 +150,15 @@ class Branch(NonCompletableGithubObject):
assert is_optional_list(dismissal_apps, str), dismissal_apps
assert is_optional(dismiss_stale_reviews, bool), dismiss_stale_reviews
assert is_optional(require_code_owner_reviews, bool), require_code_owner_reviews
assert is_optional(
required_approving_review_count, int
), required_approving_review_count
assert is_optional(required_approving_review_count, int), required_approving_review_count
assert is_optional(required_linear_history, bool), required_linear_history
assert is_optional(allow_force_pushes, bool), allow_force_pushes
assert is_optional(
required_linear_history, bool
), required_conversation_resolution
assert is_optional(required_linear_history, bool), required_conversation_resolution
assert is_optional(lock_branch, bool), lock_branch
assert is_optional(allow_fork_syncing, bool), allow_fork_syncing
assert is_optional_list(
users_bypass_pull_request_allowances, str
), users_bypass_pull_request_allowances
assert is_optional_list(
teams_bypass_pull_request_allowances, str
), teams_bypass_pull_request_allowances
assert is_optional_list(
apps_bypass_pull_request_allowances, str
), apps_bypass_pull_request_allowances
assert is_optional_list(users_bypass_pull_request_allowances, str), users_bypass_pull_request_allowances
assert is_optional_list(teams_bypass_pull_request_allowances, str), teams_bypass_pull_request_allowances
assert is_optional_list(apps_bypass_pull_request_allowances, str), apps_bypass_pull_request_allowances
post_parameters: dict[str, Any] = {}
if is_defined(strict) or is_defined(contexts):
@@ -207,9 +191,7 @@ class Branch(NonCompletableGithubObject):
):
post_parameters["required_pull_request_reviews"] = {}
if is_defined(dismiss_stale_reviews):
post_parameters["required_pull_request_reviews"][
"dismiss_stale_reviews"
] = dismiss_stale_reviews
post_parameters["required_pull_request_reviews"]["dismiss_stale_reviews"] = dismiss_stale_reviews
if is_defined(require_code_owner_reviews):
post_parameters["required_pull_request_reviews"][
"require_code_owner_reviews"
@@ -228,23 +210,15 @@ class Branch(NonCompletableGithubObject):
dismissal_restrictions["apps"] = dismissal_apps
if dismissal_restrictions:
post_parameters["required_pull_request_reviews"][
"dismissal_restrictions"
] = dismissal_restrictions
post_parameters["required_pull_request_reviews"]["dismissal_restrictions"] = dismissal_restrictions
bypass_pull_request_allowances = {}
if is_defined(users_bypass_pull_request_allowances):
bypass_pull_request_allowances[
"users"
] = users_bypass_pull_request_allowances
bypass_pull_request_allowances["users"] = users_bypass_pull_request_allowances
if is_defined(teams_bypass_pull_request_allowances):
bypass_pull_request_allowances[
"teams"
] = teams_bypass_pull_request_allowances
bypass_pull_request_allowances["teams"] = teams_bypass_pull_request_allowances
if is_defined(apps_bypass_pull_request_allowances):
bypass_pull_request_allowances[
"apps"
] = apps_bypass_pull_request_allowances
bypass_pull_request_allowances["apps"] = apps_bypass_pull_request_allowances
if bypass_pull_request_allowances:
post_parameters["required_pull_request_reviews"][
@@ -279,9 +253,7 @@ class Branch(NonCompletableGithubObject):
else:
post_parameters["allow_force_pushes"] = None
if is_defined(required_conversation_resolution):
post_parameters[
"required_conversation_resolution"
] = required_conversation_resolution
post_parameters["required_conversation_resolution"] = required_conversation_resolution
else:
post_parameters["required_conversation_resolution"] = None
if is_defined(lock_branch):
@@ -318,12 +290,8 @@ class Branch(NonCompletableGithubObject):
:calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks <https://docs.github.com/en/rest/reference/repos#branches>`_
:rtype: :class:`github.RequiredStatusChecks.RequiredStatusChecks`
"""
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.protection_url}/required_status_checks"
)
return github.RequiredStatusChecks.RequiredStatusChecks(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.protection_url}/required_status_checks")
return github.RequiredStatusChecks.RequiredStatusChecks(self._requester, headers, data, completed=True)
def edit_required_status_checks(
self,
@@ -336,9 +304,7 @@ class Branch(NonCompletableGithubObject):
assert is_optional(strict, bool), strict
assert is_optional_list(contexts, str), contexts
post_parameters: dict[str, Any] = NotSet.remove_unset_items(
{"strict": strict, "contexts": contexts}
)
post_parameters: dict[str, Any] = NotSet.remove_unset_items({"strict": strict, "contexts": contexts})
headers, data = self._requester.requestJsonAndCheck(
"PATCH",
f"{self.protection_url}/required_status_checks",
@@ -383,9 +349,7 @@ class Branch(NonCompletableGithubObject):
assert is_optional_list(dismissal_teams, str), dismissal_teams
assert is_optional(dismiss_stale_reviews, bool), dismiss_stale_reviews
assert is_optional(require_code_owner_reviews, bool), require_code_owner_reviews
assert is_optional(
required_approving_review_count, int
), required_approving_review_count
assert is_optional(required_approving_review_count, int), required_approving_review_count
post_parameters: dict[str, Any] = NotSet.remove_unset_items(
{
@@ -422,26 +386,20 @@ class Branch(NonCompletableGithubObject):
"""
:calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.protection_url}/enforce_admins"
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.protection_url}/enforce_admins")
return data["enabled"]
def set_admin_enforcement(self) -> None:
"""
:calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.protection_url}/enforce_admins"
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.protection_url}/enforce_admins")
def remove_admin_enforcement(self) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.protection_url}/enforce_admins"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.protection_url}/enforce_admins")
def get_user_push_restrictions(self) -> PaginatedList[NamedUser]:
"""
@@ -535,9 +493,7 @@ class Branch(NonCompletableGithubObject):
"""
:calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions <https://docs.github.com/en/rest/reference/repos#branches>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.protection_url}/restrictions"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.protection_url}/restrictions")
def get_required_signatures(self) -> bool:
"""
+3 -9
View File
@@ -51,9 +51,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
self._url: Attribute[str] = NotSet
self._required_status_checks: Attribute[RequiredStatusChecks] = NotSet
self._enforce_admins: Attribute[bool] = NotSet
self._required_pull_request_reviews: Attribute[
RequiredPullRequestReviews
] = NotSet
self._required_pull_request_reviews: Attribute[RequiredPullRequestReviews] = NotSet
self._user_push_restrictions: Opt[str] = NotSet
self._team_push_restrictions: Opt[str] = NotSet
@@ -90,9 +88,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
def get_team_push_restrictions(self) -> PaginatedList[Team] | None:
if not is_defined(self._team_push_restrictions):
return None
return github.PaginatedList.PaginatedList(
github.Team.Team, self._requester, self._team_push_restrictions, None
)
return github.PaginatedList.PaginatedList(github.Team.Team, self._requester, self._team_push_restrictions, None)
def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "url" in attributes: # pragma no branch
@@ -103,9 +99,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
attributes["required_status_checks"],
)
if "enforce_admins" in attributes: # pragma no branch
self._enforce_admins = self._makeBoolAttribute(
attributes["enforce_admins"]["enabled"]
)
self._enforce_admins = self._makeBoolAttribute(attributes["enforce_admins"]["enabled"])
if "required_pull_request_reviews" in attributes: # pragma no branch
self._required_pull_request_reviews = self._makeClassAttribute(
github.RequiredPullRequestReviews.RequiredPullRequestReviews,
+14 -42
View File
@@ -37,9 +37,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"id": self._id.value, "conclusion": self._conclusion.value}
)
return self.get__repr__({"id": self._id.value, "conclusion": self._conclusion.value})
@property
def app(self):
@@ -210,29 +208,15 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert name is github.GithubObject.NotSet or isinstance(name, str), name
assert head_sha is github.GithubObject.NotSet or isinstance(
head_sha, str
), head_sha
assert details_url is github.GithubObject.NotSet or isinstance(
details_url, str
), details_url
assert external_id is github.GithubObject.NotSet or isinstance(
external_id, str
), external_id
assert head_sha is github.GithubObject.NotSet or isinstance(head_sha, str), head_sha
assert details_url is github.GithubObject.NotSet or isinstance(details_url, str), details_url
assert external_id is github.GithubObject.NotSet or isinstance(external_id, str), external_id
assert status is github.GithubObject.NotSet or isinstance(status, str), status
assert started_at is github.GithubObject.NotSet or isinstance(
started_at, datetime
), started_at
assert conclusion is github.GithubObject.NotSet or isinstance(
conclusion, str
), conclusion
assert completed_at is github.GithubObject.NotSet or isinstance(
completed_at, datetime
), completed_at
assert started_at is github.GithubObject.NotSet or isinstance(started_at, datetime), started_at
assert conclusion is github.GithubObject.NotSet or isinstance(conclusion, str), conclusion
assert completed_at is github.GithubObject.NotSet or isinstance(completed_at, datetime), completed_at
assert output is github.GithubObject.NotSet or isinstance(output, dict), output
assert actions is github.GithubObject.NotSet or all(
isinstance(element, dict) for element in actions
), actions
assert actions is github.GithubObject.NotSet or all(isinstance(element, dict) for element in actions), actions
post_parameters = dict()
if name is not github.GithubObject.NotSet:
@@ -248,9 +232,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
if started_at is not github.GithubObject.NotSet:
post_parameters["started_at"] = started_at.strftime("%Y-%m-%dT%H:%M:%SZ")
if completed_at is not github.GithubObject.NotSet:
post_parameters["completed_at"] = completed_at.strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
post_parameters["completed_at"] = completed_at.strftime("%Y-%m-%dT%H:%M:%SZ")
if conclusion is not github.GithubObject.NotSet:
post_parameters["conclusion"] = conclusion
if output is not github.GithubObject.NotSet:
@@ -258,9 +240,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
if actions is not github.GithubObject.NotSet:
post_parameters["actions"] = actions
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def _initAttributes(self):
@@ -283,16 +263,10 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "app" in attributes: # pragma no branch
self._app = self._makeClassAttribute(
github.GithubApp.GithubApp, attributes["app"]
)
self._app = self._makeClassAttribute(github.GithubApp.GithubApp, attributes["app"])
# This only gives us a dictionary with `id` attribute of `check_suite`
if (
"check_suite" in attributes and "id" in attributes["check_suite"]
): # pragma no branch
self._check_suite_id = self._makeIntAttribute(
attributes["check_suite"]["id"]
)
if "check_suite" in attributes and "id" in attributes["check_suite"]: # pragma no branch
self._check_suite_id = self._makeIntAttribute(attributes["check_suite"]["id"])
if "completed_at" in attributes: # pragma no branch
self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"])
if "conclusion" in attributes: # pragma no branch
@@ -312,9 +286,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject):
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "output" in attributes: # pragma no branch
self._output = self._makeClassAttribute(
github.CheckRunOutput.CheckRunOutput, attributes["output"]
)
self._output = self._makeClassAttribute(github.CheckRunOutput.CheckRunOutput, attributes["output"])
if "pull_requests" in attributes: # pragma no branch
self._pull_requests = self._makeListOfClassesAttribute(
github.PullRequest.PullRequest, attributes["pull_requests"]
+1 -3
View File
@@ -23,9 +23,7 @@ class CheckRun(CompletableGithubObject):
started_at: Union[_NotSetType, datetime] = ...,
conclusion: Union[_NotSetType, str] = ...,
completed_at: Union[_NotSetType, datetime] = ...,
output: Union[
_NotSetType, Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]
] = ...,
output: Union[_NotSetType, Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]] = ...,
actions: Union[_NotSetType, List[Dict[str, str]]] = ...,
) -> None: ...
@property
+1 -3
View File
@@ -81,9 +81,7 @@ class CheckRunAnnotation(NonCompletableGithubObject):
def _useAttributes(self, attributes) -> None:
if "annotation_level" in attributes: # pragma no branch
self._annotation_level = self._makeStringAttribute(
attributes["annotation_level"]
)
self._annotation_level = self._makeStringAttribute(attributes["annotation_level"])
if "end_column" in attributes: # pragma no branch
self._end_column = self._makeIntAttribute(attributes["end_column"])
if "end_line" in attributes: # pragma no branch
+2 -6
View File
@@ -58,13 +58,9 @@ class CheckRunOutput(NonCompletableGithubObject):
def _useAttributes(self, attributes) -> None:
if "annotations_count" in attributes: # pragma no branch
self._annotations_count = self._makeIntAttribute(
attributes["annotations_count"]
)
self._annotations_count = self._makeIntAttribute(attributes["annotations_count"])
if "annotations_url" in attributes: # pragma no branch
self._annotations_url = self._makeStringAttribute(
attributes["annotations_url"]
)
self._annotations_url = self._makeStringAttribute(attributes["annotations_url"])
if "summary" in attributes: # pragma no branch
self._summary = self._makeStringAttribute(attributes["summary"])
if "text" in attributes: # pragma no branch
+7 -21
View File
@@ -165,9 +165,7 @@ class CheckSuite(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
request_headers = {"Accept": "application/vnd.github.v3+json"}
status, _, _ = self._requester.requestJson(
"POST", f"{self.url}/rerequest", headers=request_headers
)
status, _, _ = self._requester.requestJson("POST", f"{self.url}/rerequest", headers=request_headers)
return status == 201
def get_check_runs(
@@ -183,9 +181,7 @@ class CheckSuite(github.GithubObject.CompletableGithubObject):
:param filter: string
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CheckRun.CheckRun`
"""
assert check_name is github.GithubObject.NotSet or isinstance(
check_name, str
), check_name
assert check_name is github.GithubObject.NotSet or isinstance(check_name, str), check_name
assert status is github.GithubObject.NotSet or isinstance(status, str), status
assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter
url_parameters = dict()
@@ -226,15 +222,11 @@ class CheckSuite(github.GithubObject.CompletableGithubObject):
if "after" in attributes: # pragma no branch
self._after = self._makeStringAttribute(attributes["after"])
if "app" in attributes: # pragma no branch
self._app = self._makeClassAttribute(
github.GithubApp.GithubApp, attributes["app"]
)
self._app = self._makeClassAttribute(github.GithubApp.GithubApp, attributes["app"])
if "before" in attributes: # pragma no branch
self._before = self._makeStringAttribute(attributes["before"])
if "check_runs_url" in attributes: # pragma no branch
self._check_runs_url = self._makeStringAttribute(
attributes["check_runs_url"]
)
self._check_runs_url = self._makeStringAttribute(attributes["check_runs_url"])
if "conclusion" in attributes: # pragma no branch
self._conclusion = self._makeStringAttribute(attributes["conclusion"])
if "created_at" in attributes: # pragma no branch
@@ -246,25 +238,19 @@ class CheckSuite(github.GithubObject.CompletableGithubObject):
# The GitCommit object only looks for 'sha'
if "id" in attributes["head_commit"]:
attributes["head_commit"]["sha"] = attributes["head_commit"]["id"]
self._head_commit = self._makeClassAttribute(
github.GitCommit.GitCommit, attributes["head_commit"]
)
self._head_commit = self._makeClassAttribute(github.GitCommit.GitCommit, attributes["head_commit"])
if "head_sha" in attributes: # pragma no branch
self._head_sha = self._makeStringAttribute(attributes["head_sha"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "latest_check_runs_count" in attributes: # pragma no branch
self._latest_check_runs_count = self._makeIntAttribute(
attributes["latest_check_runs_count"]
)
self._latest_check_runs_count = self._makeIntAttribute(attributes["latest_check_runs_count"])
if "pull_requests" in attributes: # pragma no branch
self._pull_requests = self._makeListOfClassesAttribute(
github.PullRequest.PullRequest, attributes["pull_requests"]
)
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "status" in attributes: # pragma no branch
self._status = self._makeStringAttribute(attributes["status"])
if "updated_at" in attributes: # pragma no branch
+1 -3
View File
@@ -46,6 +46,4 @@ class CheckSuite(CompletableGithubObject):
@property
def url(self) -> str: ...
def rerequest(self) -> bool: ...
def get_check_runs(
self, check_name: str, status: str, filter: str
) -> PaginatedList[CheckRun]: ...
def get_check_runs(self, check_name: str, status: str, filter: str) -> PaginatedList[CheckRun]: ...
+4 -12
View File
@@ -154,26 +154,18 @@ class CodeScanAlert(github.GithubObject.NonCompletableGithubObject):
if "number" in attributes: # pragma no branch
self._number = self._makeIntAttribute(attributes["number"])
if "rule" in attributes: # pragma no branch
self._rule = self._makeClassAttribute(
github.CodeScanRule.CodeScanRule, attributes["rule"]
)
self._rule = self._makeClassAttribute(github.CodeScanRule.CodeScanRule, attributes["rule"])
if "tool" in attributes: # pragma no branch
self._tool = self._makeClassAttribute(
github.CodeScanTool.CodeScanTool, attributes["tool"]
)
self._tool = self._makeClassAttribute(github.CodeScanTool.CodeScanTool, attributes["tool"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "dismissed_at" in attributes: # pragma no branch
self._dismissed_at = self._makeDatetimeAttribute(attributes["dismissed_at"])
if "dismissed_by" in attributes: # pragma no branch
self._dismissed_by = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["dismissed_by"]
)
self._dismissed_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["dismissed_by"])
if "dismissed_reason" in attributes: # pragma no branch
self._dismissed_reason = self._makeStringAttribute(
attributes["dismissed_reason"]
)
self._dismissed_reason = self._makeStringAttribute(attributes["dismissed_reason"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+1 -3
View File
@@ -120,6 +120,4 @@ class CodeScanAlertInstance(github.GithubObject.NonCompletableGithubObject):
attributes["location"],
)
if "classifications" in attributes: # pragma no branch
self._classifications = self._makeListOfStringsAttribute(
attributes["classifications"]
)
self._classifications = self._makeListOfStringsAttribute(attributes["classifications"])
+1 -3
View File
@@ -82,8 +82,6 @@ class CodeScanRule(github.GithubObject.NonCompletableGithubObject):
if "severity" in attributes: # pragma no branch
self._severity = self._makeStringAttribute(attributes["severity"])
if "security_severity_level" in attributes: # pragma no branch
self._security_severity_level = self._makeStringAttribute(
attributes["security_severity_level"]
)
self._security_severity_level = self._makeStringAttribute(attributes["security_severity_level"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
+17 -51
View File
@@ -149,9 +149,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
assert isinstance(body, str), body
assert line is github.GithubObject.NotSet or isinstance(line, int), line
assert path is github.GithubObject.NotSet or isinstance(path, str), path
assert position is github.GithubObject.NotSet or isinstance(
position, int
), position
assert position is github.GithubObject.NotSet or isinstance(position, int), position
post_parameters = {
"body": body,
}
@@ -161,12 +159,8 @@ class Commit(github.GithubObject.CompletableGithubObject):
post_parameters["path"] = path
if position is not github.GithubObject.NotSet:
post_parameters["position"] = position
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/comments", input=post_parameters
)
return github.CommitComment.CommitComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/comments", input=post_parameters)
return github.CommitComment.CommitComment(self._requester, headers, data, completed=True)
def create_status(
self,
@@ -184,15 +178,9 @@ class Commit(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.CommitStatus.CommitStatus`
"""
assert isinstance(state, str), state
assert target_url is github.GithubObject.NotSet or isinstance(
target_url, str
), target_url
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert context is github.GithubObject.NotSet or isinstance(
context, str
), context
assert target_url is github.GithubObject.NotSet or isinstance(target_url, str), target_url
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert context is github.GithubObject.NotSet or isinstance(context, str), context
post_parameters = {
"state": state,
}
@@ -207,9 +195,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
f"{self._parentUrl(self._parentUrl(self.url))}/statuses/{self.sha}",
input=post_parameters,
)
return github.CommitStatus.CommitStatus(
self._requester, headers, data, completed=True
)
return github.CommitStatus.CommitStatus(self._requester, headers, data, completed=True)
def get_comments(self):
"""
@@ -241,9 +227,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.CommitCombinedStatus.CommitCombinedStatus`
"""
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/status")
return github.CommitCombinedStatus.CommitCombinedStatus(
self._requester, headers, data, completed=True
)
return github.CommitCombinedStatus.CommitCombinedStatus(self._requester, headers, data, completed=True)
def get_pulls(self):
"""
@@ -271,9 +255,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
:param filter: string
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CheckRun.CheckRun`
"""
assert check_name is github.GithubObject.NotSet or isinstance(
check_name, str
), check_name
assert check_name is github.GithubObject.NotSet or isinstance(check_name, str), check_name
assert status is github.GithubObject.NotSet or isinstance(status, str), status
assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter
url_parameters = dict()
@@ -292,9 +274,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
list_item="check_runs",
)
def get_check_suites(
self, app_id=github.GithubObject.NotSet, check_name=github.GithubObject.NotSet
):
def get_check_suites(self, app_id=github.GithubObject.NotSet, check_name=github.GithubObject.NotSet):
"""
:class: `GET /repos/{owner}/{repo}/commits/{ref}/check-suites <https://docs.github.com/en/rest/reference/checks#list-check-suites-for-a-git-reference>`_
:param app_id: int
@@ -302,9 +282,7 @@ class Commit(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CheckSuite.CheckSuite`
"""
assert app_id is github.GithubObject.NotSet or isinstance(app_id, int), app_id
assert check_name is github.GithubObject.NotSet or isinstance(
check_name, str
), check_name
assert check_name is github.GithubObject.NotSet or isinstance(check_name, str), check_name
parameters = dict()
if app_id is not github.GithubObject.NotSet:
parameters["app_id"] = app_id
@@ -338,34 +316,22 @@ class Commit(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
self._author = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["author"]
)
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "comments_url" in attributes: # pragma no branch
self._comments_url = self._makeStringAttribute(attributes["comments_url"])
if "commit" in attributes: # pragma no branch
self._commit = self._makeClassAttribute(
github.GitCommit.GitCommit, attributes["commit"]
)
self._commit = self._makeClassAttribute(github.GitCommit.GitCommit, attributes["commit"])
if "committer" in attributes: # pragma no branch
self._committer = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["committer"]
)
self._committer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["committer"])
if "files" in attributes: # pragma no branch
self._files = self._makeListOfClassesAttribute(
github.File.File, attributes["files"]
)
self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "parents" in attributes: # pragma no branch
self._parents = self._makeListOfClassesAttribute(
Commit, attributes["parents"]
)
self._parents = self._makeListOfClassesAttribute(Commit, attributes["parents"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "stats" in attributes: # pragma no branch
self._stats = self._makeClassAttribute(
github.CommitStats.CommitStats, attributes["stats"]
)
self._stats = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["stats"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+2 -6
View File
@@ -107,10 +107,6 @@ class CommitCombinedStatus(github.GithubObject.NonCompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "statuses" in attributes: # pragma no branch
self._statuses = self._makeListOfClassesAttribute(
github.CommitStatus.CommitStatus, attributes["statuses"]
)
self._statuses = self._makeListOfClassesAttribute(github.CommitStatus.CommitStatus, attributes["statuses"])
+2 -6
View File
@@ -150,9 +150,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_reactions(self):
@@ -238,6 +236,4 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+1 -3
View File
@@ -126,9 +126,7 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "id" in attributes: # pragma no branch
+4 -12
View File
@@ -160,27 +160,19 @@ class Comparison(github.GithubObject.CompletableGithubObject):
if "ahead_by" in attributes: # pragma no branch
self._ahead_by = self._makeIntAttribute(attributes["ahead_by"])
if "base_commit" in attributes: # pragma no branch
self._base_commit = self._makeClassAttribute(
github.Commit.Commit, attributes["base_commit"]
)
self._base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["base_commit"])
if "behind_by" in attributes: # pragma no branch
self._behind_by = self._makeIntAttribute(attributes["behind_by"])
if "commits" in attributes: # pragma no branch
self._commits = self._makeListOfClassesAttribute(
github.Commit.Commit, attributes["commits"]
)
self._commits = self._makeListOfClassesAttribute(github.Commit.Commit, attributes["commits"])
if "diff_url" in attributes: # pragma no branch
self._diff_url = self._makeStringAttribute(attributes["diff_url"])
if "files" in attributes: # pragma no branch
self._files = self._makeListOfClassesAttribute(
github.File.File, attributes["files"]
)
self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "merge_base_commit" in attributes: # pragma no branch
self._merge_base_commit = self._makeClassAttribute(
github.Commit.Commit, attributes["merge_base_commit"]
)
self._merge_base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["merge_base_commit"])
if "patch_url" in attributes: # pragma no branch
self._patch_url = self._makeStringAttribute(attributes["patch_url"])
if "permalink_url" in attributes: # pragma no branch
+1 -3
View File
@@ -92,9 +92,7 @@ mediaTypeOrganizationInvitationPreview = "application/vnd.github.dazzler-preview
mediaTypeTeamDiscussionsPreview = "application/vnd.github.echo-preview+json"
# https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/
mediaTypeRequireMultipleApprovingReviews = (
"application/vnd.github.luke-cage-preview+json"
)
mediaTypeRequireMultipleApprovingReviews = "application/vnd.github.luke-cage-preview+json"
# https://developer.github.com/changes/2018-05-24-user-migration-api/
mediaTypeMigrationPreview = "application/vnd.github.wyandotte-preview+json"
+5 -15
View File
@@ -122,13 +122,9 @@ class ContentFile(github.GithubObject.CompletableGithubObject):
"""
if self._repository is github.GithubObject.NotSet:
# The repository was not set automatically, so it must be looked up by url.
repo_url = "/".join(
self.url.split("/")[:6]
) # pragma no cover (Should be covered)
repo_url = "/".join(self.url.split("/")[:6]) # pragma no cover (Should be covered)
self._repository = github.GithubObject._ValuedAttribute(
github.Repository.Repository(
self._requester, self._headers, {"url": repo_url}, completed=False
)
github.Repository.Repository(self._requester, self._headers, {"url": repo_url}, completed=False)
) # pragma no cover (Should be covered)
return self._repository.value
@@ -199,17 +195,13 @@ class ContentFile(github.GithubObject.CompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "license" in attributes: # pragma no branch
self._license = self._makeClassAttribute(
github.License.License, attributes["license"]
)
self._license = self._makeClassAttribute(github.License.License, attributes["license"])
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "path" in attributes: # pragma no branch
self._path = self._makeStringAttribute(attributes["path"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "size" in attributes: # pragma no branch
@@ -219,6 +211,4 @@ class ContentFile(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "text_matches" in attributes: # pragma no branch
self._text_matches = self._makeListOfDictsAttribute(
attributes["text_matches"]
)
self._text_matches = self._makeListOfDictsAttribute(attributes["text_matches"])
+12 -36
View File
@@ -188,9 +188,7 @@ class Deployment(github.GithubObject.CompletableGithubObject):
f"{self.url}/statuses/{id_}",
headers={"Accept": self._get_accept_header()},
)
return github.DeploymentStatus.DeploymentStatus(
self._requester, headers, data, completed=True
)
return github.DeploymentStatus.DeploymentStatus(self._requester, headers, data, completed=True)
def create_status(
self,
@@ -212,21 +210,11 @@ class Deployment(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.DeploymentStatus.DeploymentStatus`
"""
assert isinstance(state, str), state
assert target_url is github.GithubObject.NotSet or isinstance(
target_url, str
), target_url
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert environment is github.GithubObject.NotSet or isinstance(
environment, str
), environment
assert environment_url is github.GithubObject.NotSet or isinstance(
environment_url, str
), environment_url
assert auto_inactive is github.GithubObject.NotSet or isinstance(
auto_inactive, bool
), auto_inactive
assert target_url is github.GithubObject.NotSet or isinstance(target_url, str), target_url
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert environment is github.GithubObject.NotSet or isinstance(environment, str), environment
assert environment_url is github.GithubObject.NotSet or isinstance(environment_url, str), environment_url
assert auto_inactive is github.GithubObject.NotSet or isinstance(auto_inactive, bool), auto_inactive
post_parameters = {"state": state}
if target_url is not github.GithubObject.NotSet:
@@ -246,9 +234,7 @@ class Deployment(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": self._get_accept_header()},
)
return github.DeploymentStatus.DeploymentStatus(
self._requester, headers, data, completed=True
)
return github.DeploymentStatus.DeploymentStatus(self._requester, headers, data, completed=True)
@staticmethod
def _get_accept_header():
@@ -281,15 +267,11 @@ class Deployment(github.GithubObject.CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "production_environment" in attributes: # pragma no branch
self._production_environment = self._makeBoolAttribute(
attributes["production_environment"]
)
self._production_environment = self._makeBoolAttribute(attributes["production_environment"])
if "ref" in attributes: # pragma no branch
self._ref = self._makeStringAttribute(attributes["ref"])
if "transient_environment" in attributes: # pragma no branch
self._transient_environment = self._makeBoolAttribute(
attributes["transient_environment"]
)
self._transient_environment = self._makeBoolAttribute(attributes["transient_environment"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "sha" in attributes: # pragma no branch
@@ -299,17 +281,13 @@ class Deployment(github.GithubObject.CompletableGithubObject):
if "payload" in attributes: # pragma no branch
self._payload = self._makeDictAttribute(attributes["payload"])
if "original_environment" in attributes: # pragma no branch
self._original_environment = self._makeStringAttribute(
attributes["original_environment"]
)
self._original_environment = self._makeStringAttribute(attributes["original_environment"])
if "environment" in attributes: # pragma no branch
self._environment = self._makeStringAttribute(attributes["environment"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "updated_at" in attributes: # pragma no branch
@@ -317,6 +295,4 @@ class Deployment(github.GithubObject.CompletableGithubObject):
if "statuses_url" in attributes: # pragma no branch
self._statuses_url = self._makeStringAttribute(attributes["statuses_url"])
if "repository_url" in attributes: # pragma no branch
self._repository_url = self._makeStringAttribute(
attributes["repository_url"]
)
self._repository_url = self._makeStringAttribute(attributes["repository_url"])
+4 -12
View File
@@ -153,9 +153,7 @@ class DeploymentStatus(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "environment_url" in attributes: # pragma no branch
self._environment_url = self._makeStringAttribute(
attributes["environment_url"]
)
self._environment_url = self._makeStringAttribute(attributes["environment_url"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "id" in attributes: # pragma no branch
@@ -165,21 +163,15 @@ class DeploymentStatus(github.GithubObject.CompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "deployment_url" in attributes: # pragma no branch
self._deployment_url = self._makeStringAttribute(
attributes["deployment_url"]
)
self._deployment_url = self._makeStringAttribute(attributes["deployment_url"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "environment" in attributes: # pragma no branch
self._environment = self._makeStringAttribute(attributes["environment"])
if "repository_url" in attributes: # pragma no branch
self._repository_url = self._makeStringAttribute(
attributes["repository_url"]
)
self._repository_url = self._makeStringAttribute(attributes["repository_url"])
if "state" in attributes: # pragma no branch
self._state = self._makeStringAttribute(attributes["state"])
if "target_url" in attributes: # pragma no branch
+3 -9
View File
@@ -46,13 +46,9 @@ class EnvironmentDeploymentBranchPolicy(github.GithubObject.NonCompletableGithub
def _useAttributes(self, attributes):
if "protected_branches" in attributes: # pragma no branch
self._protected_branches = self._makeBoolAttribute(
attributes["protected_branches"]
)
self._protected_branches = self._makeBoolAttribute(attributes["protected_branches"])
if "custom_branch_policies" in attributes: # pragma no branch
self._custom_branch_policies = self._makeBoolAttribute(
attributes["custom_branch_policies"]
)
self._custom_branch_policies = self._makeBoolAttribute(attributes["custom_branch_policies"])
class EnvironmentDeploymentBranchPolicyParams:
@@ -60,9 +56,7 @@ class EnvironmentDeploymentBranchPolicyParams:
This class presents the deployment branch policy parameters as can be configured for an Environment.
"""
def __init__(
self, protected_branches: bool = False, custom_branch_policies: bool = False
):
def __init__(self, protected_branches: bool = False, custom_branch_policies: bool = False):
assert isinstance(protected_branches, bool)
assert isinstance(custom_branch_policies, bool)
self.protected_branches = protected_branches
+1 -3
View File
@@ -49,9 +49,7 @@ class EnvironmentProtectionRule(github.GithubObject.NonCompletableGithubObject):
@property
def reviewers(
self,
) -> List[
github.EnvironmentProtectionRuleReviewer.EnvironmentProtectionRuleReviewer
]:
) -> List[github.EnvironmentProtectionRuleReviewer.EnvironmentProtectionRuleReviewer]:
return self._reviewers.value
@property
+2 -6
View File
@@ -53,13 +53,9 @@ class EnvironmentProtectionRuleReviewer(github.GithubObject.NonCompletableGithub
if "reviewer" in attributes: # pragma no branch
assert self._type.value in ("User", "Team")
if self._type.value == "User":
self._reviewer = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["reviewer"]
)
self._reviewer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["reviewer"])
elif self._type.value == "Team":
self._reviewer = self._makeClassAttribute(
github.Team.Team, attributes["reviewer"]
)
self._reviewer = self._makeClassAttribute(github.Team.Team, attributes["reviewer"])
class ReviewerParams:
+3 -9
View File
@@ -110,24 +110,18 @@ class Event(github.GithubObject.NonCompletableGithubObject):
def _useAttributes(self, attributes):
if "actor" in attributes: # pragma no branch
self._actor = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["actor"]
)
self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "id" in attributes: # pragma no branch
self._id = self._makeStringAttribute(attributes["id"])
if "org" in attributes: # pragma no branch
self._org = self._makeClassAttribute(
github.Organization.Organization, attributes["org"]
)
self._org = self._makeClassAttribute(github.Organization.Organization, attributes["org"])
if "payload" in attributes: # pragma no branch
self._payload = self._makeDictAttribute(attributes["payload"])
if "public" in attributes: # pragma no branch
self._public = self._makeBoolAttribute(attributes["public"])
if "repo" in attributes: # pragma no branch
self._repo = self._makeClassAttribute(
github.Repository.Repository, attributes["repo"]
)
self._repo = self._makeClassAttribute(github.Repository.Repository, attributes["repo"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
+2 -6
View File
@@ -39,9 +39,7 @@ class File(github.GithubObject.NonCompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"sha": self._sha.value, "filename": self._filename.value}
)
return self.get__repr__({"sha": self._sha.value, "filename": self._filename.value})
@property
def additions(self):
@@ -149,9 +147,7 @@ class File(github.GithubObject.NonCompletableGithubObject):
if "patch" in attributes: # pragma no branch
self._patch = self._makeStringAttribute(attributes["patch"])
if "previous_filename" in attributes: # pragma no branch
self._previous_filename = self._makeStringAttribute(
attributes["previous_filename"]
)
self._previous_filename = self._makeStringAttribute(attributes["previous_filename"])
if "raw_url" in attributes: # pragma no branch
self._raw_url = self._makeStringAttribute(attributes["raw_url"])
if "sha" in attributes: # pragma no branch
+13 -39
View File
@@ -209,12 +209,8 @@ class Gist(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/comments", input=post_parameters
)
return github.GistComment.GistComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/comments", input=post_parameters)
return github.GistComment.GistComment(self._requester, headers, data, completed=True)
def create_fork(self):
"""
@@ -231,33 +227,23 @@ class Gist(github.GithubObject.CompletableGithubObject):
"""
headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
def edit(
self, description=github.GithubObject.NotSet, files=github.GithubObject.NotSet
):
def edit(self, description=github.GithubObject.NotSet, files=github.GithubObject.NotSet):
"""
:calls: `PATCH /gists/{id} <https://docs.github.com/en/rest/reference/gists>`_
:param description: string
:param files: dict of string to :class:`github.InputFileContent.InputFileContent`
:rtype: None
"""
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert files is github.GithubObject.NotSet or all(
element is None or isinstance(element, github.InputFileContent)
for element in files.values()
element is None or isinstance(element, github.InputFileContent) for element in files.values()
), files
post_parameters = dict()
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if files is not github.GithubObject.NotSet:
post_parameters["files"] = {
key: None if value is None else value._identity
for key, value in files.items()
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
post_parameters["files"] = {key: None if value is None else value._identity for key, value in files.items()}
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_comment(self, id):
@@ -267,12 +253,8 @@ class Gist(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.GistComment.GistComment`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/comments/{id}"
)
return github.GistComment.GistComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/comments/{id}")
return github.GistComment.GistComment(self._requester, headers, data, completed=True)
def get_comments(self):
"""
@@ -299,9 +281,7 @@ class Gist(github.GithubObject.CompletableGithubObject):
:calls: `DELETE /gists/{id}/star <https://docs.github.com/en/rest/reference/gists>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/star"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/star")
def set_starred(self):
"""
@@ -343,9 +323,7 @@ class Gist(github.GithubObject.CompletableGithubObject):
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "files" in attributes: # pragma no branch
self._files = self._makeDictOfStringsToClassesAttribute(
github.GistFile.GistFile, attributes["files"]
)
self._files = self._makeDictOfStringsToClassesAttribute(github.GistFile.GistFile, attributes["files"])
if "fork_of" in attributes: # pragma no branch
self._fork_of = self._makeClassAttribute(Gist, attributes["fork_of"])
if "forks" in attributes: # pragma no branch
@@ -365,9 +343,7 @@ class Gist(github.GithubObject.CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeStringAttribute(attributes["id"])
if "owner" in attributes: # pragma no branch
self._owner = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["owner"]
)
self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
if "public" in attributes: # pragma no branch
self._public = self._makeBoolAttribute(attributes["public"])
if "updated_at" in attributes: # pragma no branch
@@ -375,6 +351,4 @@ class Gist(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+2 -6
View File
@@ -105,9 +105,7 @@ class GistComment(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def _initAttributes(self):
@@ -130,6 +128,4 @@ class GistComment(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+6 -18
View File
@@ -231,9 +231,7 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "change_status" in attributes: # pragma no branch
self._change_status = self._makeClassAttribute(
github.CommitStats.CommitStats, attributes["change_status"]
)
self._change_status = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["change_status"])
if "comments" in attributes: # pragma no branch
self._comments = self._makeIntAttribute(attributes["comments"])
if "comments_url" in attributes: # pragma no branch
@@ -247,13 +245,9 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject):
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "files" in attributes: # pragma no branch
self._files = self._makeDictOfStringsToClassesAttribute(
github.GistFile.GistFile, attributes["files"]
)
self._files = self._makeDictOfStringsToClassesAttribute(github.GistFile.GistFile, attributes["files"])
if "forks" in attributes: # pragma no branch
self._forks = self._makeListOfClassesAttribute(
github.Gist.Gist, attributes["forks"]
)
self._forks = self._makeListOfClassesAttribute(github.Gist.Gist, attributes["forks"])
if "forks_url" in attributes: # pragma no branch
self._forks_url = self._makeStringAttribute(attributes["forks_url"])
if "git_pull_url" in attributes: # pragma no branch
@@ -261,17 +255,13 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject):
if "git_push_url" in attributes: # pragma no branch
self._git_push_url = self._makeStringAttribute(attributes["git_push_url"])
if "history" in attributes: # pragma no branch
self._history = self._makeListOfClassesAttribute(
GistHistoryState, attributes["history"]
)
self._history = self._makeListOfClassesAttribute(GistHistoryState, attributes["history"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "id" in attributes: # pragma no branch
self._id = self._makeStringAttribute(attributes["id"])
if "owner" in attributes: # pragma no branch
self._owner = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["owner"]
)
self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
if "public" in attributes: # pragma no branch
self._public = self._makeBoolAttribute(attributes["public"])
if "updated_at" in attributes: # pragma no branch
@@ -279,8 +269,6 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
if "version" in attributes: # pragma no branch
self._version = self._makeStringAttribute(attributes["version"])
+4 -12
View File
@@ -121,26 +121,18 @@ class GitCommit(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
self._author = self._makeClassAttribute(
github.GitAuthor.GitAuthor, attributes["author"]
)
self._author = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["author"])
if "committer" in attributes: # pragma no branch
self._committer = self._makeClassAttribute(
github.GitAuthor.GitAuthor, attributes["committer"]
)
self._committer = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["committer"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "message" in attributes: # pragma no branch
self._message = self._makeStringAttribute(attributes["message"])
if "parents" in attributes: # pragma no branch
self._parents = self._makeListOfClassesAttribute(
GitCommit, attributes["parents"]
)
self._parents = self._makeListOfClassesAttribute(GitCommit, attributes["parents"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "tree" in attributes: # pragma no branch
self._tree = self._makeClassAttribute(
github.GitTree.GitTree, attributes["tree"]
)
self._tree = self._makeClassAttribute(github.GitTree.GitTree, attributes["tree"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+3 -13
View File
@@ -34,13 +34,7 @@ from typing import TYPE_CHECKING
import github.GithubObject
import github.GitObject
from github.GithubObject import (
Attribute,
CompletableGithubObject,
NotSet,
Opt,
is_optional,
)
from github.GithubObject import Attribute, CompletableGithubObject, NotSet, Opt, is_optional
if TYPE_CHECKING:
from github.GitObject import GitObject
@@ -87,16 +81,12 @@ class GitRef(CompletableGithubObject):
assert isinstance(sha, str), sha
assert is_optional(force, bool), force
post_parameters = NotSet.remove_unset_items({"sha": sha, "force": force})
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def _useAttributes(self, attributes) -> None:
if "object" in attributes: # pragma no branch
self._object = self._makeClassAttribute(
github.GitObject.GitObject, attributes["object"]
)
self._object = self._makeClassAttribute(github.GitObject.GitObject, attributes["object"])
if "ref" in attributes: # pragma no branch
self._ref = self._makeStringAttribute(attributes["ref"])
if "url" in attributes: # pragma no branch
+8 -26
View File
@@ -227,12 +227,8 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
# altogether in that case, in order to match the Github API behaviour. Only send it when set.
if target_commitish is not github.GithubObject.NotSet:
post_parameters["target_commitish"] = target_commitish
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
return github.GitRelease.GitRelease(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
return github.GitRelease.GitRelease(self._requester, headers, data, completed=True)
def upload_asset(
self,
@@ -268,9 +264,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
headers=headers,
input=path,
)
return github.GitReleaseAsset.GitReleaseAsset(
self._requester, resp_headers, data, completed=True
)
return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True)
def upload_asset_from_memory(
self,
@@ -295,11 +289,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
assert isinstance(label, str), label
post_parameters = {"label": label, "name": name}
content_type = (
content_type
if content_type is not github.GithubObject.NotSet
else Consts.defaultMediaType
)
content_type = content_type if content_type is not github.GithubObject.NotSet else Consts.defaultMediaType
headers = {"Content-Type": content_type, "Content-Length": str(file_size)}
resp_headers, data = self._requester.requestMemoryBlobAndCheck(
@@ -309,9 +299,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
headers=headers,
file_like=file_like,
)
return github.GitReleaseAsset.GitReleaseAsset(
self._requester, resp_headers, data, completed=True
)
return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True)
def get_assets(self):
"""
@@ -354,21 +342,15 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
if "tag_name" in attributes:
self._tag_name = self._makeStringAttribute(attributes["tag_name"])
if "target_commitish" in attributes:
self._target_commitish = self._makeStringAttribute(
attributes["target_commitish"]
)
self._target_commitish = self._makeStringAttribute(attributes["target_commitish"])
if "draft" in attributes:
self._draft = self._makeBoolAttribute(attributes["draft"])
if "prerelease" in attributes:
self._prerelease = self._makeBoolAttribute(attributes["prerelease"])
if "generate_release_notes" in attributes:
self._generate_release_notes = self._makeBoolAttribute(
attributes["generate_release_notes"]
)
self._generate_release_notes = self._makeBoolAttribute(attributes["generate_release_notes"])
if "author" in attributes:
self._author = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["author"]
)
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "url" in attributes:
self._url = self._makeStringAttribute(attributes["url"])
if "upload_url" in attributes:
+3 -9
View File
@@ -146,9 +146,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject):
assert isinstance(name, str), name
assert isinstance(label, str), label
post_parameters = {"name": name, "label": label}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
return GitReleaseAsset(self._requester, headers, data, completed=True)
def _initAttributes(self):
@@ -175,9 +173,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject):
if "label" in attributes: # pragma no branch
self._label = self._makeStringAttribute(attributes["label"])
if "uploader" in attributes: # pragma no branch
self._uploader = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["uploader"]
)
self._uploader = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["uploader"])
if "content_type" in attributes: # pragma no branch
self._content_type = self._makeStringAttribute(attributes["content_type"])
if "state" in attributes: # pragma no branch
@@ -191,6 +187,4 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject):
if "updated_at" in attributes: # pragma no branch
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "browser_download_url" in attributes: # pragma no branch
self._browser_download_url = self._makeStringAttribute(
attributes["browser_download_url"]
)
self._browser_download_url = self._makeStringAttribute(attributes["browser_download_url"])
+2 -6
View File
@@ -93,16 +93,12 @@ class GitTag(CompletableGithubObject):
if "message" in attributes: # pragma no branch
self._message = self._makeStringAttribute(attributes["message"])
if "object" in attributes: # pragma no branch
self._object = self._makeClassAttribute(
github.GitObject.GitObject, attributes["object"]
)
self._object = self._makeClassAttribute(github.GitObject.GitObject, attributes["object"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "tag" in attributes: # pragma no branch
self._tag = self._makeStringAttribute(attributes["tag"])
if "tagger" in attributes: # pragma no branch
self._tagger = self._makeClassAttribute(
github.GitAuthor.GitAuthor, attributes["tagger"]
)
self._tagger = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["tagger"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+1 -3
View File
@@ -75,8 +75,6 @@ class GitTree(CompletableGithubObject):
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "tree" in attributes: # pragma no branch
self._tree = self._makeListOfClassesAttribute(
github.GitTreeElement.GitTreeElement, attributes["tree"]
)
self._tree = self._makeListOfClassesAttribute(github.GitTreeElement.GitTreeElement, attributes["tree"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+1 -3
View File
@@ -157,9 +157,7 @@ class GithubApp(github.GithubObject.CompletableGithubObject):
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "owner" in attributes: # pragma no branch
self._owner = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["owner"]
)
self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
if "permissions" in attributes: # pragma no branch
self._permissions = self._makeDictAttribute(attributes["permissions"])
if "slug" in attributes: # pragma no branch
+7 -23
View File
@@ -64,19 +64,13 @@ class GithubIntegration:
if integration_id is not None:
assert isinstance(integration_id, (int, str)), integration_id
if private_key is not None:
assert isinstance(
private_key, str
), "supplied private key should be a string"
assert isinstance(private_key, str), "supplied private key should be a string"
assert isinstance(base_url, str), base_url
assert isinstance(timeout, int), timeout
assert user_agent is None or isinstance(user_agent, str), user_agent
assert isinstance(per_page, int), per_page
assert isinstance(verify, (bool, str)), verify
assert (
retry is None
or isinstance(retry, int)
or isinstance(retry, urllib3.util.Retry)
), retry
assert retry is None or isinstance(retry, int) or isinstance(retry, urllib3.util.Retry), retry
assert pool_size is None or isinstance(pool_size, int), pool_size
assert seconds_between_requests is None or seconds_between_requests >= 0
assert seconds_between_writes is None or seconds_between_writes >= 0
@@ -127,9 +121,7 @@ class GithubIntegration:
def get_github_for_installation(self, installation_id):
# The installation has to authenticate as an installation, not an app
auth = self.auth.get_installation_auth(
installation_id, requester=self.__requester
)
auth = self.auth.get_installation_auth(installation_id, requester=self.__requester)
return github.Github(**self.__requester.withAuth(auth).kwargs)
def _get_headers(self):
@@ -149,9 +141,7 @@ class GithubIntegration:
:param url: str
:rtype: :class:`github.Installation.Installation`
"""
headers, response = self.__requester.requestJsonAndCheck(
"GET", url, headers=self._get_headers()
)
headers, response = self.__requester.requestJsonAndCheck("GET", url, headers=self._get_headers())
return Installation(
requester=self.__requester,
@@ -183,9 +173,7 @@ class GithubIntegration:
permissions = {}
if not isinstance(permissions, dict):
raise GithubException(
status=400, data={"message": "Invalid permissions"}, headers=None
)
raise GithubException(status=400, data={"message": "Invalid permissions"}, headers=None)
body = {"permissions": permissions}
headers, response = self.__requester.requestJsonAndCheck(
@@ -267,9 +255,5 @@ class GithubIntegration:
:rtype: :class:`github.GithubApp.GithubApp`
"""
headers, data = self.__requester.requestJsonAndCheck(
"GET", "/app", headers=self._get_headers()
)
return GithubApp(
requester=self.__requester, headers=headers, attributes=data, completed=True
)
headers, data = self.__requester.requestJsonAndCheck("GET", "/app", headers=self._get_headers())
return GithubApp(requester=self.__requester, headers=headers, attributes=data, completed=True)
+14 -55
View File
@@ -41,17 +41,7 @@
import typing
from datetime import datetime, timezone
from operator import itemgetter
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
Optional,
Tuple,
Type,
Union,
)
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type, Union
from dateutil import parser
from typing_extensions import Protocol, TypeGuard
@@ -83,11 +73,7 @@ class _NotSetType:
@staticmethod
def remove_unset_items(data: Dict[str, Any]) -> Dict[str, Any]:
return {
key: value
for key, value in data.items()
if not isinstance(value, _NotSetType)
}
return {key: value for key, value in data.items() if not isinstance(value, _NotSetType)}
NotSet = _NotSetType()
@@ -108,11 +94,7 @@ def is_optional(v, type: Union[Type, Tuple[Type, ...]]) -> bool:
def is_optional_list(v, type: Union[Type, Tuple[Type, ...]]) -> bool:
return (
isinstance(v, _NotSetType)
or isinstance(v, list)
and all(isinstance(element, type) for element in v)
)
return isinstance(v, _NotSetType) or isinstance(v, list) and all(isinstance(element, type) for element in v)
class _ValuedAttribute(Attribute[T]):
@@ -125,9 +107,7 @@ class _ValuedAttribute(Attribute[T]):
class _BadAttribute(Attribute):
def __init__(
self, value: Any, expectedType: Any, exception: Optional[Exception] = None
):
def __init__(self, value: Any, expectedType: Any, exception: Optional[Exception] = None):
self.__value = value
self.__expectedType = expectedType
self.__exception = exception
@@ -170,9 +150,7 @@ class GithubObject:
if self.CHECK_AFTER_INIT_FLAG: # pragma no branch (Flag always set in tests)
requester.check_me(self)
def _storeAndUseAttributes(
self, headers: Dict[str, Union[str, int]], attributes: Any
) -> None:
def _storeAndUseAttributes(self, headers: Dict[str, Union[str, int]], attributes: Any) -> None:
# Make sure headers are assigned before calling _useAttributes
# (Some derived classes will use headers in _useAttributes)
self._headers = headers
@@ -208,17 +186,13 @@ class GithubObject:
@staticmethod
def __makeSimpleListAttribute(value: list, type: Type[T]) -> Attribute[T]:
if isinstance(value, list) and all(
isinstance(element, type) for element in value
):
if isinstance(value, list) and all(isinstance(element, type) for element in value):
return _ValuedAttribute(value) # type: ignore
else:
return _BadAttribute(value, [type]) # type: ignore
@staticmethod
def __makeTransformedAttribute(
value: T, type: Type[T], transform: Callable[[T], K]
) -> Attribute[K]:
def __makeTransformedAttribute(value: T, type: Type[T], transform: Callable[[T], K]) -> Attribute[K]:
if value is None:
return _ValuedAttribute(None) # type: ignore
elif isinstance(value, type):
@@ -269,9 +243,7 @@ class GithubObject:
)
@staticmethod
def _makeListOfStringsAttribute(
value: Union[List[List[str]], List[str], List[Union[str, int]]]
) -> Attribute:
def _makeListOfStringsAttribute(value: Union[List[List[str]], List[str], List[Union[str, int]]]) -> Attribute:
return GithubObject.__makeSimpleListAttribute(value, str)
@staticmethod
@@ -290,17 +262,10 @@ class GithubObject:
) -> Attribute:
return GithubObject.__makeSimpleListAttribute(value, list)
def _makeListOfClassesAttribute(
self, klass: Any, value: Any
) -> Union[_ValuedAttribute, _BadAttribute]:
if isinstance(value, list) and all(
isinstance(element, dict) for element in value
):
def _makeListOfClassesAttribute(self, klass: Any, value: Any) -> Union[_ValuedAttribute, _BadAttribute]:
if isinstance(value, list) and all(isinstance(element, dict) for element in value):
return _ValuedAttribute(
[
klass(self._requester, self._headers, element, completed=False)
for element in value
]
[klass(self._requester, self._headers, element, completed=False) for element in value]
)
else:
return _BadAttribute(value, [dict])
@@ -314,14 +279,10 @@ class GithubObject:
],
) -> Union[_ValuedAttribute, _BadAttribute]:
if isinstance(value, dict) and all(
isinstance(key, str) and isinstance(element, dict)
for key, element in value.items()
isinstance(key, str) and isinstance(element, dict) for key, element in value.items()
):
return _ValuedAttribute(
{
key: klass(self._requester, self._headers, element, completed=False)
for key, element in value.items()
}
{key: klass(self._requester, self._headers, element, completed=False) for key, element in value.items()}
)
else:
return _BadAttribute(value, {str: dict})
@@ -428,9 +389,7 @@ class CompletableGithubObject(GithubObject):
if status == 304:
return False
else:
headers, data = self._requester._Requester__check( # type: ignore
status, responseHeaders, output
)
headers, data = self._requester._Requester__check(status, responseHeaders, output) # type: ignore
self._storeAndUseAttributes(headers, data)
self.__completed = True
return True
+14 -44
View File
@@ -58,9 +58,7 @@ class GithubRetry(Retry):
# references the class, not the module (due to re-exporting in github/__init__.py)
__datetime = datetime
def __init__(
self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs
):
def __init__(self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs):
"""
:param secondary_rate_wait: seconds to wait before retrying secondary rate limit errors
:param kwargs: see urllib3.Retry for more arguments
@@ -69,12 +67,8 @@ class GithubRetry(Retry):
# 403 is too broad to be retried, but GitHub API signals rate limits via 403
# we retry 403 and look into the response header via Retry.increment
# to determine if we really retry that 403
kwargs["status_forcelist"] = kwargs.get(
"status_forcelist", list(range(500, 600))
) + [403]
kwargs["allowed_methods"] = kwargs.get(
"allowed_methods", Retry.DEFAULT_ALLOWED_METHODS.union({"GET", "POST"})
)
kwargs["status_forcelist"] = kwargs.get("status_forcelist", list(range(500, 600))) + [403]
kwargs["allowed_methods"] = kwargs.get("allowed_methods", Retry.DEFAULT_ALLOWED_METHODS.union({"GET", "POST"}))
super().__init__(**kwargs)
def new(self, **kw):
@@ -116,30 +110,20 @@ class GithubRetry(Retry):
# we want to fall back to the actual github exception (probably a rate limit error)
# but provide some context why we could not deal with it without another exception
try:
raise RuntimeError(
"Failed to inspect response message"
) from e
raise RuntimeError("Failed to inspect response message") from e
except RuntimeError as e:
raise GithubException(
response.status, content, response.headers
) from e
raise GithubException(response.status, content, response.headers) from e
try:
if Requester.isRateLimitError(message):
rate_type = (
"primary"
if Requester.isPrimaryRateLimitError(message)
else "secondary"
)
rate_type = "primary" if Requester.isPrimaryRateLimitError(message) else "secondary"
self.__log(
logging.DEBUG,
f"Response body indicates retry-able {rate_type} rate limit error: {message}",
)
# check early that we are retrying at all
retry = super().increment(
method, url, response, error, _pool, _stacktrace
)
retry = super().increment(method, url, response, error, _pool, _stacktrace)
# we backoff primary rate limit at least until X-RateLimit-Reset,
# we backoff secondary rate limit at for secondary_rate_wait seconds
@@ -149,12 +133,8 @@ class GithubRetry(Retry):
if "X-RateLimit-Reset" in response.headers:
value = response.headers.get("X-RateLimit-Reset")
if value and value.isdigit():
reset = self.__datetime.fromtimestamp(
int(value), timezone.utc
)
delta = reset - self.__datetime.now(
timezone.utc
)
reset = self.__datetime.fromtimestamp(int(value), timezone.utc)
delta = reset - self.__datetime.now(timezone.utc)
resetBackoff = delta.total_seconds()
if resetBackoff > 0:
@@ -175,9 +155,7 @@ class GithubRetry(Retry):
self.__log(
logging.DEBUG,
f"Retry backoff of {retry_backoff}s exceeds "
f"required rate limit backoff of {backoff}s".replace(
".0s", "s"
),
f"required rate limit backoff of {backoff}s".replace(".0s", "s"),
)
backoff = retry_backoff
@@ -186,9 +164,7 @@ class GithubRetry(Retry):
self.__log(
logging.INFO,
f"Setting next backoff to {backoff}s".replace(
".0s", "s"
),
f"Setting next backoff to {backoff}s".replace(".0s", "s"),
)
retry.get_backoff_time = get_backoff_time # type: ignore
return retry
@@ -197,22 +173,16 @@ class GithubRetry(Retry):
logging.DEBUG,
"Response message does not indicate retry-able error",
)
raise Requester.createException(
response.status, response.headers, content
)
raise Requester.createException(response.status, response.headers, content)
except (MaxRetryError, GithubException):
raise
except Exception as e:
# we want to fall back to the actual github exception (probably a rate limit error)
# but provide some context why we could not deal with it without another exception
try:
raise RuntimeError(
"Failed to determine retry backoff"
) from e
raise RuntimeError("Failed to determine retry backoff") from e
except RuntimeError as e:
raise GithubException(
response.status, content, response.headers
) from e
raise GithubException(response.status, content, response.headers) from e
raise GithubException(response.status, content, response.headers)
+2 -6
View File
@@ -157,9 +157,7 @@ class Hook(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 events is github.GithubObject.NotSet or all(isinstance(element, str) for element in events), events
assert add_events is github.GithubObject.NotSet or all(
isinstance(element, str) for element in add_events
), add_events
@@ -179,9 +177,7 @@ class Hook(github.GithubObject.CompletableGithubObject):
post_parameters["remove_events"] = remove_events
if active is not github.GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def test(self):
+3 -9
View File
@@ -124,9 +124,7 @@ class HookDeliverySummary(github.GithubObject.NonCompletableGithubObject):
if "action" in attributes: # pragma no branch
self._action = self._makeStringAttribute(attributes["action"])
if "installation_id" in attributes: # pragma no branch
self._installation_id = self._makeIntAttribute(
attributes["installation_id"]
)
self._installation_id = self._makeIntAttribute(attributes["installation_id"])
if "repository_id" in attributes: # pragma no branch
self._repository_id = self._makeIntAttribute(attributes["repository_id"])
if "url" in attributes: # pragma no branch
@@ -211,11 +209,7 @@ class HookDelivery(HookDeliverySummary):
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
super()._useAttributes(attributes)
if "request" in attributes: # pragma no branch
self._request = self._makeClassAttribute(
HookDeliveryRequest, attributes["request"]
)
self._request = self._makeClassAttribute(HookDeliveryRequest, attributes["request"])
if "response" in attributes: # pragma no branch
self._response = self._makeClassAttribute(
HookDeliveryResponse, attributes["response"]
)
self._response = self._makeClassAttribute(HookDeliveryResponse, attributes["response"])
# self._response = self._makeDictAttribute(attributes["response"])
+1 -3
View File
@@ -70,6 +70,4 @@ class HookDescription(NonCompletableGithubObject):
if "schema" in attributes: # pragma no branch
self._schema = self._makeListOfListOfStringsAttribute(attributes["schema"])
if "supported_events" in attributes: # pragma no branch
self._supported_events = self._makeListOfStringsAttribute(
attributes["supported_events"]
)
self._supported_events = self._makeListOfStringsAttribute(attributes["supported_events"])
+2 -6
View File
@@ -76,12 +76,8 @@ class InstallationAuthorization(NonCompletableGithubObject):
if "expires_at" in attributes: # pragma no branch
self._expires_at = self._makeDatetimeAttribute(attributes["expires_at"])
if "on_behalf_of" in attributes: # pragma no branch
self._on_behalf_of = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["on_behalf_of"]
)
self._on_behalf_of = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["on_behalf_of"])
if "permissions" in attributes: # pragma no branch
self._permissions = self._makeDictAttribute(attributes["permissions"])
if "repository_selection" in attributes: # pragma no branch
self._repository_selection = self._makeStringAttribute(
attributes["repository_selection"]
)
self._repository_selection = self._makeStringAttribute(attributes["repository_selection"])
+3 -9
View File
@@ -109,19 +109,13 @@ class Invitation(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "invitee" in attributes: # pragma no branch
self._invitee = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["invitee"]
)
self._invitee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["invitee"])
if "inviter" in attributes: # pragma no branch
self._inviter = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["inviter"]
)
self._inviter = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["inviter"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
+39 -121
View File
@@ -117,9 +117,7 @@ class Issue(CompletableGithubObject):
self._user: Attribute[NamedUser] = NotSet
def __repr__(self):
return self.get__repr__(
{"number": self._number.value, "title": self._title.value}
)
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@property
def assignee(self) -> NamedUser | None:
@@ -208,9 +206,7 @@ class Issue(CompletableGithubObject):
# The repository was not set automatically, so it must be looked up by url.
repo_url = "/".join(self.url.split("/")[:-2])
self._repository = github.GithubObject._ValuedAttribute(
github.Repository.Repository(
self._requester, self._headers, {"url": repo_url}, completed=False
)
github.Repository.Repository(self._requester, self._headers, {"url": repo_url}, completed=False)
)
return self._repository.value
@@ -258,48 +254,30 @@ class Issue(CompletableGithubObject):
"""
:calls: `GET /repos/{owner}/{repo}/pulls/{number} <https://docs.github.com/en/rest/reference/pulls>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"GET", "/pulls/".join(self.url.rsplit("/issues/", 1))
)
return github.PullRequest.PullRequest(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", "/pulls/".join(self.url.rsplit("/issues/", 1)))
return github.PullRequest.PullRequest(self._requester, headers, data, completed=True)
def add_to_assignees(self, *assignees: NamedUser | str) -> None:
"""
:calls: `POST /repos/{owner}/{repo}/issues/{number}/assignees <https://docs.github.com/en/rest/reference/issues#assignees>`_
"""
assert all(
isinstance(element, (github.NamedUser.NamedUser, str))
for element in assignees
), assignees
assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees
post_parameters = {
"assignees": [
assignee.login
if isinstance(assignee, github.NamedUser.NamedUser)
else assignee
assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee
for assignee in assignees
]
}
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/assignees", input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/assignees", input=post_parameters)
self._useAttributes(data)
def add_to_labels(self, *labels: Label | str) -> None:
"""
:calls: `POST /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
"""
assert all(
isinstance(element, (github.Label.Label, str)) for element in labels
), labels
post_parameters = [
label.name if isinstance(label, github.Label.Label) else label
for label in labels
]
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/labels", input=post_parameters
)
assert all(isinstance(element, (github.Label.Label, str)) for element in labels), labels
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/labels", input=post_parameters)
def create_comment(self, body: str) -> IssueComment:
"""
@@ -309,20 +287,14 @@ class Issue(CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/comments", input=post_parameters
)
return github.IssueComment.IssueComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/comments", input=post_parameters)
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
def delete_labels(self) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/labels"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/labels")
def edit(
self,
@@ -342,14 +314,10 @@ class Issue(CompletableGithubObject):
"""
assert is_optional(title, str), title
assert is_optional(body, str), body
assert assignee is None or is_optional(
assignee, (github.NamedUser.NamedUser, str)
), assignee
assert assignee is None or is_optional(assignee, (github.NamedUser.NamedUser, str)), assignee
assert is_optional_list(assignees, (github.NamedUser.NamedUser, str)), assignees
assert is_optional(state, str), state
assert milestone is None or is_optional(
milestone, github.Milestone.Milestone
), milestone
assert milestone is None or is_optional(milestone, github.Milestone.Milestone), milestone
assert is_optional_list(labels, str), labels
post_parameters = NotSet.remove_unset_items(
@@ -370,15 +338,11 @@ class Issue(CompletableGithubObject):
if is_defined(assignees):
post_parameters["assignees"] = [
element._identity
if isinstance(element, github.NamedUser.NamedUser)
else element
element._identity if isinstance(element, github.NamedUser.NamedUser) else element
for element in assignees
]
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def lock(self, lock_reason: str) -> None:
@@ -398,25 +362,17 @@ class Issue(CompletableGithubObject):
"""
:calls: `DELETE /repos/{owner}/{repo}/issues/{issue_number}/lock <https://docs.github.com/en/rest/reference/issues>`_
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/lock"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/lock")
def get_comment(self, id: int) -> IssueComment:
"""
:calls: `GET /repos/{owner}/{repo}/issues/comments/{id} <https://docs.github.com/en/rest/reference/issues#comments>`_
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self._parentUrl(self.url)}/comments/{id}"
)
return github.IssueComment.IssueComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self._parentUrl(self.url)}/comments/{id}")
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
def get_comments(
self, since: Opt[datetime] = NotSet
) -> PaginatedList[IssueComment]:
def get_comments(self, since: Opt[datetime] = NotSet) -> PaginatedList[IssueComment]:
"""
:calls: `GET /repos/{owner}/{repo}/issues/{number}/comments <https://docs.github.com/en/rest/reference/issues#comments>`_
"""
@@ -448,29 +404,20 @@ class Issue(CompletableGithubObject):
"""
:calls: `GET /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
"""
return PaginatedList(
github.Label.Label, self._requester, f"{self.url}/labels", None
)
return PaginatedList(github.Label.Label, self._requester, f"{self.url}/labels", None)
def remove_from_assignees(self, *assignees: NamedUser | str) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/issues/{number}/assignees <https://docs.github.com/en/rest/reference/issues#assignees>`_
"""
assert all(
isinstance(element, (github.NamedUser.NamedUser, str))
for element in assignees
), assignees
assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees
post_parameters = {
"assignees": [
assignee.login
if isinstance(assignee, github.NamedUser.NamedUser)
else assignee
assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee
for assignee in assignees
]
}
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/assignees", input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/assignees", input=post_parameters)
self._useAttributes(data)
def remove_from_labels(self, label: Label | str) -> None:
@@ -482,24 +429,15 @@ class Issue(CompletableGithubObject):
label = label._identity
else:
label = urllib.parse.quote(label)
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/labels/{label}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/labels/{label}")
def set_labels(self, *labels: Label | str) -> None:
"""
:calls: `PUT /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
"""
assert all(
isinstance(element, (github.Label.Label, str)) for element in labels
), labels
post_parameters = [
label.name if isinstance(label, github.Label.Label) else label
for label in labels
]
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/labels", input=post_parameters
)
assert all(isinstance(element, (github.Label.Label, str)) for element in labels), labels
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/labels", input=post_parameters)
def get_reactions(self) -> PaginatedList[Reaction]:
"""
@@ -559,34 +497,22 @@ class Issue(CompletableGithubObject):
def _useAttributes(self, attributes) -> None:
if "active_lock_reason" in attributes: # pragma no branch
self._active_lock_reason = self._makeStringAttribute(
attributes["active_lock_reason"]
)
self._active_lock_reason = self._makeStringAttribute(attributes["active_lock_reason"])
if "assignee" in attributes: # pragma no branch
self._assignee = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["assignee"]
)
self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"])
if "assignees" in attributes: # pragma no branch
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, attributes["assignees"]
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, attributes["assignees"])
elif "assignee" in attributes:
if attributes["assignee"] is not None:
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, [attributes["assignee"]]
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [attributes["assignee"]])
else:
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, []
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "closed_at" in attributes: # pragma no branch
self._closed_at = self._makeDatetimeAttribute(attributes["closed_at"])
if "closed_by" in attributes: # pragma no branch
self._closed_by = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["closed_by"]
)
self._closed_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["closed_by"])
if "comments" in attributes: # pragma no branch
self._comments = self._makeIntAttribute(attributes["comments"])
if "comments_url" in attributes: # pragma no branch
@@ -600,17 +526,13 @@ class Issue(CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "labels" in attributes: # pragma no branch
self._labels = self._makeListOfClassesAttribute(
github.Label.Label, attributes["labels"]
)
self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"])
if "labels_url" in attributes: # pragma no branch
self._labels_url = self._makeStringAttribute(attributes["labels_url"])
if "locked" in attributes: # pragma no branch
self._locked = self._makeBoolAttribute(attributes["locked"])
if "milestone" in attributes: # pragma no branch
self._milestone = self._makeClassAttribute(
github.Milestone.Milestone, attributes["milestone"]
)
self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"])
if "number" in attributes: # pragma no branch
self._number = self._makeIntAttribute(attributes["number"])
if "pull_request" in attributes: # pragma no branch
@@ -618,9 +540,7 @@ class Issue(CompletableGithubObject):
github.IssuePullRequest.IssuePullRequest, attributes["pull_request"]
)
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "state" in attributes: # pragma no branch
self._state = self._makeStringAttribute(attributes["state"])
if "state_reason" in attributes: # pragma no branch
@@ -632,6 +552,4 @@ class Issue(CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+2 -6
View File
@@ -127,9 +127,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_reactions(self):
@@ -206,6 +204,4 @@ class IssueComment(github.GithubObject.CompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+7 -21
View File
@@ -208,9 +208,7 @@ class IssueEvent(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "actor" in attributes: # pragma no branch
self._actor = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["actor"]
)
self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"])
if "commit_id" in attributes: # pragma no branch
self._commit_id = self._makeStringAttribute(attributes["commit_id"])
if "created_at" in attributes: # pragma no branch
@@ -220,9 +218,7 @@ class IssueEvent(github.GithubObject.CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "issue" in attributes: # pragma no branch
self._issue = self._makeClassAttribute(
github.Issue.Issue, attributes["issue"]
)
self._issue = self._makeClassAttribute(github.Issue.Issue, attributes["issue"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "node_id" in attributes: # pragma no branch
@@ -230,17 +226,11 @@ class IssueEvent(github.GithubObject.CompletableGithubObject):
if "commit_url" in attributes: # pragma no branch
self._commit_url = self._makeStringAttribute(attributes["commit_url"])
if "label" in attributes: # pragma no branch
self._label = self._makeClassAttribute(
github.Label.Label, attributes["label"]
)
self._label = self._makeClassAttribute(github.Label.Label, attributes["label"])
if "assignee" in attributes: # pragma no branch
self._assignee = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["assignee"]
)
self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"])
if "assigner" in attributes: # pragma no branch
self._assigner = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["assigner"]
)
self._assigner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assigner"])
if "review_requester" in attributes: # pragma no branch
self._review_requester = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["review_requester"]
@@ -250,14 +240,10 @@ class IssueEvent(github.GithubObject.CompletableGithubObject):
github.NamedUser.NamedUser, attributes["requested_reviewer"]
)
if "milestone" in attributes: # pragma no branch
self._milestone = self._makeClassAttribute(
github.Milestone.Milestone, attributes["milestone"]
)
self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"])
if "rename" in attributes: # pragma no branch
self._rename = self._makeDictAttribute(attributes["rename"])
if "dismissed_review" in attributes: # pragma no branch
self._dismissed_review = self._makeDictAttribute(
attributes["dismissed_review"]
)
self._dismissed_review = self._makeDictAttribute(attributes["dismissed_review"])
if "lock_reason" in attributes: # pragma no branch
self._lock_reason = self._makeStringAttribute(attributes["lock_reason"])
+1 -3
View File
@@ -93,9 +93,7 @@ class Label(github.GithubObject.CompletableGithubObject):
"""
assert isinstance(name, str), name
assert isinstance(color, str), color
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert description is github.GithubObject.NotSet or isinstance(description, str), description
post_parameters = {
"new_name": name,
"color": color,
+1 -3
View File
@@ -13,9 +13,7 @@ class Label(CompletableGithubObject):
def delete(self) -> None: ...
@property
def description(self) -> Optional[str]: ...
def edit(
self, name: str, color: str, description: Union[str, _NotSetType] = ...
) -> None: ...
def edit(self, name: str, color: str, description: Union[str, _NotSetType] = ...) -> None: ...
@property
def name(self) -> str: ...
@property
+4 -12
View File
@@ -146,20 +146,12 @@ class License(github.GithubObject.CompletableGithubObject):
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "implementation" in attributes: # pragma no branch
self._implementation = self._makeStringAttribute(
attributes["implementation"]
)
self._implementation = self._makeStringAttribute(attributes["implementation"])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "permissions" in attributes: # pragma no branch
self._permissions = self._makeListOfStringsAttribute(
attributes["permissions"]
)
self._permissions = self._makeListOfStringsAttribute(attributes["permissions"])
if "conditions" in attributes: # pragma no branch
self._conditions = self._makeListOfStringsAttribute(
attributes["conditions"]
)
self._conditions = self._makeListOfStringsAttribute(attributes["conditions"])
if "limitations" in attributes: # pragma no branch
self._limitations = self._makeListOfStringsAttribute(
attributes["limitations"]
)
self._limitations = self._makeListOfStringsAttribute(attributes["limitations"])
+31 -93
View File
@@ -135,11 +135,7 @@ class Github:
assert user_agent is None or isinstance(user_agent, str), user_agent
assert isinstance(per_page, int), per_page
assert isinstance(verify, (bool, str)), verify
assert (
retry is None
or isinstance(retry, int)
or isinstance(retry, urllib3.util.Retry)
), retry
assert retry is None or isinstance(retry, int) or isinstance(retry, urllib3.util.Retry), retry
assert pool_size is None or isinstance(pool_size, int), pool_size
assert seconds_between_requests is None or seconds_between_requests >= 0
assert seconds_between_writes is None or seconds_between_writes >= 0
@@ -154,8 +150,7 @@ class Github:
auth = Auth.Login(login_or_token, password)
elif login_or_token is not None:
warnings.warn(
"Argument login_or_token is deprecated, please use "
"auth=github.Auth.Token(...) instead",
"Argument login_or_token is deprecated, please use " "auth=github.Auth.Token(...) instead",
category=DeprecationWarning,
)
auth = Auth.Token(login_or_token)
@@ -169,8 +164,7 @@ class Github:
auth = Auth.AppAuthToken(jwt)
elif app_auth is not None:
warnings.warn(
"Argument app_auth is deprecated, please use "
"auth=github.Auth.AppInstallationAuth(...) instead",
"Argument app_auth is deprecated, please use " "auth=github.Auth.AppInstallationAuth(...) instead",
category=DeprecationWarning,
)
auth = app_auth
@@ -273,9 +267,7 @@ class Github:
url_parameters = dict()
return github.PaginatedList.PaginatedList(
github.License.License, self.__requester, "/licenses", url_parameters
)
return github.PaginatedList.PaginatedList(github.License.License, self.__requester, "/licenses", url_parameters)
def get_events(self):
"""
@@ -283,9 +275,7 @@ class Github:
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
return github.PaginatedList.PaginatedList(
github.Event.Event, self.__requester, "/events", None
)
return github.PaginatedList.PaginatedList(github.Event.Event, self.__requester, "/events", None)
def get_user(self, login=github.GithubObject.NotSet):
"""
@@ -295,16 +285,10 @@ class Github:
"""
assert login is github.GithubObject.NotSet or isinstance(login, str), login
if login is github.GithubObject.NotSet:
return AuthenticatedUser.AuthenticatedUser(
self.__requester, {}, {"url": "/user"}, completed=False
)
return AuthenticatedUser.AuthenticatedUser(self.__requester, {}, {"url": "/user"}, completed=False)
else:
headers, data = self.__requester.requestJsonAndCheck(
"GET", f"/users/{login}"
)
return github.NamedUser.NamedUser(
self.__requester, headers, data, completed=True
)
headers, data = self.__requester.requestJsonAndCheck("GET", f"/users/{login}")
return github.NamedUser.NamedUser(self.__requester, headers, data, completed=True)
def get_user_by_id(self, user_id):
"""
@@ -314,9 +298,7 @@ class Github:
"""
assert isinstance(user_id, int), user_id
headers, data = self.__requester.requestJsonAndCheck("GET", f"/user/{user_id}")
return github.NamedUser.NamedUser(
self.__requester, headers, data, completed=True
)
return github.NamedUser.NamedUser(self.__requester, headers, data, completed=True)
def get_users(self, since=github.GithubObject.NotSet):
"""
@@ -340,9 +322,7 @@ class Github:
"""
assert isinstance(login, str), login
headers, data = self.__requester.requestJsonAndCheck("GET", f"/orgs/{login}")
return github.Organization.Organization(
self.__requester, headers, data, completed=True
)
return github.Organization.Organization(self.__requester, headers, data, completed=True)
def get_organizations(self, since=github.GithubObject.NotSet):
"""
@@ -370,15 +350,11 @@ class Github:
url_base = "/repositories/" if isinstance(full_name_or_id, int) else "/repos/"
url = f"{url_base}{full_name_or_id}"
if lazy:
return Repository.Repository(
self.__requester, {}, {"url": url}, completed=False
)
return Repository.Repository(self.__requester, {}, {"url": url}, completed=False)
headers, data = self.__requester.requestJsonAndCheck("GET", url)
return Repository.Repository(self.__requester, headers, data, completed=True)
def get_repos(
self, since=github.GithubObject.NotSet, visibility=github.GithubObject.NotSet
):
def get_repos(self, since=github.GithubObject.NotSet, visibility=github.GithubObject.NotSet):
"""
:calls: `GET /repositories <https://docs.github.com/en/rest/reference/repos#list-public-repositories>`_
:param since: integer
@@ -423,9 +399,7 @@ class Github:
"/projects/columns/%d" % id,
headers={"Accept": Consts.mediaTypeProjectsPreview},
)
return github.ProjectColumn.ProjectColumn(
self.__requester, headers, data, completed=True
)
return github.ProjectColumn.ProjectColumn(self.__requester, headers, data, completed=True)
def get_gist(self, id):
"""
@@ -447,9 +421,7 @@ class Github:
url_parameters = dict()
if since is not github.GithubObject.NotSet:
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
return github.PaginatedList.PaginatedList(
github.Gist.Gist, self.__requester, "/gists/public", url_parameters
)
return github.PaginatedList.PaginatedList(github.Gist.Gist, self.__requester, "/gists/public", url_parameters)
def search_repositories(
self,
@@ -468,14 +440,10 @@ class Github:
"""
assert isinstance(query, str), query
url_parameters = dict()
if (
sort is not github.GithubObject.NotSet
): # pragma no branch (Should be covered)
if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
assert sort in ("stars", "forks", "updated"), sort
url_parameters["sort"] = sort
if (
order is not github.GithubObject.NotSet
): # pragma no branch (Should be covered)
if order is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
assert order in ("asc", "desc"), order
url_parameters["order"] = order
@@ -594,14 +562,10 @@ class Github:
"""
assert isinstance(query, str), query
url_parameters = dict()
if (
sort is not github.GithubObject.NotSet
): # pragma no branch (Should be covered)
if sort is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
assert sort in ("indexed",), sort
url_parameters["sort"] = sort
if (
order is not github.GithubObject.NotSet
): # pragma no branch (Should be covered)
if order is not github.GithubObject.NotSet: # pragma no branch (Should be covered)
assert order in ("asc", "desc"), order
url_parameters["order"] = order
@@ -703,16 +667,12 @@ class Github:
:rtype: string
"""
assert isinstance(text, str), text
assert context is github.GithubObject.NotSet or isinstance(
context, github.Repository.Repository
), context
assert context is github.GithubObject.NotSet or isinstance(context, github.Repository.Repository), context
post_parameters = {"text": text}
if context is not github.GithubObject.NotSet:
post_parameters["mode"] = "gfm"
post_parameters["context"] = context._identity
status, headers, data = self.__requester.requestJson(
"POST", "/markdown", input=post_parameters
)
status, headers, data = self.__requester.requestJson("POST", "/markdown", input=post_parameters)
return data
def get_hook(self, name):
@@ -722,12 +682,8 @@ class Github:
:rtype: :class:`github.HookDescription.HookDescription`
"""
assert isinstance(name, str), name
headers, attributes = self.__requester.requestJsonAndCheck(
"GET", f"/hooks/{name}"
)
return HookDescription.HookDescription(
self.__requester, headers, attributes, completed=True
)
headers, attributes = self.__requester.requestJsonAndCheck("GET", f"/hooks/{name}")
return HookDescription.HookDescription(self.__requester, headers, attributes, completed=True)
def get_hooks(self):
"""
@@ -736,9 +692,7 @@ class Github:
"""
headers, data = self.__requester.requestJsonAndCheck("GET", "/hooks")
return [
HookDescription.HookDescription(
self.__requester, headers, attributes, completed=True
)
HookDescription.HookDescription(self.__requester, headers, attributes, completed=True)
for attributes in data
]
@@ -751,12 +705,8 @@ class Github:
"""
assert isinstance(hook_id, int), hook_id
assert isinstance(delivery_id, int), delivery_id
headers, attributes = self.__requester.requestJsonAndCheck(
"GET", f"/hooks/{hook_id}/deliveries/{delivery_id}"
)
return HookDelivery.HookDelivery(
self.__requester, headers, attributes, completed=True
)
headers, attributes = self.__requester.requestJsonAndCheck("GET", f"/hooks/{hook_id}/deliveries/{delivery_id}")
return HookDelivery.HookDelivery(self.__requester, headers, attributes, completed=True)
def get_hook_deliveries(self, hook_id: int) -> List[HookDeliverySummary]:
"""
@@ -765,13 +715,9 @@ class Github:
:rtype: list of :class:`github.HookDelivery.HookDeliverySummary`
"""
assert isinstance(hook_id, int), hook_id
headers, data = self.__requester.requestJsonAndCheck(
"GET", f"/hooks/{hook_id}/deliveries"
)
headers, data = self.__requester.requestJsonAndCheck("GET", f"/hooks/{hook_id}/deliveries")
return [
HookDelivery.HookDeliverySummary(
self.__requester, headers, attributes, completed=True
)
HookDelivery.HookDeliverySummary(self.__requester, headers, attributes, completed=True)
for attributes in data
]
@@ -780,9 +726,7 @@ class Github:
:calls: `GET /gitignore/templates <https://docs.github.com/en/rest/reference/gitignore>`_
:rtype: list of string
"""
headers, data = self.__requester.requestJsonAndCheck(
"GET", "/gitignore/templates"
)
headers, data = self.__requester.requestJsonAndCheck("GET", "/gitignore/templates")
return data
def get_gitignore_template(self, name):
@@ -791,12 +735,8 @@ class Github:
:rtype: :class:`github.GitignoreTemplate.GitignoreTemplate`
"""
assert isinstance(name, str), name
headers, attributes = self.__requester.requestJsonAndCheck(
"GET", f"/gitignore/templates/{name}"
)
return GitignoreTemplate.GitignoreTemplate(
self.__requester, headers, attributes, completed=True
)
headers, attributes = self.__requester.requestJsonAndCheck("GET", f"/gitignore/templates/{name}")
return GitignoreTemplate.GitignoreTemplate(self.__requester, headers, attributes, completed=True)
def get_emojis(self):
"""
@@ -866,9 +806,7 @@ class Github:
return GithubIntegration(auth=self.__requester.auth).get_app()
else:
# with a slug given, we can lazily load the GithubApp
return GithubApp.GithubApp(
self.__requester, {}, {"url": f"/apps/{slug}"}, completed=False
)
return GithubApp.GithubApp(self.__requester, {}, {"url": f"/apps/{slug}"}, completed=False)
# Retrocompatibility
+12 -42
View File
@@ -69,9 +69,7 @@ class Github:
def get_emojis(self) -> Dict[str, str]: ...
def get_events(self) -> PaginatedList[Event]: ...
def get_gist(self, id: str) -> Gist: ...
def get_gists(
self, since: Union[datetime, _NotSetType] = ...
) -> PaginatedList[Gist]: ...
def get_gists(self, since: Union[datetime, _NotSetType] = ...) -> PaginatedList[Gist]: ...
def get_gitignore_template(self, name: str) -> GitignoreTemplate: ...
def get_gitignore_templates(self) -> List[str]: ...
def get_hook(self, name: str) -> HookDescription: ...
@@ -79,15 +77,11 @@ class Github:
def get_license(self, key: Union[str, _NotSetType] = ...) -> License: ...
def get_licenses(self) -> PaginatedList[License]: ...
def get_organization(self, login: str) -> Organization: ...
def get_organizations(
self, since: Union[int, _NotSetType] = ...
) -> PaginatedList[Organization]: ...
def get_organizations(self, since: Union[int, _NotSetType] = ...) -> PaginatedList[Organization]: ...
def get_project(self, id: int) -> Project: ...
def get_project_column(self, id: int) -> ProjectColumn: ...
def get_rate_limit(self) -> RateLimit: ...
def get_repo(
self, full_name_or_id: Union[int, str], lazy: bool = ...
) -> Repository: ...
def get_repo(self, full_name_or_id: Union[int, str], lazy: bool = ...) -> Repository: ...
def get_repos(
self,
since: Union[int, _NotSetType] = ...,
@@ -96,62 +90,38 @@ class Github:
@overload
def get_user(self, login: _NotSetType = ...) -> AuthenticatedUser: ...
@overload
def get_user(
self, login: Union[str, _NotSetType] = ...
) -> Union[NamedUser, AuthenticatedUser]: ...
def get_user(self, login: Union[str, _NotSetType] = ...) -> Union[NamedUser, AuthenticatedUser]: ...
def get_user_by_id(self, user_id: int) -> NamedUser: ...
def get_users(
self, since: Union[int, _NotSetType] = ...
) -> PaginatedList[NamedUser]: ...
def get_users(self, since: Union[int, _NotSetType] = ...) -> PaginatedList[NamedUser]: ...
def load(self, f: BytesIO) -> Repository: ...
# argument slug is deprecated, not included here
def get_app(self): ...
def get_oauth_application(
self, client_id: str, client_secret: str
) -> ApplicationOAuth: ...
def get_oauth_application(self, client_id: str, client_secret: str) -> ApplicationOAuth: ...
@property
def oauth_scopes(self) -> Optional[List[str]]: ...
@property
def rate_limiting(self) -> Tuple[int, int]: ...
@property
def rate_limiting_resettime(self) -> int: ...
def render_markdown(
self, text: str, context: Union[Repository, _NotSetType] = ...
) -> str: ...
def render_markdown(self, text: str, context: Union[Repository, _NotSetType] = ...) -> str: ...
def search_code(
self,
query: str,
sort: Union[str, _NotSetType] = ...,
order: Union[str, _NotSetType] = ...,
highlight: bool = ...,
**qualifiers: Any
**qualifiers: Any,
) -> PaginatedList[ContentFile]: ...
def search_commits(
self,
query: str,
sort: Union[str, _NotSetType] = ...,
order: Union[str, _NotSetType] = ...,
**qualifiers: Any
self, query: str, sort: Union[str, _NotSetType] = ..., order: Union[str, _NotSetType] = ..., **qualifiers: Any
) -> PaginatedList[Commit]: ...
def search_issues(
self,
query: str,
sort: Union[str, _NotSetType] = ...,
order: Union[str, _NotSetType] = ...,
**qualifiers: Any
self, query: str, sort: Union[str, _NotSetType] = ..., order: Union[str, _NotSetType] = ..., **qualifiers: Any
) -> PaginatedList[Issue]: ...
def search_repositories(
self,
query: str,
sort: Union[str, _NotSetType] = ...,
order: Union[str, _NotSetType] = ...,
**qualifiers: Any
self, query: str, sort: Union[str, _NotSetType] = ..., order: Union[str, _NotSetType] = ..., **qualifiers: Any
) -> PaginatedList[Repository]: ...
def search_topics(self, query: str, **qualifiers: Any) -> PaginatedList[Topic]: ...
def search_users(
self,
query: str,
sort: Union[str, _NotSetType] = ...,
order: Union[str, _NotSetType] = ...,
**qualifiers: Any
self, query: str, sort: Union[str, _NotSetType] = ..., order: Union[str, _NotSetType] = ..., **qualifiers: Any
) -> PaginatedList[NamedUser]: ...
+3 -9
View File
@@ -113,14 +113,8 @@ class Membership(github.GithubObject.CompletableGithubObject):
if "role" in attributes: # pragma no branch
self._role = self._makeStringAttribute(attributes["role"])
if "organization_url" in attributes: # pragma no branch
self._organization_url = self._makeStringAttribute(
attributes["organization_url"]
)
self._organization_url = self._makeStringAttribute(attributes["organization_url"])
if "organization" in attributes: # pragma no branch
self._organization = self._makeClassAttribute(
github.Organization.Organization, attributes["organization"]
)
self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+3 -9
View File
@@ -188,21 +188,15 @@ class Migration(github.GithubObject.CompletableGithubObject):
if "id" in attributes:
self._id = self._makeIntAttribute(attributes["id"])
if "owner" in attributes:
self._owner = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["owner"]
)
self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
if "guid" in attributes:
self._guid = self._makeStringAttribute(attributes["guid"])
if "state" in attributes:
self._state = self._makeStringAttribute(attributes["state"])
if "lock_repositories" in attributes:
self._lock_repositories = self._makeBoolAttribute(
attributes["lock_repositories"]
)
self._lock_repositories = self._makeBoolAttribute(attributes["lock_repositories"])
if "exclude_attachments" in attributes:
self._exclude_attachments = self._makeBoolAttribute(
attributes["exclude_attachments"]
)
self._exclude_attachments = self._makeBoolAttribute(attributes["exclude_attachments"])
if "repositories" in attributes:
self._repositories = self._makeListOfClassesAttribute(
github.Repository.Repository, attributes["repositories"]
+5 -15
View File
@@ -42,9 +42,7 @@ class Milestone(github.GithubObject.CompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"number": self._number.value, "title": self._title.value}
)
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@property
def closed_issues(self):
@@ -174,9 +172,7 @@ class Milestone(github.GithubObject.CompletableGithubObject):
"""
assert isinstance(title, str), title
assert state is github.GithubObject.NotSet or isinstance(state, str), state
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert due_on is github.GithubObject.NotSet or isinstance(due_on, date), due_on
post_parameters = {
"title": title,
@@ -187,9 +183,7 @@ class Milestone(github.GithubObject.CompletableGithubObject):
post_parameters["description"] = description
if due_on is not github.GithubObject.NotSet:
post_parameters["due_on"] = due_on.strftime("%Y-%m-%d")
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_labels(self):
@@ -197,9 +191,7 @@ class Milestone(github.GithubObject.CompletableGithubObject):
:calls: `GET /repos/{owner}/{repo}/milestones/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label`
"""
return github.PaginatedList.PaginatedList(
github.Label.Label, self._requester, f"{self.url}/labels", None
)
return github.PaginatedList.PaginatedList(github.Label.Label, self._requester, f"{self.url}/labels", None)
@property
def _identity(self):
@@ -226,9 +218,7 @@ class Milestone(github.GithubObject.CompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "due_on" in attributes: # pragma no branch
+21 -65
View File
@@ -78,11 +78,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
return hash((self.id, self.login))
def __eq__(self, other):
return (
isinstance(other, type(self))
and self.login == other.login
and self.id == other.id
)
return isinstance(other, type(self)) and self.login == other.login and self.id == other.id
@property
def avatar_url(self):
@@ -433,27 +429,21 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /users/{user}/events <https://docs.github.com/en/rest/reference/activity#events>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
return github.PaginatedList.PaginatedList(
github.Event.Event, self._requester, f"{self.url}/events", None
)
return github.PaginatedList.PaginatedList(github.Event.Event, self._requester, f"{self.url}/events", None)
def get_followers(self):
"""
:calls: `GET /users/{user}/followers <https://docs.github.com/en/rest/reference/users#followers>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
NamedUser, self._requester, f"{self.url}/followers", None
)
return github.PaginatedList.PaginatedList(NamedUser, self._requester, f"{self.url}/followers", None)
def get_following(self):
"""
:calls: `GET /users/{user}/following <https://docs.github.com/en/rest/reference/users#followers>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
"""
return github.PaginatedList.PaginatedList(
NamedUser, self._requester, f"{self.url}/following", None
)
return github.PaginatedList.PaginatedList(NamedUser, self._requester, f"{self.url}/following", None)
def get_gists(self, since=github.GithubObject.NotSet):
"""
@@ -474,9 +464,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
:calls: `GET /users/{user}/keys <https://docs.github.com/en/rest/reference/users#create-a-public-ssh-key-for-the-authenticated-user>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey`
"""
return github.PaginatedList.PaginatedList(
github.UserKey.UserKey, self._requester, f"{self.url}/keys", None
)
return github.PaginatedList.PaginatedList(github.UserKey.UserKey, self._requester, f"{self.url}/keys", None)
def get_orgs(self):
"""
@@ -540,12 +528,8 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/repos/{self.login}/{name}"
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/repos/{self.login}/{name}")
return github.Repository.Repository(self._requester, headers, data, completed=True)
def get_repos(
self,
@@ -562,9 +546,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
"""
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 direction is github.GithubObject.NotSet or isinstance(direction, str), direction
url_parameters = dict()
if type is not github.GithubObject.NotSet:
url_parameters["type"] = type
@@ -616,9 +598,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(following, github.NamedUser.NamedUser), following
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/following/{following._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"{self.url}/following/{following._identity}")
return status == 204
@property
@@ -631,17 +611,11 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
:param org: string or :class:`github.Organization.Organization`
:rtype: :class:`github.Membership.Membership`
"""
assert isinstance(org, str) or isinstance(
org, github.Organization.Organization
), org
assert isinstance(org, str) or isinstance(org, github.Organization.Organization), org
if isinstance(org, github.Organization.Organization):
org = org.login
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/orgs/{org}/memberships/{self.login}"
)
return github.Membership.Membership(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"/orgs/{org}/memberships/{self.login}")
return github.Membership.Membership(self._requester, headers, data, completed=True)
def _initAttributes(self):
self._avatar_url = github.GithubObject.NotSet
@@ -730,13 +704,9 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "invitation_teams_url" in attributes: # pragma no branch
self._invitation_teams_url = self._makeStringAttribute(
attributes["invitation_teams_url"]
)
self._invitation_teams_url = self._makeStringAttribute(attributes["invitation_teams_url"])
if "inviter" in attributes: # pragma no branch
self._inviter = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["inviter"]
)
self._inviter = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["inviter"])
if "location" in attributes: # pragma no branch
self._location = self._makeStringAttribute(attributes["location"])
if "login" in attributes: # pragma no branch
@@ -746,17 +716,11 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "organizations_url" in attributes: # pragma no branch
self._organizations_url = self._makeStringAttribute(
attributes["organizations_url"]
)
self._organizations_url = self._makeStringAttribute(attributes["organizations_url"])
if "owned_private_repos" in attributes: # pragma no branch
self._owned_private_repos = self._makeIntAttribute(
attributes["owned_private_repos"]
)
self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"])
if "permissions" in attributes: # pragma no branch
self._permissions = self._makeClassAttribute(
github.Permissions.Permissions, attributes["permissions"]
)
self._permissions = self._makeClassAttribute(github.Permissions.Permissions, attributes["permissions"])
if "plan" in attributes: # pragma no branch
self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"])
if "private_gists" in attributes: # pragma no branch
@@ -766,9 +730,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
if "public_repos" in attributes: # pragma no branch
self._public_repos = self._makeIntAttribute(attributes["public_repos"])
if "received_events_url" in attributes: # pragma no branch
self._received_events_url = self._makeStringAttribute(
attributes["received_events_url"]
)
self._received_events_url = self._makeStringAttribute(attributes["received_events_url"])
if "repos_url" in attributes: # pragma no branch
self._repos_url = self._makeStringAttribute(attributes["repos_url"])
if "role" in attributes: # pragma no branch
@@ -778,21 +740,15 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
if "starred_url" in attributes: # pragma no branch
self._starred_url = self._makeStringAttribute(attributes["starred_url"])
if "subscriptions_url" in attributes: # pragma no branch
self._subscriptions_url = self._makeStringAttribute(
attributes["subscriptions_url"]
)
self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"])
if "suspended_at" in attributes: # pragma no branch
self._suspended_at = self._makeDatetimeAttribute(attributes["suspended_at"])
if "team_count" in attributes:
self._team_count = self._makeIntAttribute(attributes["team_count"])
if "total_private_repos" in attributes: # pragma no branch
self._total_private_repos = self._makeIntAttribute(
attributes["total_private_repos"]
)
self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"])
if "twitter_username" in attributes: # pragma no branch
self._twitter_username = self._makeStringAttribute(
attributes["twitter_username"]
)
self._twitter_username = self._makeStringAttribute(attributes["twitter_username"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "updated_at" in attributes: # pragma no branch
+1 -3
View File
@@ -52,9 +52,7 @@ class NamedUser(CompletableGithubObject):
def get_events(self) -> PaginatedList[Event]: ...
def get_followers(self) -> PaginatedList[NamedUser]: ...
def get_following(self) -> PaginatedList[NamedUser]: ...
def get_gists(
self, since: Union[_NotSetType, datetime] = ...
) -> PaginatedList[Gist]: ...
def get_gists(self, since: Union[_NotSetType, datetime] = ...) -> PaginatedList[Gist]: ...
def get_keys(self) -> PaginatedList[UserKey]: ...
def get_organization_membership(self, org: int) -> Membership: ...
def get_orgs(self) -> PaginatedList[Organization]: ...
+3 -9
View File
@@ -126,9 +126,7 @@ class Notification(github.GithubObject.CompletableGithubObject):
:type: :class:github.PullRequest.PullRequest
"""
headers, data = self._requester.requestJsonAndCheck("GET", self.subject.url)
return github.PullRequest.PullRequest(
self._requester, headers, data, completed=True
)
return github.PullRequest.PullRequest(self._requester, headers, data, completed=True)
def get_issue(self):
"""
@@ -153,9 +151,7 @@ class Notification(github.GithubObject.CompletableGithubObject):
if "last_read_at" in attributes: # pragma no branch
self._last_read_at = self._makeDatetimeAttribute(attributes["last_read_at"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "subject" in attributes: # pragma no branch
self._subject = self._makeClassAttribute(
github.NotificationSubject.NotificationSubject, attributes["subject"]
@@ -163,9 +159,7 @@ class Notification(github.GithubObject.CompletableGithubObject):
if "reason" in attributes: # pragma no branch
self._reason = self._makeStringAttribute(attributes["reason"])
if "subscription_url" in attributes: # pragma no branch
self._subscription_url = self._makeStringAttribute(
attributes["subscription_url"]
)
self._subscription_url = self._makeStringAttribute(attributes["subscription_url"])
if "unread" in attributes: # pragma no branch
self._unread = self._makeBoolAttribute(attributes["unread"])
if "updated_at" in attributes: # pragma no branch
+1 -3
View File
@@ -66,8 +66,6 @@ class NotificationSubject(NonCompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "latest_comment_url" in attributes: # pragma no branch
self._latest_comment_url = self._makeStringAttribute(
attributes["latest_comment_url"]
)
self._latest_comment_url = self._makeStringAttribute(attributes["latest_comment_url"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
+71 -210
View File
@@ -424,12 +424,8 @@ class Organization(github.GithubObject.CompletableGithubObject):
"""
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
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,
@@ -444,9 +440,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": "application/vnd.github.v3+json"},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def create_hook(
self,
@@ -465,9 +459,7 @@ 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 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,
@@ -477,9 +469,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
post_parameters["events"] = events
if active is not github.GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/hooks", input=post_parameters
)
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):
@@ -545,39 +535,17 @@ class Organization(github.GithubObject.CompletableGithubObject):
: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 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
@@ -639,18 +607,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": Consts.repoVisibilityPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def create_secret(
self,
secret_name,
unencrypted_value,
visibility="all",
selected_repositories: github.GithubObject.Opt[
list[github.Repository.Repository]
] = github.GithubObject.NotSet,
selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
):
"""
:calls: `PUT /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret>`_
@@ -665,8 +629,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert isinstance(visibility, str), visibility
if visibility == "selected":
assert isinstance(selected_repositories, list) and all(
isinstance(element, github.Repository.Repository)
for element in selected_repositories
isinstance(element, github.Repository.Repository) for element in selected_repositories
), selected_repositories
else:
assert selected_repositories is github.GithubObject.NotSet
@@ -679,9 +642,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"visibility": visibility,
}
if selected_repositories is not github.GithubObject.NotSet:
put_parameters["selected_repository_ids"] = [
element.id for element in selected_repositories
]
put_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
status, headers, data = self._requester.requestJson(
"PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters
@@ -709,31 +670,21 @@ class Organization(github.GithubObject.CompletableGithubObject):
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
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:
post_parameters["repo_names"] = [
element._identity for element in 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
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/teams", input=post_parameters)
return github.Team.Team(self._requester, headers, data, completed=True)
def create_variable(
@@ -741,9 +692,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]] = github.GithubObject.NotSet,
) -> bool:
"""
:calls: `PUT /orgs/{org}/actions/variables/ <https://docs.github.com/en/rest/reference/actions/variables#create-an-organization-variable>`_
@@ -758,8 +707,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert isinstance(visibility, str), visibility
if visibility == "selected":
assert isinstance(selected_repositories, list) and all(
isinstance(element, github.Repository.Repository)
for element in selected_repositories
isinstance(element, github.Repository.Repository) for element in selected_repositories
), selected_repositories
else:
assert selected_repositories is github.GithubObject.NotSet
@@ -770,9 +718,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"visibility": visibility,
}
if selected_repositories is not github.GithubObject.NotSet:
post_parameters["selected_repository_ids"] = [
element.id for element in selected_repositories
]
post_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
status, headers, data = self._requester.requestJson(
"POST", f"{self.url}/actions/variables", input=post_parameters
)
@@ -785,9 +731,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: None`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/hooks/{id}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/hooks/{id}")
def delete_secret(self, secret_name):
"""
@@ -796,9 +740,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(secret_name, str), secret_name
status, headers, data = self._requester.requestJson(
"DELETE", f"{self.url}/actions/secrets/{secret_name}"
)
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/secrets/{secret_name}")
return status == 204
def delete_variable(self, variable_name: str) -> bool:
@@ -808,9 +750,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(variable_name, str), variable_name
status, headers, data = self._requester.requestJson(
"DELETE", f"{self.url}/actions/variables/{variable_name}"
)
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/variables/{variable_name}")
return status == 204
def edit(
@@ -834,20 +774,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
:param name: string
:rtype: None
"""
assert billing_email is github.GithubObject.NotSet or isinstance(
billing_email, str
), billing_email
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 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 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:
@@ -864,9 +796,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
post_parameters["location"] = location
if name is not github.GithubObject.NotSet:
post_parameters["name"] = name
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def edit_hook(
@@ -889,9 +819,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
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 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,
@@ -901,9 +829,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
post_parameters["events"] = events
if active is not github.GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestJsonAndCheck(
"PATCH", f"{self.url}/hooks/{id}", input=post_parameters
)
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 update_variable(
@@ -911,9 +837,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]] = github.GithubObject.NotSet,
) -> bool:
"""
:calls: `PATCH /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#update-an-organization-variable>`_
@@ -928,8 +852,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
assert isinstance(visibility, str), visibility
if visibility == "selected":
assert isinstance(selected_repositories, list) and all(
isinstance(element, github.Repository.Repository)
for element in selected_repositories
isinstance(element, github.Repository.Repository) for element in selected_repositories
), selected_repositories
else:
assert selected_repositories is github.GithubObject.NotSet
@@ -940,9 +863,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"visibility": visibility,
}
if selected_repositories is not github.GithubObject.NotSet:
patch_parameters["selected_repository_ids"] = [
element.id for element in selected_repositories
]
patch_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
status, headers, data = self._requester.requestJson(
"PATCH",
@@ -956,9 +877,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:calls: `GET /orgs/{org}/events <https://docs.github.com/en/rest/reference/activity#events>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
"""
return github.PaginatedList.PaginatedList(
github.Event.Event, self._requester, f"{self.url}/events", None
)
return github.PaginatedList.PaginatedList(github.Event.Event, self._requester, f"{self.url}/events", None)
def get_hook(self, id):
"""
@@ -967,9 +886,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Hook.Hook`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/hooks/{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):
@@ -977,13 +894,9 @@ class Organization(github.GithubObject.CompletableGithubObject):
:calls: `GET /orgs/{owner}/hooks <https://docs.github.com/en/rest/reference/orgs#webhooks>`_
: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 github.PaginatedList.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:
def get_hook_delivery(self, hook_id: int, delivery_id: int) -> github.HookDelivery.HookDelivery:
"""
:calls: `GET /orgs/{owner}/hooks/{hook_id}/deliveries/{delivery_id} <https://docs.github.com/en/rest/reference/orgs#get-a-webhook-delivery-for-an-organization-webhook>`_
:param hook_id: integer
@@ -995,9 +908,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/hooks/{hook_id}/deliveries/{delivery_id}"
)
return github.HookDelivery.HookDelivery(
self._requester, headers, data, completed=True
)
return github.HookDelivery.HookDelivery(self._requester, headers, data, completed=True)
def get_hook_deliveries(
self, hook_id: int
@@ -1041,9 +952,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
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 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:
@@ -1062,18 +971,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
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_=github.GithubObject.NotSet, role=github.GithubObject.NotSet):
"""
:calls: `GET /orgs/{org}/members <https://docs.github.com/en/rest/reference/orgs#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 filter_ is github.GithubObject.NotSet or isinstance(filter_, str), filter_
assert role is github.GithubObject.NotSet or isinstance(role, str), role
url_parameters = {}
@@ -1125,9 +1030,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
: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 filter_ is github.GithubObject.NotSet or isinstance(filter_, str), filter_
url_parameters = {}
if filter_ is not github.GithubObject.NotSet:
@@ -1166,12 +1069,8 @@ class Organization(github.GithubObject.CompletableGithubObject):
:calls: `GET /orgs/{org}/actions/secrets/public-key <https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key>`_
:rtype: :class:`github.PublicKey.PublicKey`
"""
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/actions/secrets/public-key"
)
return github.PublicKey.PublicKey(
self._requester, headers, data, completed=True
)
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):
"""
@@ -1185,9 +1084,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
f"/repos/{self.login}/{name}",
headers={"Accept": Consts.repoVisibilityPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)
return github.Repository.Repository(self._requester, headers, data, completed=True)
def get_repos(
self,
@@ -1204,9 +1101,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
"""
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 direction is github.GithubObject.NotSet or isinstance(direction, str), direction
url_parameters = dict()
if type is not github.GithubObject.NotSet:
@@ -1240,9 +1135,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.Team.Team`
"""
assert isinstance(slug, str), slug
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/teams/{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):
@@ -1250,9 +1143,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:calls: `GET /orgs/{org}/teams <https://docs.github.com/en/rest/reference/teams#list-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 github.PaginatedList.PaginatedList(github.Team.Team, self._requester, f"{self.url}/teams", None)
def invitations(self):
"""
@@ -1282,9 +1173,7 @@ 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 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
@@ -1315,9 +1204,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(invitee, github.NamedUser.NamedUser), invitee
status, headers, data = self._requester.requestJson(
"DELETE", f"{self.url}/invitations/{invitee.id}"
)
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/invitations/{invitee.id}")
return status == 204
def has_in_members(self, member):
@@ -1327,13 +1214,9 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(member, github.NamedUser.NamedUser), member
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/members/{member._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"{self.url}/members/{member._identity}")
if status == 302:
status, headers, data = self._requester.requestJson(
"GET", headers["location"]
)
status, headers, data = self._requester.requestJson("GET", headers["location"])
return status == 204
def has_in_public_members(self, public_member):
@@ -1355,9 +1238,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/memberships/{member._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/memberships/{member._identity}")
def remove_from_members(self, member):
"""
@@ -1366,9 +1247,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/members/{member._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/members/{member._identity}")
def remove_from_public_members(self, public_member):
"""
@@ -1396,9 +1275,7 @@ 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 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
@@ -1413,9 +1290,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
input=post_parameters,
headers={"Accept": Consts.mediaTypeMigrationPreview},
)
return github.Migration.Migration(
self._requester, headers, data, completed=True
)
return github.Migration.Migration(self._requester, headers, data, completed=True)
def get_migrations(self):
"""
@@ -1498,9 +1373,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "default_repository_permission" in attributes: # pragma no branch
self._default_repository_permission = self._makeStringAttribute(
attributes["default_repository_permission"]
)
self._default_repository_permission = self._makeStringAttribute(attributes["default_repository_permission"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "disk_usage" in attributes: # pragma no branch
@@ -1516,13 +1389,9 @@ class Organization(github.GithubObject.CompletableGithubObject):
if "gravatar_id" in attributes: # pragma no branch
self._gravatar_id = self._makeStringAttribute(attributes["gravatar_id"])
if "has_organization_projects" in attributes: # pragma no branch
self._has_organization_projects = self._makeBoolAttribute(
attributes["has_organization_projects"]
)
self._has_organization_projects = self._makeBoolAttribute(attributes["has_organization_projects"])
if "has_repository_projects" in attributes: # pragma no branch
self._has_repository_projects = self._makeBoolAttribute(
attributes["has_repository_projects"]
)
self._has_repository_projects = self._makeBoolAttribute(attributes["has_repository_projects"])
if "hooks_url" in attributes: # pragma no branch
self._hooks_url = self._makeStringAttribute(attributes["hooks_url"])
if "html_url" in attributes: # pragma no branch
@@ -1544,9 +1413,7 @@ class Organization(github.GithubObject.CompletableGithubObject):
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "owned_private_repos" in attributes: # pragma no branch
self._owned_private_repos = self._makeIntAttribute(
attributes["owned_private_repos"]
)
self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"])
if "plan" in attributes: # pragma no branch
self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"])
if "private_gists" in attributes: # pragma no branch
@@ -1554,21 +1421,15 @@ class Organization(github.GithubObject.CompletableGithubObject):
if "public_gists" in attributes: # pragma no branch
self._public_gists = self._makeIntAttribute(attributes["public_gists"])
if "public_members_url" in attributes: # pragma no branch
self._public_members_url = self._makeStringAttribute(
attributes["public_members_url"]
)
self._public_members_url = self._makeStringAttribute(attributes["public_members_url"])
if "public_repos" in attributes: # pragma no branch
self._public_repos = self._makeIntAttribute(attributes["public_repos"])
if "repos_url" in attributes: # pragma no branch
self._repos_url = self._makeStringAttribute(attributes["repos_url"])
if "total_private_repos" in attributes: # pragma no branch
self._total_private_repos = self._makeIntAttribute(
attributes["total_private_repos"]
)
self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"])
if "two_factor_requirement_enabled" in attributes: # pragma no branch
self._two_factor_requirement_enabled = self._makeBoolAttribute(
attributes["two_factor_requirement_enabled"]
)
self._two_factor_requirement_enabled = self._makeBoolAttribute(attributes["two_factor_requirement_enabled"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "updated_at" in attributes: # pragma no branch
+3 -9
View File
@@ -20,9 +20,7 @@ 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_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: ...
@@ -156,12 +154,8 @@ class Organization(CompletableGithubObject):
) -> 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_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: ...
+1 -4
View File
@@ -263,7 +263,4 @@ class PaginatedList(PaginatedListBase[T]):
self.__totalCount = data.get("total_count")
data = data[self.__list_item]
return [
self.__contentClass(self.__requester, headers, element, completed=False)
for element in data
]
return [self.__contentClass(self.__requester, headers, element, completed=False) for element in data]
+3 -9
View File
@@ -170,9 +170,7 @@ class Project(github.GithubObject.CompletableGithubObject):
assert organization_permission is github.GithubObject.NotSet or isinstance(
organization_permission, str
), organization_permission
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
assert private is github.GithubObject.NotSet or isinstance(private, bool), private
patch_parameters = dict()
if name is not github.GithubObject.NotSet:
patch_parameters["name"] = name
@@ -217,9 +215,7 @@ class Project(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/columns", headers=import_header, input=post_parameters
)
return github.ProjectColumn.ProjectColumn(
self._requester, headers, data, completed=True
)
return github.ProjectColumn.ProjectColumn(self._requester, headers, data, completed=True)
def _initAttributes(self):
self._body = github.GithubObject.NotSet
@@ -244,9 +240,7 @@ class Project(github.GithubObject.CompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "id" in attributes: # pragma no branch
+6 -18
View File
@@ -118,9 +118,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject):
:param content_type: string, optional
:rtype: :class:`github.PullRequest.PullRequest` or :class:`github.Issue.Issue`
"""
assert content_type is github.GithubObject.NotSet or isinstance(
content_type, str
), content_type
assert content_type is github.GithubObject.NotSet or isinstance(content_type, str), content_type
if self.content_url is None:
return None
@@ -143,14 +141,10 @@ class ProjectCard(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(position, str), position
assert isinstance(column, github.ProjectColumn.ProjectColumn) or isinstance(
column, int
), column
assert isinstance(column, github.ProjectColumn.ProjectColumn) or isinstance(column, int), column
post_parameters = {
"position": position,
"column_id": column.id
if isinstance(column, github.ProjectColumn.ProjectColumn)
else column,
"column_id": column.id if isinstance(column, github.ProjectColumn.ProjectColumn) else column,
}
status, _, _ = self._requester.requestJson(
"POST",
@@ -172,9 +166,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject):
)
return status == 204
def edit(
self, note=github.GithubObject.NotSet, archived=github.GithubObject.NotSet
):
def edit(self, note=github.GithubObject.NotSet, archived=github.GithubObject.NotSet):
"""
:calls: `PATCH /projects/columns/cards/{card_id} <https://docs.github.com/en/rest/reference/projects#cards>`_
:param note: string
@@ -182,9 +174,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert note is github.GithubObject.NotSet or isinstance(note, str), note
assert archived is github.GithubObject.NotSet or isinstance(
archived, bool
), archived
assert archived is github.GithubObject.NotSet or isinstance(archived, bool), archived
patch_parameters = dict()
if note is not github.GithubObject.NotSet:
patch_parameters["note"] = note
@@ -220,9 +210,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject):
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "creator" in attributes: # pragma no branch
self._creator = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["creator"]
)
self._creator = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["creator"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "node_id" in attributes: # pragma no branch
+2 -6
View File
@@ -20,12 +20,8 @@ class ProjectCard(CompletableGithubObject):
def created_at(self) -> datetime: ...
@property
def creator(self) -> NamedUser: ...
def get_content(
self, content_type: Union[_NotSetType, str] = ...
) -> Optional[Union[PullRequest, Issue]]: ...
def edit(
self, note=Union[_NotSetType, str], archived=Union[_NotSetType, bool]
) -> None: ...
def get_content(self, content_type: Union[_NotSetType, str] = ...) -> Optional[Union[PullRequest, Issue]]: ...
def edit(self, note=Union[_NotSetType, str], archived=Union[_NotSetType, bool]) -> None: ...
@property
def id(self) -> int: ...
@property
+2 -6
View File
@@ -97,9 +97,7 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.ProjectCard.ProjectCard`
:param archived_state: string
"""
assert archived_state is github.GithubObject.NotSet or isinstance(
archived_state, str
), archived_state
assert archived_state is github.GithubObject.NotSet or isinstance(archived_state, str), archived_state
url_parameters = dict()
if archived_state is not github.GithubObject.NotSet:
@@ -141,9 +139,7 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/cards", headers=import_header, input=post_parameters
)
return github.ProjectCard.ProjectCard(
self._requester, headers, data, completed=True
)
return github.ProjectCard.ProjectCard(self._requester, headers, data, completed=True)
def move(self, position):
"""
+1 -3
View File
@@ -19,9 +19,7 @@ class ProjectColumn(CompletableGithubObject):
) -> ProjectCard: ...
@property
def created_at(self) -> datetime: ...
def get_cards(
self, archived_state: Union[_NotSetType, str] = ...
) -> PaginatedList[ProjectCard]: ...
def get_cards(self, archived_state: Union[_NotSetType, str] = ...) -> PaginatedList[ProjectCard]: ...
@property
def id(self) -> int: ...
@property
+60 -184
View File
@@ -64,9 +64,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"number": self._number.value, "title": self._title.value}
)
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@property
def additions(self):
@@ -442,16 +440,12 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
assert isinstance(path, str), path
assert line is github.GithubObject.NotSet or isinstance(line, int), line
assert side is github.GithubObject.NotSet or side in ["LEFT", "RIGHT"], side
assert start_line is github.GithubObject.NotSet or isinstance(
start_line, int
), start_line
assert start_line is github.GithubObject.NotSet or isinstance(start_line, int), start_line
assert start_side is github.GithubObject.NotSet or start_side in [
"LEFT",
"RIGHT",
], start_side
assert in_reply_to is github.GithubObject.NotSet or isinstance(
in_reply_to, int
), in_reply_to
assert in_reply_to is github.GithubObject.NotSet or isinstance(in_reply_to, int), in_reply_to
assert subject_type is github.GithubObject.NotSet or subject_type in [
"LINE",
"FILE",
@@ -478,12 +472,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
post_parameters["in_reply_to"] = in_reply_to
if subject_type is not github.GithubObject.NotSet:
post_parameters["subject_type"] = subject_type
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/comments", input=post_parameters
)
return github.PullRequestComment.PullRequestComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/comments", input=post_parameters)
return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True)
def create_review_comment_reply(self, comment_id, body):
"""
@@ -500,9 +490,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
f"{self.url}/comments/{comment_id}/replies",
input=post_parameters,
)
return github.PullRequestComment.PullRequestComment(
self._requester, headers, data, completed=True
)
return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True)
def create_issue_comment(self, body):
"""
@@ -514,12 +502,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.issue_url}/comments", input=post_parameters
)
return github.IssueComment.IssueComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.issue_url}/comments", input=post_parameters)
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
def create_review(
self,
@@ -536,32 +520,22 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param comments: list
:rtype: :class:`github.PullRequestReview.PullRequestReview`
"""
assert commit is github.GithubObject.NotSet or isinstance(
commit, github.Commit.Commit
), commit
assert commit is github.GithubObject.NotSet or isinstance(commit, github.Commit.Commit), commit
assert body is github.GithubObject.NotSet or isinstance(body, str), body
assert event is github.GithubObject.NotSet or isinstance(event, str), event
assert comments is github.GithubObject.NotSet or isinstance(
comments, list
), comments
assert comments is github.GithubObject.NotSet or isinstance(comments, list), comments
post_parameters = dict()
if commit is not github.GithubObject.NotSet:
post_parameters["commit_id"] = commit.sha
if body is not github.GithubObject.NotSet:
post_parameters["body"] = body
post_parameters["event"] = (
"COMMENT" if event == github.GithubObject.NotSet else event
)
post_parameters["event"] = "COMMENT" if event == github.GithubObject.NotSet else event
if comments is github.GithubObject.NotSet:
post_parameters["comments"] = []
else:
post_parameters["comments"] = comments
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/reviews", input=post_parameters
)
return github.PullRequestReview.PullRequestReview(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/reviews", input=post_parameters)
return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True)
def create_review_request(
self,
@@ -579,9 +553,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
assert all(isinstance(element, str) for element in reviewers), reviewers
post_parameters["reviewers"] = reviewers
if team_reviewers is not github.GithubObject.NotSet:
assert all(
isinstance(element, str) for element in team_reviewers
), team_reviewers
assert all(isinstance(element, str) for element in team_reviewers), team_reviewers
post_parameters["team_reviewers"] = team_reviewers
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/requested_reviewers", input=post_parameters
@@ -603,9 +575,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
assert all(isinstance(element, str) for element in reviewers), reviewers
post_parameters["reviewers"] = reviewers
if team_reviewers is not github.GithubObject.NotSet:
assert all(
isinstance(element, str) for element in team_reviewers
), team_reviewers
assert all(isinstance(element, str) for element in team_reviewers), team_reviewers
post_parameters["team_reviewers"] = team_reviewers
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/requested_reviewers", input=post_parameters
@@ -646,9 +616,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
post_parameters["base"] = base
if maintainer_can_modify is not github.GithubObject.NotSet:
post_parameters["maintainer_can_modify"] = maintainer_can_modify
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_comment(self, id):
@@ -666,12 +634,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.PullRequestComment.PullRequestComment`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self._parentUrl(self.url)}/comments/{id}"
)
return github.PullRequestComment.PullRequestComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self._parentUrl(self.url)}/comments/{id}")
return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True)
def get_comments(
self,
@@ -706,9 +670,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment`
"""
assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort
assert direction is github.GithubObject.NotSet or isinstance(
direction, str
), direction
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 sort is not github.GithubObject.NotSet:
@@ -743,18 +705,14 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:calls: `GET /repos/{owner}/{repo}/pulls/{number}/commits <https://docs.github.com/en/rest/reference/pulls>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit`
"""
return github.PaginatedList.PaginatedList(
github.Commit.Commit, self._requester, f"{self.url}/commits", None
)
return github.PaginatedList.PaginatedList(github.Commit.Commit, self._requester, f"{self.url}/commits", None)
def get_files(self):
"""
:calls: `GET /repos/{owner}/{repo}/pulls/{number}/files <https://docs.github.com/en/rest/reference/pulls>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.File.File`
"""
return github.PaginatedList.PaginatedList(
github.File.File, self._requester, f"{self.url}/files", None
)
return github.PaginatedList.PaginatedList(github.File.File, self._requester, f"{self.url}/files", None)
def get_issue_comment(self, id):
"""
@@ -763,12 +721,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.IssueComment.IssueComment`
"""
assert isinstance(id, int), id
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self._parentUrl(self.issue_url)}/comments/{id}"
)
return github.IssueComment.IssueComment(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self._parentUrl(self.issue_url)}/comments/{id}")
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
def get_issue_comments(self):
"""
@@ -806,9 +760,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
"GET",
f"{self.url}/reviews/{id}",
)
return github.PullRequestReview.PullRequestReview(
self._requester, headers, data, completed=True
)
return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True)
def get_reviews(self):
"""
@@ -849,9 +801,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:calls: `GET /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label`
"""
return github.PaginatedList.PaginatedList(
github.Label.Label, self._requester, f"{self.issue_url}/labels", None
)
return github.PaginatedList.PaginatedList(github.Label.Label, self._requester, f"{self.issue_url}/labels", None)
def add_to_labels(self, *labels):
"""
@@ -859,25 +809,16 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param label: :class:`github.Label.Label` or string
:rtype: None
"""
assert all(
isinstance(element, (github.Label.Label, str)) for element in labels
), labels
post_parameters = [
label.name if isinstance(label, github.Label.Label) else label
for label in labels
]
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.issue_url}/labels", input=post_parameters
)
assert all(isinstance(element, (github.Label.Label, str)) for element in labels), labels
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.issue_url}/labels", input=post_parameters)
def delete_labels(self):
"""
:calls: `DELETE /repos/{owner}/{repo}/issues/{number}/labels <https://docs.github.com/en/rest/reference/issues#labels>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.issue_url}/labels"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.issue_url}/labels")
def remove_from_labels(self, label):
"""
@@ -890,9 +831,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
label = label._identity
else:
label = urllib.parse.quote(label)
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.issue_url}/labels/{label}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.issue_url}/labels/{label}")
def set_labels(self, *labels):
"""
@@ -900,16 +839,9 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param labels: list of :class:`github.Label.Label` or strings
:rtype: None
"""
assert all(
isinstance(element, (github.Label.Label, str)) for element in labels
), labels
post_parameters = [
label.name if isinstance(label, github.Label.Label) else label
for label in labels
]
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.issue_url}/labels", input=post_parameters
)
assert all(isinstance(element, (github.Label.Label, str)) for element in labels), labels
post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels]
headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.issue_url}/labels", input=post_parameters)
def is_merged(self):
"""
@@ -934,15 +866,9 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param sha: string
:rtype: :class:`github.PullRequestMergeStatus.PullRequestMergeStatus`
"""
assert commit_message is github.GithubObject.NotSet or isinstance(
commit_message, str
), commit_message
assert commit_title is github.GithubObject.NotSet or isinstance(
commit_title, str
), commit_title
assert merge_method is github.GithubObject.NotSet or isinstance(
merge_method, str
), merge_method
assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, str), commit_message
assert commit_title is github.GithubObject.NotSet or isinstance(commit_title, str), commit_title
assert merge_method is github.GithubObject.NotSet or isinstance(merge_method, str), merge_method
assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha
post_parameters = dict()
if commit_message is not github.GithubObject.NotSet:
@@ -953,12 +879,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
post_parameters["merge_method"] = merge_method
if sha is not github.GithubObject.NotSet:
post_parameters["sha"] = sha
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/merge", input=post_parameters
)
return github.PullRequestMergeStatus.PullRequestMergeStatus(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/merge", input=post_parameters)
return github.PullRequestMergeStatus.PullRequestMergeStatus(self._requester, headers, data, completed=True)
def add_to_assignees(self, *assignees):
"""
@@ -966,15 +888,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param assignees: list of :class:`github.NamedUser.NamedUser` or string
:rtype: None
"""
assert all(
isinstance(element, (github.NamedUser.NamedUser, str))
for element in assignees
), assignees
assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees
post_parameters = {
"assignees": [
assignee.login
if isinstance(assignee, github.NamedUser.NamedUser)
else assignee
assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee
for assignee in assignees
]
}
@@ -990,15 +907,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param assignees: list of :class:`github.NamedUser.NamedUser` or string
:rtype: None
"""
assert all(
isinstance(element, (github.NamedUser.NamedUser, str))
for element in assignees
), assignees
assert all(isinstance(element, (github.NamedUser.NamedUser, str)) for element in assignees), assignees
post_parameters = {
"assignees": [
assignee.login
if isinstance(assignee, github.NamedUser.NamedUser)
else assignee
assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee
for assignee in assignees
]
}
@@ -1014,9 +926,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:param expected_head_sha: string
:rtype: bool
"""
assert expected_head_sha is github.GithubObject.NotSet or isinstance(
expected_head_sha, str
), expected_head_sha
assert expected_head_sha is github.GithubObject.NotSet or isinstance(expected_head_sha, str), expected_head_sha
post_parameters = {}
if expected_head_sha is not github.GithubObject.NotSet:
post_parameters["expected_head_sha"] = expected_head_sha
@@ -1075,26 +985,16 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
if "additions" in attributes: # pragma no branch
self._additions = self._makeIntAttribute(attributes["additions"])
if "assignee" in attributes: # pragma no branch
self._assignee = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["assignee"]
)
self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"])
if "assignees" in attributes: # pragma no branch
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, attributes["assignees"]
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, attributes["assignees"])
elif "assignee" in attributes:
if attributes["assignee"] is not None:
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, [attributes["assignee"]]
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [attributes["assignee"]])
else:
self._assignees = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, []
)
self._assignees = self._makeListOfClassesAttribute(github.NamedUser.NamedUser, [])
if "base" in attributes: # pragma no branch
self._base = self._makeClassAttribute(
github.PullRequestPart.PullRequestPart, attributes["base"]
)
self._base = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["base"])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "changed_files" in attributes: # pragma no branch
@@ -1118,9 +1018,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
if "draft" in attributes: # pragma no branch
self._draft = self._makeBoolAttribute(attributes["draft"])
if "head" in attributes: # pragma no branch
self._head = self._makeClassAttribute(
github.PullRequestPart.PullRequestPart, attributes["head"]
)
self._head = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["head"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "id" in attributes: # pragma no branch
@@ -1128,35 +1026,23 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
if "issue_url" in attributes: # pragma no branch
self._issue_url = self._makeStringAttribute(attributes["issue_url"])
if "labels" in attributes: # pragma no branch
self._labels = self._makeListOfClassesAttribute(
github.Label.Label, attributes["labels"]
)
self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"])
if "maintainer_can_modify" in attributes: # pragma no branch
self._maintainer_can_modify = self._makeBoolAttribute(
attributes["maintainer_can_modify"]
)
self._maintainer_can_modify = self._makeBoolAttribute(attributes["maintainer_can_modify"])
if "merge_commit_sha" in attributes: # pragma no branch
self._merge_commit_sha = self._makeStringAttribute(
attributes["merge_commit_sha"]
)
self._merge_commit_sha = self._makeStringAttribute(attributes["merge_commit_sha"])
if "mergeable" in attributes: # pragma no branch
self._mergeable = self._makeBoolAttribute(attributes["mergeable"])
if "mergeable_state" in attributes: # pragma no branch
self._mergeable_state = self._makeStringAttribute(
attributes["mergeable_state"]
)
self._mergeable_state = self._makeStringAttribute(attributes["mergeable_state"])
if "merged" in attributes: # pragma no branch
self._merged = self._makeBoolAttribute(attributes["merged"])
if "merged_at" in attributes: # pragma no branch
self._merged_at = self._makeDatetimeAttribute(attributes["merged_at"])
if "merged_by" in attributes: # pragma no branch
self._merged_by = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["merged_by"]
)
self._merged_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["merged_by"])
if "milestone" in attributes: # pragma no branch
self._milestone = self._makeClassAttribute(
github.Milestone.Milestone, attributes["milestone"]
)
self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"])
if "number" in attributes: # pragma no branch
self._number = self._makeIntAttribute(attributes["number"])
if "patch_url" in attributes: # pragma no branch
@@ -1164,17 +1050,11 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
if "rebaseable" in attributes: # pragma no branch
self._rebaseable = self._makeBoolAttribute(attributes["rebaseable"])
if "review_comment_url" in attributes: # pragma no branch
self._review_comment_url = self._makeStringAttribute(
attributes["review_comment_url"]
)
self._review_comment_url = self._makeStringAttribute(attributes["review_comment_url"])
if "review_comments" in attributes: # pragma no branch
self._review_comments = self._makeIntAttribute(
attributes["review_comments"]
)
self._review_comments = self._makeIntAttribute(attributes["review_comments"])
if "review_comments_url" in attributes: # pragma no branch
self._review_comments_url = self._makeStringAttribute(
attributes["review_comments_url"]
)
self._review_comments_url = self._makeStringAttribute(attributes["review_comments_url"])
if "state" in attributes: # pragma no branch
self._state = self._makeStringAttribute(attributes["state"])
if "title" in attributes: # pragma no branch
@@ -1184,14 +1064,10 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
if "requested_reviewers" in attributes:
self._requested_reviewers = self._makeListOfClassesAttribute(
github.NamedUser.NamedUser, attributes["requested_reviewers"]
)
if "requested_teams" in attributes:
self._requested_teams = self._makeListOfClassesAttribute(
github.Team.Team, attributes["requested_teams"]
)
self._requested_teams = self._makeListOfClassesAttribute(github.Team.Team, attributes["requested_teams"])
+3 -9
View File
@@ -49,9 +49,7 @@ class PullRequest(CompletableGithubObject):
def commits(self) -> int: ...
@property
def commits_url(self) -> str: ...
def create_comment(
self, body: str, commit_id: Commit, path: str, position: int
) -> PullRequestComment: ...
def create_comment(self, body: str, commit_id: Commit, path: str, position: int) -> PullRequestComment: ...
def create_issue_comment(self, body: str) -> IssueComment: ...
def create_review(
self,
@@ -60,9 +58,7 @@ class PullRequest(CompletableGithubObject):
event: Union[_NotSetType, str] = ...,
comments: Union[_NotSetType, str] = ...,
) -> PullRequestReview: ...
def create_review_comment(
self, body: str, commit_id: Commit, path: str, position: int
) -> PullRequestComment: ...
def create_review_comment(self, body: str, commit_id: Commit, path: str, position: int) -> PullRequestComment: ...
def create_review_request(
self,
reviewers: Union[_NotSetType, List[str]] = ...,
@@ -110,9 +106,7 @@ class PullRequest(CompletableGithubObject):
direction: Union[_NotSetType, str] = ...,
since: Union[_NotSetType, datetime] = ...,
) -> PaginatedList[PullRequestComment]: ...
def get_single_review_comments(
self, id: int
) -> PaginatedList[PullRequestComment]: ...
def get_single_review_comments(self, id: int) -> PaginatedList[PullRequestComment]: ...
def get_review_requests(
self,
) -> Tuple[PaginatedList[NamedUser], PaginatedList[Team]]: ...
+5 -15
View File
@@ -184,9 +184,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject):
post_parameters = {
"body": body,
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_reactions(self):
@@ -268,21 +266,15 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject):
if "in_reply_to_id" in attributes: # pragma no branch
self._in_reply_to_id = self._makeIntAttribute(attributes["in_reply_to_id"])
if "original_commit_id" in attributes: # pragma no branch
self._original_commit_id = self._makeStringAttribute(
attributes["original_commit_id"]
)
self._original_commit_id = self._makeStringAttribute(attributes["original_commit_id"])
if "original_position" in attributes: # pragma no branch
self._original_position = self._makeIntAttribute(
attributes["original_position"]
)
self._original_position = self._makeIntAttribute(attributes["original_position"])
if "path" in attributes: # pragma no branch
self._path = self._makeStringAttribute(attributes["path"])
if "position" in attributes: # pragma no branch
self._position = self._makeIntAttribute(attributes["position"])
if "pull_request_url" in attributes: # pragma no branch
self._pull_request_url = self._makeStringAttribute(
attributes["pull_request_url"]
)
self._pull_request_url = self._makeStringAttribute(attributes["pull_request_url"])
if "updated_at" in attributes: # pragma no branch
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
@@ -290,6 +282,4 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+2 -6
View File
@@ -81,12 +81,8 @@ class PullRequestPart(NonCompletableGithubObject):
if "ref" in attributes: # pragma no branch
self._ref = self._makeStringAttribute(attributes["ref"])
if "repo" in attributes: # pragma no branch
self._repo = self._makeClassAttribute(
github.Repository.Repository, attributes["repo"]
)
self._repo = self._makeClassAttribute(github.Repository.Repository, attributes["repo"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+3 -9
View File
@@ -110,9 +110,7 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject):
:calls: `DELETE /repos/:owner/:repo/pulls/:number/reviews/:review_id <https://developer.github.com/v3/pulls/reviews/>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.pull_request_url}/reviews/{self.id}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.pull_request_url}/reviews/{self.id}")
def _initAttributes(self):
self._id = github.GithubObject.NotSet
@@ -128,9 +126,7 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "commit_id" in attributes: # pragma no branch
@@ -140,8 +136,6 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "pull_request_url" in attributes: # pragma no branch
self._pull_request_url = self._makeStringAttribute(
attributes["pull_request_url"]
)
self._pull_request_url = self._makeStringAttribute(attributes["pull_request_url"])
if "submitted_at" in attributes: # pragma no branch
self._submitted_at = self._makeDatetimeAttribute(attributes["submitted_at"])
+2 -6
View File
@@ -80,10 +80,6 @@ class RateLimit(NonCompletableGithubObject):
if "core" in attributes: # pragma no branch
self._core = self._makeClassAttribute(github.Rate.Rate, attributes["core"])
if "search" in attributes: # pragma no branch
self._search = self._makeClassAttribute(
github.Rate.Rate, attributes["search"]
)
self._search = self._makeClassAttribute(github.Rate.Rate, attributes["search"])
if "graphql" in attributes: # pragma no branch
self._graphql = self._makeClassAttribute(
github.Rate.Rate, attributes["graphql"]
)
self._graphql = self._makeClassAttribute(github.Rate.Rate, attributes["graphql"])
+1 -3
View File
@@ -88,6 +88,4 @@ class Reaction(CompletableGithubObject):
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+242 -732
View File
File diff suppressed because it is too large Load Diff
+23 -69
View File
@@ -74,9 +74,7 @@ from github.WorkflowRun import WorkflowRun
class Repository(CompletableGithubObject):
def __repr__(self) -> str: ...
def _hub(
self, mode: str, event: str, callback: str, secret: Union[str, _NotSetType]
) -> None: ...
def _hub(self, mode: str, event: str, callback: str, secret: Union[str, _NotSetType]) -> None: ...
@property
def _identity(self) -> str: ...
def _initAttributes(self) -> None: ...
@@ -135,9 +133,7 @@ class Repository(CompletableGithubObject):
started_at: Union[_NotSetType, datetime] = ...,
conclusion: Union[_NotSetType, str] = ...,
completed_at: Union[_NotSetType, datetime] = ...,
output: Union[
_NotSetType, Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]
] = ...,
output: Union[_NotSetType, Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]] = ...,
actions: Union[_NotSetType, List[Dict[str, str]]] = ...,
) -> CheckRun: ...
def create_check_suite(self, head_sha: str) -> CheckSuite: ...
@@ -160,9 +156,7 @@ class Repository(CompletableGithubObject):
environment_name: str,
wait_timer: int = ...,
reviewers: List[ReviewerParams] = ...,
deployment_branch_policy: Optional[
EnvironmentDeploymentBranchPolicyParams
] = ...,
deployment_branch_policy: Optional[EnvironmentDeploymentBranchPolicyParams] = ...,
) -> Environment: ...
def create_file(
self,
@@ -235,12 +229,8 @@ class Repository(CompletableGithubObject):
labels: Union[List[Label], _NotSetType, List[str]] = ...,
assignees: Union[_NotSetType, List[str], List[NamedUser]] = ...,
) -> Issue: ...
def create_key(
self, title: str, key: str, read_only: bool = ...
) -> RepositoryKey: ...
def create_label(
self, name: str, color: str, description: Union[str, _NotSetType] = ...
) -> Label: ...
def create_key(self, title: str, key: str, read_only: bool = ...) -> RepositoryKey: ...
def create_label(self, name: str, color: str, description: Union[str, _NotSetType] = ...) -> Label: ...
def create_milestone(
self,
title: str,
@@ -248,9 +238,7 @@ class Repository(CompletableGithubObject):
description: Union[str, _NotSetType] = ...,
due_on: Union[date, _NotSetType] = ...,
) -> Milestone: ...
def create_project(
self, name: str, body: Union[str, _NotSetType] = ...
) -> Project: ...
def create_project(self, name: str, body: Union[str, _NotSetType] = ...) -> Project: ...
@overload
def create_pull(
self,
@@ -365,13 +353,9 @@ class Repository(CompletableGithubObject):
def forks_url(self) -> str: ...
@property
def full_name(self) -> str: ...
def get_archive_link(
self, archive_format: str, ref: Union[str, _NotSetType] = ...
) -> str: ...
def get_archive_link(self, archive_format: str, ref: Union[str, _NotSetType] = ...) -> str: ...
def get_artifact(self, artifact_id: int) -> Artifact: ...
def get_artifacts(
self, name: Union[str, _NotSetType] = ...
) -> PaginatedList[Artifact]: ...
def get_artifacts(self, name: Union[str, _NotSetType] = ...) -> PaginatedList[Artifact]: ...
def get_codescan_alerts(self) -> PaginatedList[CodeScanAlert]: ...
def get_assignees(self) -> PaginatedList[NamedUser]: ...
def get_autolinks(self) -> PaginatedList[Autolink]: ...
@@ -380,15 +364,9 @@ class Repository(CompletableGithubObject):
def get_branches(self) -> PaginatedList[Branch]: ...
def get_check_run(self, check_run_id: int) -> CheckRun: ...
def get_check_suite(self, check_suite_id: int) -> CheckSuite: ...
def get_clones_traffic(
self, per: Union[str, _NotSetType] = ...
) -> Dict[str, Union[int, List[Clones]]]: ...
def get_collaborator_permission(
self, collaborator: Union[str, NamedUser]
) -> str: ...
def get_collaborators(
self, affiliation: Union[str, _NotSetType] = ...
) -> PaginatedList[NamedUser]: ...
def get_clones_traffic(self, per: Union[str, _NotSetType] = ...) -> Dict[str, Union[int, List[Clones]]]: ...
def get_collaborator_permission(self, collaborator: Union[str, NamedUser]) -> str: ...
def get_collaborators(self, affiliation: Union[str, _NotSetType] = ...) -> PaginatedList[NamedUser]: ...
def get_comment(self, id: int) -> CommitComment: ...
def get_comments(self) -> PaginatedList[CommitComment]: ...
def get_commit(self, sha: str) -> Commit: ...
@@ -400,12 +378,8 @@ class Repository(CompletableGithubObject):
until: Union[_NotSetType, datetime] = ...,
author: Union[AuthenticatedUser, NamedUser, str, _NotSetType] = ...,
) -> PaginatedList[Commit]: ...
def get_contents(
self, path: str, ref: Union[str, _NotSetType] = ...
) -> Union[List[ContentFile], ContentFile]: ...
def get_contributors(
self, anon: Union[str, _NotSetType] = ...
) -> PaginatedList[NamedUser]: ...
def get_contents(self, path: str, ref: Union[str, _NotSetType] = ...) -> Union[List[ContentFile], ContentFile]: ...
def get_contributors(self, anon: Union[str, _NotSetType] = ...) -> PaginatedList[NamedUser]: ...
def get_deployment(self, id_: int) -> Deployment: ...
def get_deployments(
self,
@@ -414,9 +388,7 @@ class Repository(CompletableGithubObject):
task: Union[str, _NotSetType] = ...,
environment: Union[str, _NotSetType] = ...,
) -> PaginatedList[Deployment]: ...
def get_dir_contents(
self, path: str, ref: Union[str, _NotSetType] = ...
) -> List[ContentFile]: ...
def get_dir_contents(self, path: str, ref: Union[str, _NotSetType] = ...) -> List[ContentFile]: ...
def get_download(self, id: int) -> Download: ...
def get_downloads(self) -> PaginatedList[Download]: ...
def get_environments(self) -> PaginatedList[Environment]: ...
@@ -435,15 +407,11 @@ class Repository(CompletableGithubObject):
def get_git_ref(self, ref: str) -> GitRef: ...
def get_git_refs(self) -> PaginatedList[GitRef]: ...
def get_git_tag(self, sha: str) -> GitTag: ...
def get_git_tree(
self, sha: str, recursive: Union[bool, _NotSetType] = ...
) -> GitTree: ...
def get_git_tree(self, sha: str, recursive: Union[bool, _NotSetType] = ...) -> GitTree: ...
def get_hook(self, id: int) -> Hook: ...
def get_hooks(self) -> PaginatedList[Hook]: ...
def get_hook_delivery(self, hook_id: int, delivery_id: int) -> HookDelivery: ...
def get_hook_deliveries(
self, hook_id: int
) -> PaginatedList[HookDeliverySummary]: ...
def get_hook_deliveries(self, hook_id: int) -> PaginatedList[HookDeliverySummary]: ...
def get_issue(self, number: int) -> Issue: ...
def get_issues(
self,
@@ -488,9 +456,7 @@ class Repository(CompletableGithubObject):
before: Union[datetime, _NotSetType] = ...,
) -> PaginatedList[Notification]: ...
def get_pending_invitations(self) -> PaginatedList[Invitation]: ...
def get_projects(
self, state: Union[str, _NotSetType] = ...
) -> PaginatedList[Project]: ...
def get_projects(self, state: Union[str, _NotSetType] = ...) -> PaginatedList[Project]: ...
def get_public_key(self) -> PublicKey: ...
def get_pull(self, number: int) -> PullRequest: ...
def get_pulls(
@@ -533,9 +499,7 @@ class Repository(CompletableGithubObject):
def get_top_paths(self) -> List[Path]: ...
def get_top_referrers(self) -> List[Referrer]: ...
def get_topics(self) -> List[str]: ...
def get_views_traffic(
self, per: Union[str, _NotSetType] = ...
) -> Dict[str, Union[int, List[View]]]: ...
def get_views_traffic(self, per: Union[str, _NotSetType] = ...) -> Dict[str, Union[int, List[View]]]: ...
def get_vulnerability_alert(self) -> bool: ...
def get_watchers(self) -> PaginatedList[NamedUser]: ...
def get_workflow(self, id_or_name: Union[str, int]) -> Workflow: ...
@@ -601,9 +565,7 @@ class Repository(CompletableGithubObject):
def mark_notifications_as_read(self, last_read_at: datetime = ...) -> None: ...
@property
def master_branch(self) -> Optional[str]: ...
def merge(
self, base: str, head: str, commit_message: Union[str, _NotSetType] = ...
) -> Optional[Commit]: ...
def merge(self, base: str, head: str, commit_message: Union[str, _NotSetType] = ...) -> Optional[Commit]: ...
@property
def merges_url(self) -> str: ...
@property
@@ -637,12 +599,8 @@ class Repository(CompletableGithubObject):
@property
def releases_url(self) -> str: ...
def remove_autolink(self, autolink: Union[Autolink, int]) -> bool: ...
def remove_from_collaborators(
self, collaborator: Union[str, NamedUser]
) -> None: ...
def remove_self_hosted_runner(
self, runner: Union[SelfHostedActionsRunner, int]
) -> bool: ...
def remove_from_collaborators(self, collaborator: Union[str, NamedUser]) -> None: ...
def remove_self_hosted_runner(self, runner: Union[SelfHostedActionsRunner, int]) -> bool: ...
def remove_invitation(self, invite_id: int) -> None: ...
def replace_topics(self, topics: List[str]) -> None: ...
@property
@@ -657,9 +615,7 @@ class Repository(CompletableGithubObject):
def stargazers_url(self) -> str: ...
@property
def statuses_url(self) -> str: ...
def subscribe_to_hub(
self, event: str, callback: str, secret: Union[str, _NotSetType] = ...
) -> None: ...
def subscribe_to_hub(self, event: str, callback: str, secret: Union[str, _NotSetType] = ...) -> None: ...
@property
def subscribers_count(self) -> int: ...
@property
@@ -682,9 +638,7 @@ class Repository(CompletableGithubObject):
environment_name: str,
wait_timer: int = ...,
reviewers: List[ReviewerParams] = ...,
deployment_branch_policy: Optional[
EnvironmentDeploymentBranchPolicyParams
] = ...,
deployment_branch_policy: Optional[EnvironmentDeploymentBranchPolicyParams] = ...,
) -> Environment: ...
def update_file(
self,
+34 -75
View File
@@ -28,10 +28,7 @@ import github.NamedUser
from github.CWE import CWE
from github.RepositoryAdvisoryCredit import Credit, RepositoryAdvisoryCredit
from github.RepositoryAdvisoryCreditDetailed import RepositoryAdvisoryCreditDetailed
from github.RepositoryAdvisoryVulnerability import (
AdvisoryVulnerability,
RepositoryAdvisoryVulnerability,
)
from github.RepositoryAdvisoryVulnerability import AdvisoryVulnerability, RepositoryAdvisoryVulnerability
from github.Requester import Requester
@@ -215,9 +212,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
]
)
def add_vulnerabilities(
self, vulnerabilities: typing.Iterable[AdvisoryVulnerability]
):
def add_vulnerabilities(self, vulnerabilities: typing.Iterable[AdvisoryVulnerability]):
"""
:calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id <https://docs.github.com/en/rest/security-advisories/repository-advisories>`
:param vulnerabilities: iterable of :class:`github.RepositoryAdvisoryVulnerability.AdvisoryVulnerability`
@@ -231,9 +226,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
# noinspection PyProtectedMember
post_parameters = {
"vulnerabilities": [
github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._to_github_dict(
vulnerability
)
github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._to_github_dict(vulnerability)
for vulnerability in (self.vulnerabilities + list(vulnerabilities))
]
}
@@ -274,10 +267,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
RepositoryAdvisoryCredit._validate_credit(credit)
# noinspection PyProtectedMember
patch_parameters = {
"credits": [
RepositoryAdvisoryCredit._to_github_dict(credit)
for credit in (self.credits + list(credited))
]
"credits": [RepositoryAdvisoryCredit._to_github_dict(credit) for credit in (self.credits + list(credited))]
}
headers, data = self._requester.requestJsonAndCheck(
"PATCH",
@@ -286,23 +276,17 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
)
self._useAttributes(data)
def revoke_credit(
self, login_or_user: typing.Union[str, "github.NamedUser.NamedUser"]
):
def revoke_credit(self, login_or_user: typing.Union[str, "github.NamedUser.NamedUser"]):
"""
:calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id <https://docs.github.com/en/rest/security-advisories/repository-advisories>`_
:param login_or_user: string username or :class:`github.NamedUser.NamedUser`
"""
assert isinstance(
login_or_user, (str, github.NamedUser.NamedUser)
), login_or_user
assert isinstance(login_or_user, (str, github.NamedUser.NamedUser)), login_or_user
if isinstance(login_or_user, github.NamedUser.NamedUser):
login_or_user = login_or_user.login
patch_parameters = {
"credits": [
dict(login=credit.login, type=credit.type)
for credit in self.credits
if credit.login != login_or_user
dict(login=credit.login, type=credit.type) for credit in self.credits if credit.login != login_or_user
]
}
headers, data = self._requester.requestJsonAndCheck(
@@ -328,19 +312,11 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
self,
summary: github.GithubObject.Opt[str] = github.GithubObject.NotSet,
description: github.GithubObject.Opt[str] = github.GithubObject.NotSet,
severity_or_cvss_vector_string: github.GithubObject.Opt[
str
] = github.GithubObject.NotSet,
severity_or_cvss_vector_string: github.GithubObject.Opt[str] = github.GithubObject.NotSet,
cve_id: github.GithubObject.Opt[str] = github.GithubObject.NotSet,
vulnerabilities: github.GithubObject.Opt[
typing.Iterable[AdvisoryVulnerability]
] = github.GithubObject.NotSet,
cwe_ids: github.GithubObject.Opt[
typing.Iterable[str]
] = github.GithubObject.NotSet,
credits: github.GithubObject.Opt[
typing.Iterable[Credit]
] = github.GithubObject.NotSet,
vulnerabilities: github.GithubObject.Opt[typing.Iterable[AdvisoryVulnerability]] = github.GithubObject.NotSet,
cwe_ids: github.GithubObject.Opt[typing.Iterable[str]] = github.GithubObject.NotSet,
credits: github.GithubObject.Opt[typing.Iterable[Credit]] = github.GithubObject.NotSet,
state: github.GithubObject.Opt[str] = github.GithubObject.NotSet,
) -> "RepositoryAdvisory":
"""
@@ -355,16 +331,11 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
:param state: string
:rtype: :class:`github.RepositoryAdvisory.RepositoryAdvisory`
"""
assert summary is github.GithubObject.NotSet or isinstance(
summary, str
), summary
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert (
severity_or_cvss_vector_string is github.GithubObject.NotSet
or isinstance(severity_or_cvss_vector_string, str)
), (severity_or_cvss_vector_string)
assert summary is github.GithubObject.NotSet or isinstance(summary, str), summary
assert description is github.GithubObject.NotSet or isinstance(description, str), description
assert severity_or_cvss_vector_string is github.GithubObject.NotSet or isinstance(
severity_or_cvss_vector_string, str
), severity_or_cvss_vector_string
assert cve_id is github.GithubObject.NotSet or isinstance(cve_id, str), cve_id
assert vulnerabilities is github.GithubObject.NotSet or isinstance(
vulnerabilities, typing.Iterable
@@ -376,15 +347,12 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
vulnerability
)
assert cwe_ids is github.GithubObject.NotSet or (
isinstance(cwe_ids, typing.Iterable)
and all(isinstance(element, str) for element in cwe_ids)
isinstance(cwe_ids, typing.Iterable) and all(isinstance(element, str) for element in cwe_ids)
), cwe_ids
if isinstance(credits, typing.Iterable):
for credit in credits:
# noinspection PyProtectedMember
github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._validate_credit(
credit
)
github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._validate_credit(credit)
assert state is github.GithubObject.NotSet or isinstance(state, str), state
patch_parameters: typing.Dict[str, typing.Any] = dict()
if summary is not github.GithubObject.NotSet:
@@ -401,9 +369,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
if isinstance(vulnerabilities, typing.Iterable):
# noinspection PyProtectedMember
patch_parameters["vulnerabilities"] = [
github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._to_github_dict(
vulnerability
)
github.RepositoryAdvisoryVulnerability.RepositoryAdvisoryVulnerability._to_github_dict(vulnerability)
for vulnerability in vulnerabilities
]
if isinstance(cwe_ids, typing.Iterable):
@@ -411,10 +377,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
if isinstance(credits, typing.Iterable):
# noinspection PyProtectedMember
patch_parameters["credits"] = [
github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._to_github_dict(
credit
)
for credit in credits
github.RepositoryAdvisoryCredit.RepositoryAdvisoryCredit._to_github_dict(credit) for credit in credits
]
if state is not github.GithubObject.NotSet:
patch_parameters["state"] = state
@@ -491,18 +454,14 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
# noinspection PyPep8Naming
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
self._author = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["author"]
)
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "closed_at" in attributes: # pragma no branch
assert attributes["closed_at"] is None or isinstance(
attributes["closed_at"], str
), attributes["closed_at"]
assert attributes["closed_at"] is None or isinstance(attributes["closed_at"], str), attributes["closed_at"]
self._closed_at = self._makeDatetimeAttribute(attributes["closed_at"])
if "created_at" in attributes: # pragma no branch
assert attributes["created_at"] is None or isinstance(
attributes["created_at"], str
), attributes["created_at"]
assert attributes["created_at"] is None or isinstance(attributes["created_at"], str), attributes[
"created_at"
]
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "credits" in attributes: # pragma no branch
self._credits = self._makeListOfClassesAttribute(
@@ -527,9 +486,9 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "published_at" in attributes: # pragma no branch
assert attributes["published_at"] is None or isinstance(
attributes["published_at"], str
), attributes["published_at"]
assert attributes["published_at"] is None or isinstance(attributes["published_at"], str), attributes[
"published_at"
]
self._published_at = self._makeDatetimeAttribute(attributes["published_at"])
if "severity" in attributes: # pragma no branch
self._severity = self._makeStringAttribute(attributes["severity"])
@@ -538,9 +497,9 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
if "summary" in attributes: # pragma no branch
self._summary = self._makeStringAttribute(attributes["summary"])
if "updated_at" in attributes: # pragma no branch
assert attributes["updated_at"] is None or isinstance(
attributes["updated_at"], str
), attributes["updated_at"]
assert attributes["updated_at"] is None or isinstance(attributes["updated_at"], str), attributes[
"updated_at"
]
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
@@ -550,7 +509,7 @@ class RepositoryAdvisory(github.GithubObject.NonCompletableGithubObject):
attributes["vulnerabilities"],
)
if "withdrawn_at" in attributes: # pragma no branch
assert attributes["withdrawn_at"] is None or isinstance(
attributes["withdrawn_at"], str
), attributes["withdrawn_at"]
assert attributes["withdrawn_at"] is None or isinstance(attributes["withdrawn_at"], str), attributes[
"withdrawn_at"
]
self._withdrawn_at = self._makeDatetimeAttribute(attributes["withdrawn_at"])
+2 -6
View File
@@ -78,9 +78,7 @@ class RepositoryAdvisoryCredit(github.GithubObject.NonCompletableGithubObject):
if isinstance(credit, dict):
assert "login" in credit, credit
assert "type" in credit, credit
assert isinstance(
credit["login"], (str, github.NamedUser.NamedUser)
), credit["login"]
assert isinstance(credit["login"], (str, github.NamedUser.NamedUser)), credit["login"]
assert isinstance(credit["type"], str), credit["type"]
else:
assert isinstance(credit.login, str), credit.login
@@ -92,9 +90,7 @@ class RepositoryAdvisoryCredit(github.GithubObject.NonCompletableGithubObject):
if isinstance(credit, dict):
assert "login" in credit, credit
assert "type" in credit, credit
assert isinstance(
credit["login"], (str, github.NamedUser.NamedUser)
), credit["login"]
assert isinstance(credit["login"], (str, github.NamedUser.NamedUser)), credit["login"]
login = credit["login"]
if isinstance(login, github.NamedUser.NamedUser):
login = login.login
+1 -3
View File
@@ -65,6 +65,4 @@ class RepositoryAdvisoryCreditDetailed(github.GithubObject.NonCompletableGithubO
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+8 -24
View File
@@ -48,9 +48,7 @@ class SimpleAdvisoryVulnerability(TypedDict):
vulnerable_version_range: NotRequired[Optional[str]]
AdvisoryVulnerability = Union[
SimpleAdvisoryVulnerability, "RepositoryAdvisoryVulnerability"
]
AdvisoryVulnerability = Union[SimpleAdvisoryVulnerability, "RepositoryAdvisoryVulnerability"]
class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubObject):
@@ -104,17 +102,11 @@ class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubOb
attributes["package"],
)
if "patched_versions" in attributes: # pragma no branch
self._patched_versions = self._makeStringAttribute(
attributes["patched_versions"]
)
self._patched_versions = self._makeStringAttribute(attributes["patched_versions"])
if "vulnerable_functions" in attributes: # pragma no branch
self._vulnerable_functions = self._makeListOfStringsAttribute(
attributes["vulnerable_functions"]
)
self._vulnerable_functions = self._makeListOfStringsAttribute(attributes["vulnerable_functions"])
if "vulnerable_version_range" in attributes: # pragma no branch
self._vulnerable_version_range = self._makeStringAttribute(
attributes["vulnerable_version_range"]
)
self._vulnerable_version_range = self._makeStringAttribute(attributes["vulnerable_version_range"])
@classmethod
def _validate_vulnerability(cls, vulnerability: AdvisoryVulnerability) -> None:
@@ -128,13 +120,9 @@ class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubOb
assert "name" in package, package
assert isinstance(package["name"], (str, type(None))), package
assert "patched_versions" in vulnerability, vulnerability
assert isinstance(
vulnerability["patched_versions"], (str, type(None))
), vulnerability
assert isinstance(vulnerability["patched_versions"], (str, type(None))), vulnerability
assert "vulnerable_functions" in vulnerability, vulnerability
assert isinstance(
vulnerability["vulnerable_functions"], (list, type(None))
), vulnerability
assert isinstance(vulnerability["vulnerable_functions"], (list, type(None))), vulnerability
assert "vulnerable_functions" in vulnerability, vulnerability
assert (
all(isinstance(vf, str) for vf in vulnerability["vulnerable_functions"])
@@ -142,9 +130,7 @@ class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubOb
else True
), vulnerability
assert "vulnerable_version_range" in vulnerability, vulnerability
assert isinstance(
vulnerability["vulnerable_version_range"], (str, type(None))
), vulnerability
assert isinstance(vulnerability["vulnerable_version_range"], (str, type(None))), vulnerability
else:
assert (
@@ -157,9 +143,7 @@ class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubOb
vulnerability: AdvisoryVulnerability,
) -> SimpleAdvisoryVulnerability:
if isinstance(vulnerability, dict):
vulnerability_package: SimpleAdvisoryVulnerabilityPackage = vulnerability[
"package"
]
vulnerability_package: SimpleAdvisoryVulnerabilityPackage = vulnerability["package"]
return {
"package": {
"ecosystem": vulnerability_package["ecosystem"],
@@ -25,9 +25,7 @@ from typing import Optional
import github.GithubObject
class RepositoryAdvisoryVulnerabilityPackage(
github.GithubObject.NonCompletableGithubObject
):
class RepositoryAdvisoryVulnerabilityPackage(github.GithubObject.NonCompletableGithubObject):
"""
This class represents an identifier for a package that is vulnerable to a parent SecurityAdvisory.
The reference can be found here https://docs.github.com/en/rest/security-advisories/repository-advisories
+1 -3
View File
@@ -53,6 +53,4 @@ class RepositoryPreferences(NonCompletableGithubObject):
if "preferences" in attributes: # pragma no branch
self._preferences = self._makeDictAttribute(attributes["preferences"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(
github.Repository.Repository, attributes["repository"]
)
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
+30 -119
View File
@@ -63,20 +63,7 @@ import urllib.parse
from collections import defaultdict
from datetime import datetime, timezone
from io import IOBase
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Generic,
ItemsView,
List,
Optional,
Tuple,
Type,
TypeVar,
Union,
)
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, ItemsView, List, Optional, Tuple, Type, TypeVar, Union
import requests
import requests.adapters
@@ -300,18 +287,14 @@ class Requester:
"""
if self.DEBUG_FLAG: # pragma no branch (Flag always set in tests)
new_frame = [requestHeader, None, None, None]
if (
self._frameCount < self.DEBUG_FRAME_BUFFER_SIZE - 1
): # pragma no branch (Should be covered)
if self._frameCount < self.DEBUG_FRAME_BUFFER_SIZE - 1: # pragma no branch (Should be covered)
self._frameBuffer.append(new_frame)
else:
self._frameBuffer[0] = new_frame # pragma no cover (Should be covered)
self._frameCount = len(self._frameBuffer) - 1
def DEBUG_ON_RESPONSE(
self, statusCode: int, responseHeader: Dict[str, Union[str, int]], data: str
):
def DEBUG_ON_RESPONSE(self, statusCode: int, responseHeader: Dict[str, Union[str, int]], data: str):
"""
Update current frame with response
Current frame index will be attached to responseHeader
@@ -325,9 +308,7 @@ class Requester:
responseHeader[self.DEBUG_HEADER_KEY] = self._frameCount
def check_me(self, obj: "GithubObject"):
if (
self.DEBUG_FLAG and self.ON_CHECK_ME is not None
): # pragma no branch (Flag always set in tests)
if self.DEBUG_FLAG and self.ON_CHECK_ME is not None: # pragma no branch (Flag always set in tests)
frame = None
if self.DEBUG_HEADER_KEY in obj._headers:
frame_index = obj._headers[self.DEBUG_HEADER_KEY]
@@ -341,9 +322,7 @@ class Requester:
#############################################################
_frameCount: int
__connectionClass: Union[
Type[HTTPRequestsConnectionClass], Type[HTTPSRequestsConnectionClass]
]
__connectionClass: Union[Type[HTTPRequestsConnectionClass], Type[HTTPSRequestsConnectionClass]]
__hostname: str
__authorizationHeader: Optional[str]
__last_requests: Dict[str, float]
@@ -452,11 +431,7 @@ class Requester:
headers: Optional[Dict[str, str]] = None,
input: Optional[Any] = None,
) -> Tuple[Dict[str, Any], Any]:
return self.__check(
*self.requestJson(
verb, url, parameters, headers, input, self.__customConnection(url)
)
)
return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
def requestMultipartAndCheck(
self,
@@ -466,11 +441,7 @@ class Requester:
headers: Optional[Dict[str, Any]] = None,
input: Optional[Dict[str, str]] = None,
) -> Tuple[Dict[str, Any], Optional[Dict[str, Any]]]:
return self.__check(
*self.requestMultipart(
verb, url, parameters, headers, input, self.__customConnection(url)
)
)
return self.__check(*self.requestMultipart(verb, url, parameters, headers, input, self.__customConnection(url)))
def requestBlobAndCheck(
self,
@@ -479,15 +450,9 @@ class Requester:
parameters: Optional[Dict[str, str]] = None,
headers: Optional[Dict[str, str]] = None,
input: Optional[str] = None,
cnx: Optional[
Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]
] = None,
cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None,
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
return self.__check(
*self.requestBlob(
verb, url, parameters, headers, input, self.__customConnection(url)
)
)
return self.__check(*self.requestBlob(verb, url, parameters, headers, input, self.__customConnection(url)))
def __check(
self,
@@ -503,18 +468,13 @@ class Requester:
def __customConnection(
self, url: str
) -> Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]]:
cnx: Optional[
Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]
] = None
cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None
if not url.startswith("/"):
o = urllib.parse.urlparse(url)
if (
o.hostname != self.__hostname
or (o.port and o.port != self.__port)
or (
o.scheme != self.__scheme
and not (o.scheme == "https" and self.__scheme == "http")
)
or (o.scheme != self.__scheme and not (o.scheme == "https" and self.__scheme == "http"))
): # issue80
if o.scheme == "http":
cnx = self.__httpConnectionClass(
@@ -544,15 +504,9 @@ class Requester:
exc = GithubException.GithubException
if status == 401 and message == "bad credentials":
exc = GithubException.BadCredentialsException
elif (
status == 401
and Consts.headerOTP in headers
and re.match(r".*required.*", headers[Consts.headerOTP])
):
elif status == 401 and Consts.headerOTP in headers and re.match(r".*required.*", headers[Consts.headerOTP]):
exc = GithubException.TwoFactorException
elif status == 403 and message.startswith(
"missing or invalid user agent string"
):
elif status == 403 and message.startswith("missing or invalid user agent string"):
exc = GithubException.BadUserAgentException
elif status == 403 and cls.isRateLimitError(message):
exc = GithubException.RateLimitExceededException
@@ -563,9 +517,7 @@ class Requester:
@classmethod
def isRateLimitError(cls, message: str) -> bool:
return cls.isPrimaryRateLimitError(message) or cls.isSecondaryRateLimitError(
message
)
return cls.isPrimaryRateLimitError(message) or cls.isSecondaryRateLimitError(message)
@classmethod
def isPrimaryRateLimitError(cls, message: str) -> bool:
@@ -607,9 +559,7 @@ class Requester:
parameters: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, Any]] = None,
input: Optional[Any] = None,
cnx: Optional[
Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]
] = None,
cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None,
) -> Tuple[int, Dict[str, Any], str]:
def encode(input):
return "application/json", json.dumps(input)
@@ -623,9 +573,7 @@ class Requester:
parameters: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, Any]] = None,
input: Optional[Dict[str, str]] = None,
cnx: Optional[
Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]
] = None,
cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None,
) -> Tuple[int, Dict[str, Any], str]:
def encode(input):
boundary = "----------------------------3c3ba8b523b2"
@@ -649,9 +597,7 @@ class Requester:
parameters: Optional[Dict[str, str]] = None,
headers: Optional[Dict[str, str]] = None,
input: Optional[str] = None,
cnx: Optional[
Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]
] = None,
cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None,
) -> Tuple[int, Dict[str, Any], str]:
if headers is None:
headers = {}
@@ -661,11 +607,7 @@ class Requester:
mime_type = headers["Content-Type"] # type: ignore
else:
guessed_type = mimetypes.guess_type(local_path)
mime_type = (
guessed_type[0]
if guessed_type[0] is not None
else Consts.defaultMediaType
)
mime_type = guessed_type[0] if guessed_type[0] is not None else Consts.defaultMediaType
f = open(local_path, "rb")
return mime_type, f
@@ -673,20 +615,14 @@ class Requester:
headers["Content-Length"] = str(os.path.getsize(input))
return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
def requestMemoryBlobAndCheck(
self, verb, url, parameters, headers, file_like, cnx=None
):
def requestMemoryBlobAndCheck(self, verb, url, parameters, headers, file_like, cnx=None):
# The expected signature of encode means that the argument is ignored.
def encode(_):
return headers["Content-Type"], file_like
if not cnx:
cnx = self.__customConnection(url)
return self.__check(
*self.__requestEncode(
cnx, verb, url, parameters, headers, file_like, encode
)
)
return self.__check(*self.__requestEncode(cnx, verb, url, parameters, headers, file_like, encode))
def __requestEncode(
self,
@@ -705,9 +641,7 @@ class Requester:
requestHeaders = {}
if self.__auth is not None:
requestHeaders[
"Authorization"
] = f"{self.__auth.token_type} {self.__auth.token}"
requestHeaders["Authorization"] = f"{self.__auth.token_type} {self.__auth.token}"
requestHeaders["User-Agent"] = self.__userAgent
url = self.__makeAbsoluteUrl(url)
@@ -719,14 +653,9 @@ class Requester:
self.NEW_DEBUG_FRAME(requestHeaders)
status, responseHeaders, output = self.__requestRaw(
cnx, verb, url, requestHeaders, encoded_input
)
status, responseHeaders, output = self.__requestRaw(cnx, verb, url, requestHeaders, encoded_input)
if (
Consts.headerRateRemaining in responseHeaders
and Consts.headerRateLimit in responseHeaders
):
if Consts.headerRateRemaining in responseHeaders and Consts.headerRateLimit in responseHeaders:
self.rate_limiting = (
int(responseHeaders[Consts.headerRateRemaining]),
int(responseHeaders[Consts.headerRateLimit]),
@@ -767,9 +696,7 @@ class Requester:
if isinstance(input, IOBase):
input.close()
self.__log(
verb, url, requestHeaders, input, status, responseHeaders, output
)
self.__log(verb, url, requestHeaders, input, status, responseHeaders, output)
if status == 202 and (
verb == "GET" or verb == "HEAD"
@@ -792,21 +719,15 @@ class Requester:
)
if o.path == url:
port = ":" + str(self.__port) if self.__port is not None else ""
requested_location = (
f"{self.__scheme}://{self.__hostname}{port}{url}"
)
requested_location = f"{self.__scheme}://{self.__hostname}{port}{url}"
raise RuntimeError(
f"Requested {requested_location} but server redirected to {location}, "
f"you may need to correct your Github server URL "
f"via base_url: Github(base_url=...)"
)
if self._logger.isEnabledFor(logging.INFO):
self._logger.info(
f"Following Github server redirection from {url} to {o.path}"
)
return self.__requestRaw(
original_cnx, verb, o.path, requestHeaders, input
)
self._logger.info(f"Following Github server redirection from {url} to {o.path}")
return self.__requestRaw(original_cnx, verb, o.path, requestHeaders, input)
return status, responseHeaders, output
finally:
@@ -824,16 +745,8 @@ class Requester:
last_request = max(requests) if requests else 0
last_write = max(writes) if writes else 0
next_request = (
(last_request + self.__seconds_between_requests)
if self.__seconds_between_requests
else 0
)
next_write = (
(last_write + self.__seconds_between_writes)
if self.__seconds_between_writes
else 0
)
next_request = (last_request + self.__seconds_between_requests) if self.__seconds_between_requests else 0
next_write = (last_write + self.__seconds_between_writes) if self.__seconds_between_writes else 0
next = next_request if verb == "GET" else max(next_request, next_write)
defer = max(next - datetime.now(timezone.utc).timestamp(), 0)
@@ -914,9 +827,7 @@ class Requester:
headersForRequest = requestHeaders.copy()
if "Authorization" in requestHeaders:
if requestHeaders["Authorization"].startswith("Basic"):
headersForRequest[
"Authorization"
] = "Basic (login and password removed)"
headersForRequest["Authorization"] = "Basic (login and password removed)"
elif requestHeaders["Authorization"].startswith("token"):
headersForRequest["Authorization"] = "token (oauth token removed)"
elif requestHeaders["Authorization"].startswith("Bearer"):
+2 -6
View File
@@ -97,13 +97,9 @@ class RequiredPullRequestReviews(github.GithubObject.CompletableGithubObject):
github.Team.Team, attributes["dismissal_restrictions"]["teams"]
)
if "dismiss_stale_reviews" in attributes: # pragma no branch
self._dismiss_stale_reviews = self._makeBoolAttribute(
attributes["dismiss_stale_reviews"]
)
self._dismiss_stale_reviews = self._makeBoolAttribute(attributes["dismiss_stale_reviews"])
if "require_code_owner_reviews" in attributes: # pragma no branch
self._require_code_owner_reviews = self._makeBoolAttribute(
attributes["require_code_owner_reviews"]
)
self._require_code_owner_reviews = self._makeBoolAttribute(attributes["require_code_owner_reviews"])
if "required_approving_review_count" in attributes: # pragma no branch
self._required_approving_review_count = self._makeIntAttribute(
attributes["required_approving_review_count"]
+4 -12
View File
@@ -168,23 +168,15 @@ class SourceImport(github.GithubObject.CompletableGithubObject):
if "authors_url" in attributes: # pragma no branch
self._authors_url = self._makeStringAttribute(attributes["authors_url"])
if "has_large_files" in attributes: # pragma no branch
self._has_large_files = self._makeBoolAttribute(
attributes["has_large_files"]
)
self._has_large_files = self._makeBoolAttribute(attributes["has_large_files"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "large_files_count" in attributes: # pragma no branch
self._large_files_count = self._makeIntAttribute(
attributes["large_files_count"]
)
self._large_files_count = self._makeIntAttribute(attributes["large_files_count"])
if "large_files_size" in attributes: # pragma no branch
self._large_files_size = self._makeIntAttribute(
attributes["large_files_size"]
)
self._large_files_size = self._makeIntAttribute(attributes["large_files_size"])
if "repository_url" in attributes: # pragma no branch
self._repository_url = self._makeStringAttribute(
attributes["repository_url"]
)
self._repository_url = self._makeStringAttribute(attributes["repository_url"])
if "status" in attributes: # pragma no branch
self._status = self._makeStringAttribute(attributes["status"])
if "status_text" in attributes: # pragma no branch
+1 -3
View File
@@ -60,6 +60,4 @@ class Stargazer(NonCompletableGithubObject):
if "starred_at" in attributes:
self._starred_at = self._makeDatetimeAttribute(attributes["starred_at"])
if "user" in attributes:
self._user = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["user"]
)
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
+2 -6
View File
@@ -110,12 +110,8 @@ class StatsContributor(github.GithubObject.NonCompletableGithubObject):
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
self._author = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["author"]
)
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "total" in attributes: # pragma no branch
self._total = self._makeIntAttribute(attributes["total"])
if "weeks" in attributes: # pragma no branch
self._weeks = self._makeListOfClassesAttribute(
self.Week, attributes["weeks"]
)
self._weeks = self._makeListOfClassesAttribute(self.Week, attributes["weeks"])
+2 -6
View File
@@ -45,9 +45,7 @@ class Tag(NonCompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"name": self._name.value, "commit": self._commit.value}
)
return self.get__repr__({"name": self._name.value, "commit": self._commit.value})
def _initAttributes(self) -> None:
self._commit: Attribute[Commit] = NotSet
@@ -73,9 +71,7 @@ class Tag(NonCompletableGithubObject):
def _useAttributes(self, attributes) -> None:
if "commit" in attributes: # pragma no branch
self._commit = self._makeClassAttribute(
github.Commit.Commit, attributes["commit"]
)
self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"])
if "name" in attributes: # pragma no branch
self._name = self._makeStringAttribute(attributes["name"])
if "tarball_url" in attributes: # pragma no branch
+20 -60
View File
@@ -182,9 +182,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/members/{member._identity}"
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/members/{member._identity}")
def add_membership(self, member, role=github.GithubObject.NotSet):
"""
@@ -214,17 +212,11 @@ class Team(github.GithubObject.CompletableGithubObject):
:param member: string or :class:`github.NamedUser.NamedUser`
:rtype: :class:`github.Membership.Membership`
"""
assert isinstance(member, str) or isinstance(
member, github.NamedUser.NamedUser
), member
assert isinstance(member, str) or isinstance(member, github.NamedUser.NamedUser), member
if isinstance(member, github.NamedUser.NamedUser):
member = member._identity
headers, data = self._requester.requestJsonAndCheck(
"GET", f"{self.url}/memberships/{member}"
)
return github.Membership.Membership(
self._requester, headers, data, completed=True
)
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/memberships/{member}")
return github.Membership.Membership(self._requester, headers, data, completed=True)
def add_to_repos(self, repo):
"""
@@ -233,9 +225,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(repo, github.Repository.Repository), repo
headers, data = self._requester.requestJsonAndCheck(
"PUT", f"{self.url}/repos/{repo._identity}"
)
headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/repos/{repo._identity}")
def get_repo_permission(self, repo):
"""
@@ -243,9 +233,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:param repo: string or :class:`github.Repository.Repository`
:rtype: None or :class:`github.Permissions.Permissions`
"""
assert isinstance(repo, github.Repository.Repository) or isinstance(
repo, str
), repo
assert isinstance(repo, github.Repository.Repository) or isinstance(repo, str), repo
if isinstance(repo, github.Repository.Repository):
repo = repo._identity
try:
@@ -254,9 +242,7 @@ class Team(github.GithubObject.CompletableGithubObject):
f"{self.url}/repos/{repo}",
headers={"Accept": Consts.teamRepositoryPermissions},
)
return github.Permissions.Permissions(
self._requester, headers, data["permissions"], completed=True
)
return github.Permissions.Permissions(self._requester, headers, data["permissions"], completed=True)
except UnknownObjectException:
return None
@@ -288,9 +274,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:param permission: string
:rtype: bool
"""
assert isinstance(repo, github.Repository.Repository) or isinstance(
repo, str
), repo
assert isinstance(repo, github.Repository.Repository) or isinstance(repo, str), repo
assert isinstance(permission, str), permission
repo_url_param = repo
if isinstance(repo, github.Repository.Repository):
@@ -328,15 +312,9 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(name, str), name
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
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
assert permission is github.GithubObject.NotSet or isinstance(permission, str), permission
assert privacy is github.GithubObject.NotSet or isinstance(privacy, str), privacy
post_parameters = {
"name": name,
}
@@ -346,9 +324,7 @@ class Team(github.GithubObject.CompletableGithubObject):
post_parameters["permission"] = permission
if privacy is not github.GithubObject.NotSet:
post_parameters["privacy"] = privacy
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_teams(self):
@@ -423,9 +399,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(member, github.NamedUser.NamedUser), member
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/members/{member._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"{self.url}/members/{member._identity}")
return status == 204
def has_in_repos(self, repo):
@@ -435,9 +409,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: bool
"""
assert isinstance(repo, github.Repository.Repository), repo
status, headers, data = self._requester.requestJson(
"GET", f"{self.url}/repos/{repo._identity}"
)
status, headers, data = self._requester.requestJson("GET", f"{self.url}/repos/{repo._identity}")
return status == 204
def remove_membership(self, member):
@@ -447,9 +419,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:return:
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/memberships/{member._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/memberships/{member._identity}")
def remove_from_members(self, member):
"""
@@ -461,9 +431,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(member, github.NamedUser.NamedUser), member
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/members/{member._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/members/{member._identity}")
def remove_from_repos(self, repo):
"""
@@ -472,9 +440,7 @@ class Team(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert isinstance(repo, github.Repository.Repository), repo
headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/repos/{repo._identity}"
)
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/repos/{repo._identity}")
@property
def _identity(self):
@@ -512,22 +478,16 @@ class Team(github.GithubObject.CompletableGithubObject):
if "repos_count" in attributes: # pragma no branch
self._repos_count = self._makeIntAttribute(attributes["repos_count"])
if "repositories_url" in attributes: # pragma no branch
self._repositories_url = self._makeStringAttribute(
attributes["repositories_url"]
)
self._repositories_url = self._makeStringAttribute(attributes["repositories_url"])
if "slug" in attributes: # pragma no branch
self._slug = self._makeStringAttribute(attributes["slug"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "organization" in attributes: # pragma no branch
self._organization = self._makeClassAttribute(
github.Organization.Organization, attributes["organization"]
)
self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"])
if "privacy" in attributes: # pragma no branch
self._privacy = self._makeStringAttribute(attributes["privacy"])
if "parent" in attributes: # pragma no branch
self._parent = self._makeClassAttribute(
github.Team.Team, attributes["parent"]
)
self._parent = self._makeClassAttribute(github.Team.Team, attributes["parent"])
if "html_url" in attributes:
self._html_url = self._makeStringAttribute(attributes["html_url"])
+3 -9
View File
@@ -15,15 +15,11 @@ class Team(CompletableGithubObject):
def _identity(self) -> int: ...
def _initAttributes(self) -> None: ...
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
def add_membership(
self, member: NamedUser, role: Union[str, _NotSetType] = ...
) -> None: ...
def add_membership(self, member: NamedUser, role: Union[str, _NotSetType] = ...) -> None: ...
def add_to_members(self, member: NamedUser) -> None: ...
def get_team_membership(self, member: Union[str, NamedUser]) -> Membership: ...
def add_to_repos(self, repo: Repository) -> None: ...
def get_repo_permission(
self, repo: Repository
) -> Union[Permissions, _NotSetType]: ...
def get_repo_permission(self, repo: Repository) -> Union[Permissions, _NotSetType]: ...
def update_team_repository(self, repo: Repository, permission: str) -> bool: ...
def delete(self) -> None: ...
@property
@@ -37,9 +33,7 @@ class Team(CompletableGithubObject):
) -> None: ...
def get_teams(self) -> PaginatedList[Team]: ...
def get_discussions(self) -> PaginatedList[TeamDiscussion]: ...
def get_members(
self, role: Union[str, _NotSetType] = ...
) -> PaginatedList[NamedUser]: ...
def get_members(self, role: Union[str, _NotSetType] = ...) -> PaginatedList[NamedUser]: ...
def get_repos(self) -> PaginatedList[Repository]: ...
def has_in_members(self, member: NamedUser) -> bool: ...
def has_in_repos(self, repo: Repository) -> bool: ...
+3 -9
View File
@@ -31,9 +31,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject):
"""
def __repr__(self):
return self.get__repr__(
{"number": self._number.value, "title": self._title.value}
)
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@property
def author(self):
@@ -192,9 +190,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
self._author = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["author"]
)
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "body_html" in attributes: # pragma no branch
@@ -210,9 +206,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject):
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "last_edited_at" in attributes: # pragma no branch
self._last_edited_at = self._makeDatetimeAttribute(
attributes["last_edited_at"]
)
self._last_edited_at = self._makeDatetimeAttribute(attributes["last_edited_at"])
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "number" in attributes: # pragma no branch
+4 -14
View File
@@ -88,10 +88,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject):
:type: :class:`github.TimelineEventSource.TimelineEventSource`
"""
# only available on `cross-referenced` events.
if (
self.event == "cross-referenced"
and self._source is not github.GithubObject.NotSet
):
if self.event == "cross-referenced" and self._source is not github.GithubObject.NotSet:
return self._source.value
return None
@@ -109,10 +106,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject):
"""
:type string
"""
if (
self.event == "commented"
and self._author_association is not github.GithubObject.NotSet
):
if self.event == "commented" and self._author_association is not github.GithubObject.NotSet:
return self._author_association.value
return None
@@ -138,9 +132,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject):
def _useAttributes(self, attributes):
if "actor" in attributes: # pragma no branch
self._actor = self._makeClassAttribute(
github.NamedUser.NamedUser, attributes["actor"]
)
self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"])
if "commit_id" in attributes: # pragma no branch
self._commit_id = self._makeStringAttribute(attributes["commit_id"])
if "created_at" in attributes: # pragma no branch
@@ -160,8 +152,6 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject):
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "author_association" in attributes: # pragma no branch
self._author_association = self._makeStringAttribute(
attributes["author_association"]
)
self._author_association = self._makeStringAttribute(attributes["author_association"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
+1 -3
View File
@@ -55,6 +55,4 @@ class TimelineEventSource(NonCompletableGithubObject):
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
if "issue" in attributes: # pragma no branch
self._issue = self._makeClassAttribute(
github.Issue.Issue, attributes["issue"]
)
self._issue = self._makeClassAttribute(github.Issue.Issue, attributes["issue"])

Some files were not shown because too many files have changed in this diff Show More