Skip to content

Commit

Permalink
merge GithubObject.pyi/Requester.pyi stubs back to source (#2463)
Browse files Browse the repository at this point in the history
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
Co-authored-by: Jonathan Leitschuh <jonathan.leitschuh@gmail.com>
  • Loading branch information
3 people committed Jun 16, 2023
1 parent 6d4b6d1 commit b6258f4
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 680 deletions.
43 changes: 24 additions & 19 deletions github/AccessToken.py
Expand Up @@ -21,16 +21,27 @@
################################################################################

from datetime import datetime, timedelta, timezone
from typing import Optional

import github.GithubObject

from .GithubObject import Attribute


class AccessToken(github.GithubObject.NonCompletableGithubObject):
"""
This class represents access tokens.
"""

def __repr__(self):
_created: datetime
_token: Attribute[str]
_type: Attribute[str]
_scope: Attribute[str]
_expires_in: Attribute[Optional[int]]
_refresh_token: Attribute[str]
_refresh_expires_in: Attribute[Optional[int]]

def __repr__(self) -> str:
return self.get__repr__(
{
"token": f"{self.token[:5]}...",
Expand All @@ -45,44 +56,42 @@ def __repr__(self):
)

@property
def token(self):
def token(self) -> str:
"""
:type: string
"""
return self._token.value

@property
def type(self):
def type(self) -> str:
"""
:type: string
"""
return self._type.value

@property
def scope(self):
def scope(self) -> str:
"""
:type: string
"""
return self._scope.value

@property
def created(self):
def created(self) -> datetime:
"""
:type: datetime
"""
return self._created

@property
def expires_in(self):
def expires_in(self) -> Optional[int]:
"""
:type: Optional[int]
"""
if self._expires_in is not github.GithubObject.NotSet:
return self._expires_in.value
return None
return self._expires_in.value

@property
def expires_at(self):
def expires_at(self) -> Optional[datetime]:
"""
:type: Optional[datetime]
"""
Expand All @@ -92,25 +101,21 @@ def expires_at(self):
return None

@property
def refresh_token(self):
def refresh_token(self) -> Optional[str]:
"""
:type: Optional[string]
"""
if self._refresh_token is not github.GithubObject.NotSet:
return self._refresh_token.value
return None
return self._refresh_token.value

@property
def refresh_expires_in(self):
def refresh_expires_in(self) -> Optional[int]:
"""
:type: Optional[int]
"""
if self._refresh_expires_in is not github.GithubObject.NotSet:
return self._refresh_expires_in.value
return None
return self._refresh_expires_in.value

@property
def refresh_expires_at(self):
def refresh_expires_at(self) -> Optional[datetime]:
"""
:type: Optional[datetime]
"""
Expand Down
29 changes: 0 additions & 29 deletions github/AccessToken.pyi

This file was deleted.

127 changes: 58 additions & 69 deletions github/Authorization.py
Expand Up @@ -27,106 +27,97 @@
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from datetime import datetime
from typing import TYPE_CHECKING, List, Optional

import github.AuthorizationApplication
import github.GithubObject
from github.GithubObject import Attribute, NotSet, Opt, _NotSetType

if TYPE_CHECKING:
from github.AuthorizationApplication import AuthorizationApplication


class Authorization(github.GithubObject.CompletableGithubObject):
"""
This class represents Authorizations. The reference can be found here https://docs.github.com/en/enterprise-server@3.0/rest/reference/oauth-authorizations
"""

def __repr__(self):
_app: Attribute["AuthorizationApplication"]
_created_at: Attribute[datetime]
_id: Attribute[int]
_note: Attribute[Optional[str]]
_note_url: Attribute[Optional[str]]
_scopes: Attribute[str]
_token: Attribute[str]
_updated_at: Attribute[datetime]
_url: Attribute[str]

def __repr__(self) -> str:
return self.get__repr__({"scopes": self._scopes.value})

@property
def app(self):
"""
:type: :class:`github.AuthorizationApplication.AuthorizationApplication`
"""
def app(self) -> "AuthorizationApplication":
self._completeIfNotSet(self._app)
return self._app.value

@property
def created_at(self):
def created_at(self) -> datetime:
"""
:type: datetime.datetime
"""
self._completeIfNotSet(self._created_at)
return self._created_at.value

@property
def id(self):
"""
:type: integer
"""
def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value

@property
def note(self):
"""
:type: string
"""
def note(self) -> Optional[str]:
self._completeIfNotSet(self._note)
return self._note.value

@property
def note_url(self):
"""
:type: string
"""
def note_url(self) -> Optional[str]:
self._completeIfNotSet(self._note_url)
return self._note_url.value

@property
def scopes(self):
"""
:type: list of string
"""
def scopes(self) -> str:
self._completeIfNotSet(self._scopes)
return self._scopes.value

@property
def token(self):
"""
:type: string
"""
def token(self) -> str:
self._completeIfNotSet(self._token)
return self._token.value

@property
def updated_at(self):
"""
:type: datetime.datetime
"""
def updated_at(self) -> datetime:
self._completeIfNotSet(self._updated_at)
return self._updated_at.value

@property
def url(self):
"""
:type: string
"""
def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value

def delete(self):
def delete(self) -> None:
"""
:calls: `DELETE /authorizations/{id} <https://docs.github.com/en/developers/apps/authorizing-oauth-apps>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)

def edit(
self,
scopes=github.GithubObject.NotSet,
add_scopes=github.GithubObject.NotSet,
remove_scopes=github.GithubObject.NotSet,
note=github.GithubObject.NotSet,
note_url=github.GithubObject.NotSet,
):
scopes: Opt[List[str]] = NotSet,
add_scopes: Opt[List[str]] = NotSet,
remove_scopes: Opt[List[str]] = NotSet,
note: Opt[str] = NotSet,
note_url: Opt[str] = NotSet,
) -> None:
"""
:calls: `PATCH /authorizations/{id} <https://docs.github.com/en/developers/apps/authorizing-oauth-apps>`_
:param scopes: list of string
Expand All @@ -136,45 +127,43 @@ def edit(
:param note_url: string
:rtype: None
"""
assert scopes is github.GithubObject.NotSet or all(
assert isinstance(scopes, _NotSetType) or all(
isinstance(element, str) for element in scopes
), scopes
assert add_scopes is github.GithubObject.NotSet or all(
assert isinstance(add_scopes, _NotSetType) or all(
isinstance(element, str) for element in add_scopes
), add_scopes
assert remove_scopes is github.GithubObject.NotSet or all(
assert isinstance(remove_scopes, _NotSetType) or all(
isinstance(element, str) for element in remove_scopes
), remove_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
post_parameters = dict()
if scopes is not github.GithubObject.NotSet:
post_parameters["scopes"] = scopes
if add_scopes is not github.GithubObject.NotSet:
post_parameters["add_scopes"] = add_scopes
if remove_scopes is not github.GithubObject.NotSet:
post_parameters["remove_scopes"] = remove_scopes
if note is not github.GithubObject.NotSet:
post_parameters["note"] = note
if note_url is not github.GithubObject.NotSet:
post_parameters["note_url"] = note_url
assert isinstance(note, (_NotSetType, str)), note
assert isinstance(note_url, (_NotSetType, str)), note_url

post_parameters = NotSet.remove_unset_items(
{
"scopes": scopes,
"add_scopes": add_scopes,
"remove_scopes": remove_scopes,
"note": note,
"note_url": note_url,
}
)

headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
self._useAttributes(data)

def _initAttributes(self):
self._app = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._id = github.GithubObject.NotSet
self._note = github.GithubObject.NotSet
self._note_url = github.GithubObject.NotSet
self._scopes = github.GithubObject.NotSet
self._token = github.GithubObject.NotSet
self._updated_at = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
self._app = NotSet
self._created_at = NotSet
self._id = NotSet
self._note = NotSet
self._note_url = NotSet
self._scopes = NotSet
self._token = NotSet
self._updated_at = NotSet
self._url = NotSet

def _useAttributes(self, attributes):
if "app" in attributes: # pragma no branch
Expand Down
37 changes: 0 additions & 37 deletions github/Authorization.pyi

This file was deleted.

0 comments on commit b6258f4

Please sign in to comment.