Skip to content

Commit f997a2f

Browse files
committed
Add CodeSecurityConfigRepository returned by get_repos_for_code_security_config (#3219)
Follow-up on #3095.
1 parent 048a1a3 commit f997a2f

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
############################ Copyrights and license ############################
2+
# #
3+
# #
4+
# This file is part of PyGithub. #
5+
# http://pygithub.readthedocs.io/ #
6+
# #
7+
# PyGithub is free software: you can redistribute it and/or modify it under #
8+
# the terms of the GNU Lesser General Public License as published by the Free #
9+
# Software Foundation, either version 3 of the License, or (at your option) #
10+
# any later version. #
11+
# #
12+
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
13+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
14+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
15+
# details. #
16+
# #
17+
# You should have received a copy of the GNU Lesser General Public License #
18+
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
19+
# #
20+
################################################################################
21+
22+
from __future__ import annotations
23+
24+
from typing import TYPE_CHECKING, Any
25+
26+
import github.Repository
27+
from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
28+
29+
if TYPE_CHECKING:
30+
from github.Repository import Repository
31+
32+
33+
class CodeSecurityConfigRepository(NonCompletableGithubObject):
34+
"""
35+
This class represents CodeSecurityConfigRepository.
36+
37+
The reference can be found here
38+
https://docs.github.com/en/rest/code-security/configurations
39+
40+
The OpenAPI schema can be found at
41+
- /components/schemas/code-security-configuration-repositories
42+
43+
"""
44+
45+
def _initAttributes(self) -> None:
46+
self._repository: Attribute[Repository] = NotSet
47+
self._status: Attribute[str] = NotSet
48+
49+
def __repr__(self) -> str:
50+
return self.repository.__repr__()
51+
52+
@property
53+
def repository(self) -> Repository:
54+
return self._repository.value
55+
56+
@property
57+
def status(self) -> str:
58+
return self._status.value
59+
60+
def _useAttributes(self, attributes: dict[str, Any]) -> None:
61+
if "repository" in attributes: # pragma no branch
62+
self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
63+
if "status" in attributes: # pragma no branch
64+
self._status = self._makeStringAttribute(attributes["status"])

github/Organization.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from typing import TYPE_CHECKING, Any
9191

9292
import github.CodeSecurityConfig
93+
import github.CodeSecurityConfigRepository
9394
import github.Copilot
9495
import github.DefaultCodeSecurityConfig
9596
import github.Event
@@ -119,6 +120,7 @@
119120

120121
if TYPE_CHECKING:
121122
from github.CodeSecurityConfig import CodeSecurityConfig
123+
from github.CodeSecurityConfigRepository import CodeSecurityConfigRepository
122124
from github.Copilot import Copilot
123125
from github.DefaultCodeSecurityConfig import DefaultCodeSecurityConfig
124126
from github.Event import Event
@@ -1820,7 +1822,9 @@ def detach_security_config_from_repositories(self, selected_repository_ids: list
18201822
headers={"Accept": Consts.repoVisibilityPreview},
18211823
)
18221824

1823-
def get_repos_for_code_security_config(self, id: int, status: Opt[str] = NotSet) -> PaginatedList[Repository]:
1825+
def get_repos_for_code_security_config(
1826+
self, id: int, status: Opt[str] = NotSet
1827+
) -> PaginatedList[CodeSecurityConfigRepository]:
18241828
"""
18251829
:calls: `GET /orgs/{org}/code-security/configurations/{configuration_id}/repositories <https://docs.github.com/en/rest/code-security/configurations#get-repositories-associated-with-a-code-security-configuration>`_
18261830
"""
@@ -1830,7 +1834,7 @@ def get_repos_for_code_security_config(self, id: int, status: Opt[str] = NotSet)
18301834
url_parameters = NotSet.remove_unset_items({"status": status})
18311835

18321836
return PaginatedList(
1833-
github.Repository.Repository,
1837+
github.CodeSecurityConfigRepository.CodeSecurityConfigRepository,
18341838
self._requester,
18351839
f"{self.url}/code-security/configurations/{id}/repositories",
18361840
url_parameters,

0 commit comments

Comments
 (0)