Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ Change log
Stable versions
~~~~~~~~~~~~~~~

Version 2.7.0 (XXXXXXX)
-----------------------

Breaking Changes
^^^^^^^^^^^^^^^^

* Method ``Github.get_rate_limit()`` now returns ``RateLimitOverview`` rather than ``RateLimit``.

Code like

.. code-block:: python

gh.get_rate_limit().core.remaining

should be replaced with

.. code-block:: python

gh.get_rate_limit().resources.core.remaining

Version 2.6.0 (February 15, 2025)
---------------------------------

Expand All @@ -15,19 +35,39 @@ Breaking Changes
View and clones traffic information returned by ``Repository.get_views_traffic`` and ``Repository.get_clones_traffic``
now return proper PyGithub objects, instead of a ``dict``, with all information that used to be provided by the ``dict``:

Code like
Code like

.. code-block:: python
.. code-block:: python

repo.get_views_traffic().["views"].timestamp
repo.get_clones_traffic().["clones"].timestamp
repo.get_views_traffic().["views"].timestamp
repo.get_clones_traffic().["clones"].timestamp

should be replaced with
should be replaced with

.. code-block:: python
.. code-block:: python

repo.get_views_traffic().views.timestamp
repo.get_clones_traffic().clones.timestamp

* Add ``GitCommitVerification`` class (`#3028 <https://github.com/PyGithub/PyGithub/pull/3028>`_) (`822e6d71 <https://github.com/PyGithub/PyGithub/commit/822e6d71>`_):

Changes the return value of ``GitTag.verification`` and ``GitCommit.verification`` from ``dict`` to ``GitCommitVerification``.

Code like

.. code-block:: python

tag.verification["reason"]
commit.verification["reason"]

should be replaced with

.. code-block:: python

tag.verification.reason
commit.verification.reason

repo.get_views_traffic().views.timestamp
repo.get_clones_traffic().clones.timestamp
* Property ``AppAuth.private_key`` has been removed (`#3065 <https://github.com/PyGithub/PyGithub/pull/3065>`_) (`36697b22 <https://github.com/PyGithub/PyGithub/commit/36697b22>`_)

* Fix typos (`#3086 <https://github.com/PyGithub/PyGithub/pull/3086>`_) (`a50ae51b <https://github.com/PyGithub/PyGithub/commit/a50ae51b>`_):

Expand Down
22 changes: 14 additions & 8 deletions github/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ def token_type(self) -> str:
return "Bearer"


class JwtSigner:
def __init__(self, private_key_or_func: Union[str, PrivateKeyGenerator], jwt_algorithm: str):
self._private_key_or_func = private_key_or_func
self._jwt_algorithm = jwt_algorithm

def jwt_sign(self, payload: dict) -> Union[str, bytes]:
if callable(self._private_key_or_func):
private_key = self._private_key_or_func()
else:
private_key = self._private_key_or_func
return jwt.encode(payload, key=private_key, algorithm=self._jwt_algorithm)


class AppAuth(JWT):
"""
This class is used to authenticate as a GitHub App.
Expand All @@ -196,14 +209,7 @@ class AppAuth(JWT):

@staticmethod
def create_jwt_sign(private_key_or_func: Union[str, PrivateKeyGenerator], jwt_algorithm: str) -> DictSignFunction:
def jwt_sign(payload: dict) -> Union[str, bytes]:
if callable(private_key_or_func):
private_key = private_key_or_func()
else:
private_key = private_key_or_func
return jwt.encode(payload, key=private_key, algorithm=jwt_algorithm)

return jwt_sign
return JwtSigner(private_key_or_func, jwt_algorithm).jwt_sign

# v3: move * above private_key
def __init__(
Expand Down
11 changes: 11 additions & 0 deletions github/AuthenticatedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@


class EmailData(NamedTuple):
"""
This class represents EmailData.

The reference can be found here
http://docs.github.com/en/rest/reference/users#emails

The OpenAPI schema can be found at
- /components/schemas/email

