Skip to content

Commit 679a2fc

Browse files
Update github_rest_api/github.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent ba5d1b6 commit 679a2fc

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

github_rest_api/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
"""GitHub REST APIs."""
22

3-
from .github import Organization, Repository, RepositoryType, User
3+
from .github import (
4+
Organization,
5+
Repository,
6+
RepositoryType,
7+
SecretVisibility,
8+
User,
9+
)
410

5-
__all__ = ["Organization", "Repository", "RepositoryType", "User"]
11+
__all__ = ["Organization", "Repository", "RepositoryType", "SecretVisibility", "User"]

github_rest_api/github.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def _delete(self, url, raise_for_status: bool = True) -> requests.Response:
8282
resp.raise_for_status()
8383
return resp
8484

85-
def _put(self, url: str, raise_for_status: bool = True, **kwargs) -> requests.Response:
85+
def _put(
86+
self, url: str, raise_for_status: bool = True, **kwargs
87+
) -> requests.Response:
8688
resp = requests.put(
8789
url=url,
8890
headers=self._headers,
@@ -394,6 +396,12 @@ class RepositoryType(StrEnum):
394396
PRIVATE = "private"
395397

396398

399+
class SecretVisibility(StrEnum):
400+
ALL = "all"
401+
PRIVATE = "private"
402+
SELECTED = "selected"
403+
404+
397405
class Owner(GitHub, metaclass=ABCMeta):
398406
"""An abstract owner class representing an organization or user."""
399407

@@ -491,7 +499,7 @@ def create_or_update_secret(
491499
self,
492500
name: str,
493501
value: str,
494-
visibility: str = "all",
502+
visibility: SecretVisibility = SecretVisibility.ALL,
495503
selected_repository_ids: Sequence[int] = (),
496504
) -> requests.Response:
497505
"""Create or update an organization secret.
@@ -506,6 +514,10 @@ def create_or_update_secret(
506514
raise ValueError("A string value is required for `name`.")
507515
if not isinstance(value, str):
508516
raise ValueError("A string value is required for `value`.")
517+
if selected_repository_ids and visibility != SecretVisibility.SELECTED:
518+
raise ValueError(
519+
"`selected_repository_ids` can only be provided when `visibility` is 'selected'."
520+
)
509521
key = self.get_secret_public_key()
510522
json: dict[str, Any] = {
511523
"encrypted_value": _encrypt_secret(key["key"], value),

0 commit comments

Comments
 (0)