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
20 changes: 20 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ Breaking Changes
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

* 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>`_):

Property ``OrganizationCustomProperty.respository_id`` renamed to ``OrganizationCustomProperty.repository_id``.
Expand Down
8 changes: 4 additions & 4 deletions github/ApplicationOAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class ApplicationOAuth(NonCompletableGithubObject):

"""

def _initAttributes(self) -> None:
self._client_id: Attribute[str] = NotSet
self._client_secret: Attribute[str] = NotSet

def __init__(
self,
requester: Requester,
Expand All @@ -68,6 +64,10 @@ def __init__(
requester = requester.withAuth(auth=None)
super().__init__(requester, headers, attributes)

def _initAttributes(self) -> None:
self._client_id: Attribute[str] = NotSet
self._client_secret: Attribute[str] = NotSet

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

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
6 changes: 4 additions & 2 deletions github/Branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def edit_required_pull_request_reviews(
require_code_owner_reviews: Opt[bool] = NotSet,
required_approving_review_count: Opt[int] = NotSet,
require_last_push_approval: Opt[bool] = NotSet,
) -> RequiredStatusChecks:
) -> RequiredPullRequestReviews:
"""
:calls: `PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews <https://docs.github.com/en/rest/reference/repos#branches>`_
"""
Expand Down Expand Up @@ -460,7 +460,9 @@ def edit_required_pull_request_reviews(
input=post_parameters,
)

return github.RequiredStatusChecks.RequiredStatusChecks(self._requester, headers, data, completed=True)
return github.RequiredPullRequestReviews.RequiredPullRequestReviews(
self._requester, headers, data, completed=True
)

def remove_required_pull_request_reviews(self) -> None:
"""
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
64 changes: 64 additions & 0 deletions github/CodeSecurityConfigRepository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
############################ Copyrights and license ############################
# #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################

from __future__ import annotations

from typing import TYPE_CHECKING, Any

import github.Repository
from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet

if TYPE_CHECKING:
from github.Repository import Repository


class CodeSecurityConfigRepository(NonCompletableGithubObject):
"""
This class represents CodeSecurityConfigRepository.

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-repositories

"""

def _initAttributes(self) -> None:
self._repository: Attribute[Repository] = NotSet
self._status: Attribute[str] = NotSet

def __repr__(self) -> str:
return self.repository.__repr__()

@property
def repository(self) -> Repository:
return self._repository.value

@property
def status(self) -> str:
return self._status.value

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "repository" in attributes: # pragma no branch
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "status" in attributes: # pragma no branch
self._status = self._makeStringAttribute(attributes["status"])
8 changes: 4 additions & 4 deletions github/Copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ def __init__(self, requester: Requester, org_name: str) -> None:
def _initAttributes(self) -> None:
self._org_name: Attribute[str] = NotSet

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "org_name" in attributes: # pragma no branch
self._org_name = self._makeStringAttribute(attributes["org_name"])

def __repr__(self) -> str:
return self.get__repr__({"org_name": self._org_name.value if self._org_name is not NotSet else NotSet})

Expand Down Expand Up @@ -94,3 +90,7 @@ def remove_seats(self, selected_usernames: list[str]) -> int:
input={"selected_usernames": selected_usernames},
)
return data["seats_cancelled"]

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "org_name" in attributes: # pragma no branch
self._org_name = self._makeStringAttribute(attributes["org_name"])
Loading