"""

email: str
primary: bool
verified: bool
Expand Down
4 changes: 2 additions & 2 deletions github/CheckRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from datetime import datetime
from typing import TYPE_CHECKING, Any

from typing_extensions import deprecated
import deprecated

import github.CheckRunAnnotation
import github.CheckRunOutput
Expand Down Expand Up @@ -109,7 +109,7 @@ def check_suite(self) -> CheckSuite:
return self._check_suite.value

@property
@deprecated("Use property check_suite.id instead")
@deprecated.deprecated("Use property check_suite.id instead")
def check_suite_id(self) -> int:
self._completeIfNotSet(self._check_suite_id)
return self._check_suite_id.value
Expand Down
27 changes: 24 additions & 3 deletions github/CodeSecurityConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,35 @@ class CodeSecurityConfig(NonCompletableGithubObject):
The reference can be found here
https://docs.github.com/en/rest/code-security/configurations.

The OpenAPI schema can be found at
- /components/schemas/code-security-configuration

"""

def _initAttributes(self) -> None:
self._id: Attribute[int] = NotSet
self._name: Attribute[str] = NotSet
self._advanced_security: Attribute[str] = NotSet
self._code_scanning_default_setup: Attribute[str] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._dependabot_alerts: Attribute[str] = NotSet
self._dependabot_security_updates: Attribute[str] = NotSet
self._dependency_graph: Attribute[str] = NotSet
self._dependency_graph_autosubmit_action: Attribute[str] = NotSet
self._dependency_graph_autosubmit_action_options: Attribute[dict[str, Any]] = NotSet
self._description: Attribute[str] = NotSet
self._enforcement: Attribute[str] = NotSet
self._html_url: Attribute[str] = NotSet
self._id: Attribute[int] = NotSet
self._name: Attribute[str] = NotSet
self._private_vulnerability_reporting: Attribute[str] = NotSet
self._secret_scanning: Attribute[str] = NotSet
self._secret_scanning_delegated_bypass: Attribute[str] = NotSet
self._secret_scanning_delegated_bypass_options: Attribute[dict[str, Any]] = NotSet
self._secret_scanning_non_provider_patterns: Attribute[str] = NotSet
self._secret_scanning_push_protection: Attribute[str] = NotSet
self._secret_scanning_validity_checks: Attribute[str] = NotSet
self._target_type: Attribute[str] = NotSet
self._url: Attribute[str] = NotSet
self._updated_at: Attribute[datetime] = NotSet
self._url: Attribute[str] = NotSet

def __repr__(self) -> str:
return self.get__repr__(
Expand Down Expand Up @@ -98,6 +103,10 @@ def dependency_graph(self) -> str:
def dependency_graph_autosubmit_action(self) -> str:
return self._dependency_graph_autosubmit_action.value

@property
def dependency_graph_autosubmit_action_options(self) -> dict[str, Any]:
return self._dependency_graph_autosubmit_action_options.value

@property
def description(self) -> str:
return self._description.value
Expand Down Expand Up @@ -130,6 +139,10 @@ def secret_scanning(self) -> str:
def secret_scanning_delegated_bypass(self) -> str:
return self._secret_scanning_delegated_bypass.value

@property
def secret_scanning_delegated_bypass_options(self) -> dict[str, Any]:
return self._secret_scanning_delegated_bypass_options.value

@property
def secret_scanning_non_provider_patterns(self) -> str:
return self._secret_scanning_non_provider_patterns.value
Expand Down Expand Up @@ -174,6 +187,10 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._dependency_graph_autosubmit_action = self._makeStringAttribute(
attributes["dependency_graph_autosubmit_action"]
)
if "dependency_graph_autosubmit_action_options" in attributes: # pragma no branch
self._dependency_graph_autosubmit_action_options = self._makeDictAttribute(
attributes["dependency_graph_autosubmit_action_options"]
)
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "enforcement" in attributes: # pragma no branch
Expand All @@ -194,6 +211,10 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._secret_scanning_delegated_bypass = self._makeStringAttribute(
attributes["secret_scanning_delegated_bypass"]
)
if "secret_scanning_delegated_bypass_options" in attributes: # pragma no branch
self._secret_scanning_delegated_bypass_options = self._makeDictAttribute(
attributes["secret_scanning_delegated_bypass_options"]
)
if "secret_scanning_non_provider_patterns" in attributes: # pragma no branch
self._secret_scanning_non_provider_patterns = self._makeStringAttribute(
attributes["secret_scanning_non_provider_patterns"]
Expand Down
39 changes: 30 additions & 9 deletions github/Commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Commit(CompletableGithubObject):
The OpenAPI schema can be found at
- /components/schemas/branch-short/properties/commit
- /components/schemas/commit
- /components/schemas/commit-search-result-item
- /components/schemas/commit-search-result-item/properties/parents/items
- /components/schemas/commit/properties/parents/items
- /components/schemas/short-branch/properties/commit
Expand All @@ -107,7 +106,6 @@ def _initAttributes(self) -> None:
self._node_id: Attribute[str] = NotSet
self._parents: Attribute[list[Commit]] = NotSet
self._repository: Attribute[Repository] = NotSet
self._score: Attribute[float] = NotSet
self._sha: Attribute[str] = NotSet
self._stats: Attribute[CommitStats] = NotSet
self._text_matches: Attribute[dict[str, Any]] = NotSet
Expand Down Expand Up @@ -176,11 +174,6 @@ def repository(self) -> Repository:
self._completeIfNotSet(self._repository)
return self._repository.value

@property
def score(self) -> float:
self._completeIfNotSet(self._score)
return self._score.value

@property
def sha(self) -> str:
self._completeIfNotSet(self._sha)
Expand Down Expand Up @@ -358,8 +351,6 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._parents = self._makeListOfClassesAttribute(Commit, attributes["parents"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "score" in attributes: # pragma no branch
self._score = self._makeFloatAttribute(attributes["score"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "stats" in attributes: # pragma no branch
Expand All @@ -368,3 +359,33 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._text_matches = self._makeDictAttribute(attributes["text_matches"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])


class CommitSearchResult(Commit):
"""
This class represents CommitSearchResult.

The reference can be found here
https://docs.github.com/en/rest/reference/search#search-commits

The OpenAPI schema can be found at
- /components/schemas/commit-search-result-item

"""

def _initAttributes(self) -> None:
super()._initAttributes()
self._score: Attribute[float] = NotSet

def __repr__(self) -> str:
return self.get__repr__({"sha": self._sha.value, "score": self._score.value})

@property
def score(self) -> float:
self._completeIfNotSet(self._score)
return self._score.value

def _useAttributes(self, attributes: dict[str, Any]) -> None:
super()._useAttributes(attributes)
if "score" in attributes: # pragma no branch
self._score = self._makeFloatAttribute(attributes["score"])
39 changes: 30 additions & 9 deletions github/ContentFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class ContentFile(CompletableGithubObject):
https://docs.github.com/en/rest/reference/repos#contents

The OpenAPI schema can be found at
- /components/schemas/code-search-result-item
- /components/schemas/content-directory
- /components/schemas/content-file
- /components/schemas/content-submodule
Expand All @@ -94,7 +93,6 @@ def _initAttributes(self) -> None:
self._name: Attribute[str] = NotSet
self._path: Attribute[str] = NotSet
self._repository: Attribute[Repository] = NotSet
self._score: Attribute[float] = NotSet
self._sha: Attribute[str] = NotSet
self._size: Attribute[int] = NotSet
self._submodule_git_url: Attribute[str] = NotSet
Expand Down Expand Up @@ -191,11 +189,6 @@ def repository(self) -> Repository:
) # pragma no cover (Should be covered)
return self._repository.value

@property
def score(self) -> float:
self._completeIfNotSet(self._score)
return self._score.value

@property
def sha(self) -> str:
self._completeIfNotSet(self._sha)
Expand Down Expand Up @@ -262,8 +255,6 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._path = self._makeStringAttribute(attributes["path"])
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "score" in attributes: # pragma no branch
self._score = self._makeFloatAttribute(attributes["score"])
if "sha" in attributes: # pragma no branch
self._sha = self._makeStringAttribute(attributes["sha"])
if "size" in attributes: # pragma no branch
Expand All @@ -278,3 +269,33 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._type = self._makeStringAttribute(attributes["type"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])


class ContentFileSearchResult(ContentFile):
"""
This class represents ContentFileSearchResult.

The reference can be found here
https://docs.github.com/en/rest/reference/search#search-code

The OpenAPI schema can be found at
- /components/schemas/code-search-result-item

"""

def _initAttributes(self) -> None:
super()._initAttributes()
self._score: Attribute[float] = NotSet

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

@property
def score(self) -> float:
self._completeIfNotSet(self._score)
return self._score.value

def _useAttributes(self, attributes: dict[str, Any]) -> None:
super()._useAttributes(attributes)
if "score" in attributes: # pragma no branch
self._score = self._makeFloatAttribute(attributes["score"])
Loading