mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Add Secret and Variable classes (#2623)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
co-authored by
Enrico Minack
parent
7cfa476187
commit
bcca758d13
+87
-71
@@ -48,6 +48,8 @@ from typing import Any
|
||||
import github.Event
|
||||
import github.GithubObject
|
||||
import github.NamedUser
|
||||
import github.OrganizationSecret
|
||||
import github.OrganizationVariable
|
||||
import github.PaginatedList
|
||||
import github.Plan
|
||||
import github.Project
|
||||
@@ -618,12 +620,12 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
|
||||
):
|
||||
"""
|
||||
:calls: `PUT /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret>`_
|
||||
:calls: `PUT /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#create-or-update-an-organization-secret>`_
|
||||
:param secret_name: string
|
||||
:param unencrypted_value: string
|
||||
:param visibility: string
|
||||
:param selected_repositories: Optional list of :class:`github.Repository.Repository`
|
||||
:rtype: bool
|
||||
:rtype: github.OrganizationSecret.OrganizationSecret
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
assert isinstance(unencrypted_value, str), unencrypted_value
|
||||
@@ -645,10 +647,46 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
if selected_repositories is not github.GithubObject.NotSet:
|
||||
put_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
|
||||
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters
|
||||
self._requester.requestJsonAndCheck("PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters)
|
||||
|
||||
return github.OrganizationSecret.OrganizationSecret(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={
|
||||
"name": secret_name,
|
||||
"visibility": visibility,
|
||||
"selected_repositories_url": f"{self.url}/actions/secrets/{secret_name}/repositories",
|
||||
"url": f"{self.url}/actions/secrets/{secret_name}",
|
||||
},
|
||||
completed=False,
|
||||
)
|
||||
|
||||
def get_secrets(self):
|
||||
"""
|
||||
Gets all organization secrets
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.OrganizationSecret.OrganizationSecret`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.OrganizationSecret.OrganizationSecret,
|
||||
self._requester,
|
||||
f"{self.url}/actions/secrets",
|
||||
None,
|
||||
list_item="secrets",
|
||||
)
|
||||
|
||||
def get_secret(self, secret_name: str):
|
||||
"""
|
||||
:calls: 'GET /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-an-organization-secret>`_
|
||||
:param secret_name: string
|
||||
:rtype: github.OrganizationSecret.OrganizationSecret
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
return github.OrganizationSecret.OrganizationSecret(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={"url": f"{self.url}/actions/secrets/{secret_name}"},
|
||||
completed=False,
|
||||
)
|
||||
return status == 201
|
||||
|
||||
def create_team(
|
||||
self,
|
||||
@@ -694,14 +732,14 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
value: str,
|
||||
visibility: str = "all",
|
||||
selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
|
||||
) -> bool:
|
||||
) -> github.OrganizationVariable.OrganizationVariable:
|
||||
"""
|
||||
:calls: `PUT /orgs/{org}/actions/variables/ <https://docs.github.com/en/rest/reference/actions/variables#create-an-organization-variable>`_
|
||||
:calls: `POST /orgs/{org}/actions/variables/ <https://docs.github.com/en/rest/actions/variables#create-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:param visibility: string
|
||||
:param selected_repositories: list of :class:`github.Repository.Repository`
|
||||
:rtype: bool
|
||||
:rtype: github.OrganizationVariable.OrganizationVariable
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
assert isinstance(value, str), value
|
||||
@@ -720,10 +758,48 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
}
|
||||
if selected_repositories is not github.GithubObject.NotSet:
|
||||
post_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"POST", f"{self.url}/actions/variables", input=post_parameters
|
||||
|
||||
self._requester.requestJsonAndCheck("POST", f"{self.url}/actions/variables", input=post_parameters)
|
||||
|
||||
return github.OrganizationVariable.OrganizationVariable(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={
|
||||
"name": variable_name,
|
||||
"visibility": visibility,
|
||||
"value": value,
|
||||
"selected_repositories_url": f"{self.url}/actions/variables/{variable_name}/repositories",
|
||||
"url": self.url,
|
||||
},
|
||||
completed=False,
|
||||
)
|
||||
|
||||
def get_variables(self):
|
||||
"""
|
||||
Gets all organization variables
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.OrganizationVariable.OrganizationVariable`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.OrganizationVariable.OrganizationVariable,
|
||||
self._requester,
|
||||
f"{self.url}/actions/variables",
|
||||
None,
|
||||
list_item="variables",
|
||||
)
|
||||
|
||||
def get_variable(self, variable_name: str):
|
||||
"""
|
||||
:calls: 'GET /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#get-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:rtype: github.OrganizationVariable.OrganizationVariable
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
return github.OrganizationVariable.OrganizationVariable(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={"url": f"{self.url}/actions/variables/{variable_name}"},
|
||||
completed=False,
|
||||
)
|
||||
return status == 201
|
||||
|
||||
def delete_hook(self, id):
|
||||
"""
|
||||
@@ -734,26 +810,6 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
assert isinstance(id, int), id
|
||||
headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/hooks/{id}")
|
||||
|
||||
def delete_secret(self, secret_name):
|
||||
"""
|
||||
:calls: `DELETE /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret>`_
|
||||
:param secret_name: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/secrets/{secret_name}")
|
||||
return status == 204
|
||||
|
||||
def delete_variable(self, variable_name: str) -> bool:
|
||||
"""
|
||||
:calls: `DELETE /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#delete-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/variables/{variable_name}")
|
||||
return status == 204
|
||||
|
||||
def edit(
|
||||
self,
|
||||
billing_email=github.GithubObject.NotSet,
|
||||
@@ -833,46 +889,6 @@ class Organization(github.GithubObject.CompletableGithubObject):
|
||||
headers, data = self._requester.requestJsonAndCheck("PATCH", f"{self.url}/hooks/{id}", input=post_parameters)
|
||||
return github.Hook.Hook(self._requester, headers, data, completed=True)
|
||||
|
||||
def update_variable(
|
||||
self,
|
||||
variable_name: str,
|
||||
value: str,
|
||||
visibility: str = "all",
|
||||
selected_repositories: github.GithubObject.Opt[list[github.Repository.Repository]] = github.GithubObject.NotSet,
|
||||
) -> bool:
|
||||
"""
|
||||
:calls: `PATCH /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#update-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:param visibility: string
|
||||
:param selected_repositories: Optional list of :class:`github.Repository.Repository`
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
assert isinstance(value, str), value
|
||||
assert isinstance(visibility, str), visibility
|
||||
if visibility == "selected":
|
||||
assert isinstance(selected_repositories, list) and all(
|
||||
isinstance(element, github.Repository.Repository) for element in selected_repositories
|
||||
), selected_repositories
|
||||
else:
|
||||
assert selected_repositories is github.GithubObject.NotSet
|
||||
|
||||
patch_parameters = {
|
||||
"name": variable_name,
|
||||
"value": value,
|
||||
"visibility": visibility,
|
||||
}
|
||||
if selected_repositories is not github.GithubObject.NotSet:
|
||||
patch_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
|
||||
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"PATCH",
|
||||
f"{self.url}/actions/variables/{variable_name}",
|
||||
input=patch_parameters,
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def get_events(self):
|
||||
"""
|
||||
:calls: `GET /orgs/{org}/events <https://docs.github.com/en/rest/reference/activity#events>`_
|
||||
|
||||
+18
-11
@@ -9,6 +9,8 @@ from github.Issue import Issue
|
||||
from github.Label import Label
|
||||
from github.Migration import Migration
|
||||
from github.NamedUser import NamedUser
|
||||
from github.OrganizationSecret import OrganizationSecret
|
||||
from github.OrganizationVariable import OrganizationVariable
|
||||
from github.PaginatedList import PaginatedList
|
||||
from github.Plan import Plan
|
||||
from github.Project import Project
|
||||
@@ -70,13 +72,20 @@ class Organization(CompletableGithubObject):
|
||||
allow_merge_commit: Union[bool, _NotSetType] = ...,
|
||||
allow_rebase_merge: Union[bool, _NotSetType] = ...,
|
||||
) -> Repository: ...
|
||||
def get_secrets(
|
||||
self,
|
||||
) -> PaginatedList[OrganizationSecret]: ...
|
||||
def get_secret(
|
||||
self,
|
||||
secret_name: str,
|
||||
) -> OrganizationSecret: ...
|
||||
def create_secret(
|
||||
self,
|
||||
secret_name: str,
|
||||
unencrypted_value: str,
|
||||
visibility: str = ...,
|
||||
selected_repositories: Union[List[Repository], _NotSetType] = ...,
|
||||
) -> bool: ...
|
||||
) -> OrganizationSecret: ...
|
||||
def create_team(
|
||||
self,
|
||||
name: str,
|
||||
@@ -85,24 +94,29 @@ class Organization(CompletableGithubObject):
|
||||
privacy: Union[str, _NotSetType] = ...,
|
||||
description: Union[str, _NotSetType] = ...,
|
||||
) -> Team: ...
|
||||
def get_variables(
|
||||
self,
|
||||
) -> PaginatedList[OrganizationVariable]: ...
|
||||
def get_variable(
|
||||
self,
|
||||
variable_name: str,
|
||||
) -> OrganizationVariable: ...
|
||||
def create_variable(
|
||||
self,
|
||||
variable_name: str,
|
||||
value: str,
|
||||
visibility: str = ...,
|
||||
selected_repositories: Union[List[Repository], _NotSetType] = ...,
|
||||
) -> bool: ...
|
||||
) -> OrganizationVariable: ...
|
||||
@property
|
||||
def created_at(self) -> datetime: ...
|
||||
def delete_hook(self, id: int) -> None: ...
|
||||
@property
|
||||
def default_repository_permission(self) -> str: ...
|
||||
def delete_secret(self, secret_name: str) -> bool: ...
|
||||
@property
|
||||
def description(self) -> str: ...
|
||||
@property
|
||||
def disk_usage(self) -> int: ...
|
||||
def delete_variable(self, variable_name: str) -> bool: ...
|
||||
def edit(
|
||||
self,
|
||||
billing_email: Union[str, _NotSetType] = ...,
|
||||
@@ -121,13 +135,6 @@ class Organization(CompletableGithubObject):
|
||||
events: Union[_NotSetType, List[str]] = ...,
|
||||
active: Union[bool, _NotSetType] = ...,
|
||||
) -> Hook: ...
|
||||
def update_variable(
|
||||
self,
|
||||
variable_name: str,
|
||||
value: str,
|
||||
visibility: str = ...,
|
||||
selected_repositories: Union[List[Repository], _NotSetType] = ...,
|
||||
) -> bool: ...
|
||||
@property
|
||||
def email(self) -> Optional[str]: ...
|
||||
@property
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> #
|
||||
# #
|
||||
# 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 datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from github.GithubObject import Attribute, NotSet
|
||||
from github.PaginatedList import PaginatedList
|
||||
from github.Repository import Repository
|
||||
from github.Secret import Secret
|
||||
|
||||
|
||||
class OrganizationSecret(Secret):
|
||||
"""
|
||||
This class represents a org level GitHub secret. The reference can be found here https://docs.github.com/en/rest/actions/secrets
|
||||
"""
|
||||
|
||||
def _initAttributes(self) -> None:
|
||||
self._name: Attribute[str] = NotSet
|
||||
self._created_at: Attribute[datetime] = NotSet
|
||||
self._updated_at: Attribute[datetime] = NotSet
|
||||
self._visibility: Attribute[str] = NotSet
|
||||
self._selected_repositories: Attribute[PaginatedList[Repository]] = NotSet
|
||||
self._selected_repositories_url: Attribute[str] = NotSet
|
||||
self._url: Attribute[str] = NotSet
|
||||
|
||||
@property
|
||||
def visibility(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._visibility)
|
||||
return self._visibility.value
|
||||
|
||||
@property
|
||||
def selected_repositories(self) -> PaginatedList[Repository]:
|
||||
return PaginatedList(
|
||||
Repository,
|
||||
self._requester,
|
||||
self._selected_repositories_url.value,
|
||||
None,
|
||||
list_item="repositories",
|
||||
)
|
||||
|
||||
def edit(
|
||||
self,
|
||||
value: str,
|
||||
visibility: str = "all",
|
||||
) -> bool:
|
||||
"""
|
||||
:calls: `PATCH /orgs/{org}/actions/secrets/{variable_name} <https://docs.github.com/en/rest/reference/actions/secrets#update-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:param visibility: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(value, str), value
|
||||
assert isinstance(visibility, str), visibility
|
||||
|
||||
patch_parameters: Dict[str, Any] = {
|
||||
"name": self.name,
|
||||
"value": value,
|
||||
"visibility": visibility,
|
||||
}
|
||||
|
||||
status, _, _ = self._requester.requestJson(
|
||||
"PATCH",
|
||||
f"{self.url}/actions/secrets/{self.name}",
|
||||
input=patch_parameters,
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def add_repo(self, repo: Repository) -> bool:
|
||||
"""
|
||||
:calls: 'PUT {org_url}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#add-selected-repository-to-an-organization-secret>`_
|
||||
:param repo: github.Repository.Repository
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.visibility != "selected":
|
||||
return False
|
||||
self._requester.requestJsonAndCheck("PUT", f"{self._selected_repositories_url.value}/{repo.id}")
|
||||
return True
|
||||
|
||||
def remove_repo(self, repo: Repository) -> bool:
|
||||
"""
|
||||
:calls: 'DELETE {org_url}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#add-selected-repository-to-an-organization-secret>`_
|
||||
:param repo: github.Repository.Repository
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.visibility != "selected":
|
||||
return False
|
||||
self._requester.requestJsonAndCheck("DELETE", f"{self._selected_repositories_url.value}/{repo.id}")
|
||||
return True
|
||||
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
|
||||
if "name" in attributes:
|
||||
self._name = self._makeStringAttribute(attributes["name"])
|
||||
if "created_at" in attributes:
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "updated_at" in attributes:
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "visibility" in attributes:
|
||||
self._visibility = self._makeStringAttribute(attributes["visibility"])
|
||||
if "selected_repositories_url" in attributes:
|
||||
self._selected_repositories_url = self._makeStringAttribute(attributes["selected_repositories_url"])
|
||||
if "url" in attributes:
|
||||
self._url = self._makeStringAttribute(attributes["url"])
|
||||
@@ -0,0 +1,126 @@
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> #
|
||||
# #
|
||||
# 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 datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from github.GithubObject import Attribute, NotSet
|
||||
from github.PaginatedList import PaginatedList
|
||||
from github.Repository import Repository
|
||||
from github.Variable import Variable
|
||||
|
||||
|
||||
class OrganizationVariable(Variable):
|
||||
"""
|
||||
This class represents a org level GitHub variable. The reference can be found here https://docs.github.com/en/rest/actions/variables
|
||||
"""
|
||||
|
||||
def _initAttributes(self) -> None:
|
||||
self._name: Attribute[str] = NotSet
|
||||
self._created_at: Attribute[datetime] = NotSet
|
||||
self._updated_at: Attribute[datetime] = NotSet
|
||||
self._visibility: Attribute[str] = NotSet
|
||||
self._selected_repositories: Attribute[PaginatedList[Repository]] = NotSet
|
||||
self._selected_repositories_url: Attribute[str] = NotSet
|
||||
self._url: Attribute[str] = NotSet
|
||||
|
||||
@property
|
||||
def visibility(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._visibility)
|
||||
return self._visibility.value
|
||||
|
||||
@property
|
||||
def selected_repositories(self) -> PaginatedList[Repository]:
|
||||
return PaginatedList(
|
||||
Repository,
|
||||
self._requester,
|
||||
self._selected_repositories_url.value,
|
||||
None,
|
||||
list_item="repositories",
|
||||
)
|
||||
|
||||
def edit(
|
||||
self,
|
||||
value: str,
|
||||
visibility: str = "all",
|
||||
) -> bool:
|
||||
"""
|
||||
:calls: `PATCH /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#update-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:param visibility: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(value, str), value
|
||||
assert isinstance(visibility, str), visibility
|
||||
|
||||
patch_parameters: Dict[str, Any] = {
|
||||
"name": self.name,
|
||||
"value": value,
|
||||
"visibility": visibility,
|
||||
}
|
||||
|
||||
status, _, _ = self._requester.requestJson(
|
||||
"PATCH",
|
||||
f"{self.url}/actions/variables/{self.name}",
|
||||
input=patch_parameters,
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def add_repo(self, repo: Repository) -> bool:
|
||||
"""
|
||||
:calls: 'PUT {org_url}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#add-selected-repository-to-an-organization-secret>`_
|
||||
:param repo: github.Repository.Repository
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.visibility != "selected":
|
||||
return False
|
||||
self._requester.requestJsonAndCheck("PUT", f"{self._selected_repositories_url.value}/{repo.id}")
|
||||
return True
|
||||
|
||||
def remove_repo(self, repo: Repository) -> bool:
|
||||
"""
|
||||
:calls: 'DELETE {org_url}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#add-selected-repository-to-an-organization-secret>`_
|
||||
:param repo: github.Repository.Repository
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.visibility != "selected":
|
||||
return False
|
||||
self._requester.requestJsonAndCheck("DELETE", f"{self._selected_repositories_url.value}/{repo.id}")
|
||||
return True
|
||||
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
|
||||
if "name" in attributes:
|
||||
self._name = self._makeStringAttribute(attributes["name"])
|
||||
if "created_at" in attributes:
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "updated_at" in attributes:
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "visibility" in attributes:
|
||||
self._visibility = self._makeStringAttribute(attributes["visibility"])
|
||||
if "selected_repositories_url" in attributes:
|
||||
self._selected_repositories_url = self._makeStringAttribute(attributes["selected_repositories_url"])
|
||||
if "url" in attributes:
|
||||
self._url = self._makeStringAttribute(attributes["url"])
|
||||
+71
-44
@@ -1565,7 +1565,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
def create_repository_dispatch(self, event_type, client_payload=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: POST /repos/{owner}/{repo}/dispatches <https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event>
|
||||
:calls: POST /repos/{owner}/{repo}/dispatches <https://docs.github.com/en/rest/repos#create-a-repository-dispatch-event>
|
||||
:param event_type: string
|
||||
:param client_payload: dict
|
||||
:rtype: bool
|
||||
@@ -1580,10 +1580,10 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
def create_secret(self, secret_name, unencrypted_value):
|
||||
"""
|
||||
:calls: `PUT /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#get-a-repository-secret>`_
|
||||
:calls: `PUT /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-a-repository-secret>`_
|
||||
:param secret_name: string
|
||||
:param unencrypted_value: string
|
||||
:rtype: bool
|
||||
:rtype: github.Secret.Secret
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
assert isinstance(unencrypted_value, str), unencrypted_value
|
||||
@@ -1593,14 +1593,47 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
"key_id": public_key.key_id,
|
||||
"encrypted_value": payload,
|
||||
}
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters
|
||||
self._requester.requestJsonAndCheck("PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters)
|
||||
return github.Secret.Secret(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={
|
||||
"name": secret_name,
|
||||
"url": f"{self.url}/actions/secrets/{secret_name}",
|
||||
},
|
||||
completed=False,
|
||||
)
|
||||
|
||||
def get_secrets(self):
|
||||
"""
|
||||
Gets all repository secrets
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Secret.Secret`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.Secret.Secret,
|
||||
self._requester,
|
||||
f"{self.url}/actions/secrets",
|
||||
None,
|
||||
list_item="secrets",
|
||||
)
|
||||
|
||||
def get_secret(self, secret_name: str):
|
||||
"""
|
||||
:calls: 'GET /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-an-organization-secret>`_
|
||||
:param secret_name: string
|
||||
:rtype: github.Secret.Secret
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
return github.Secret.Secret(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={"url": f"{self.url}/actions/secrets/{secret_name}"},
|
||||
completed=False,
|
||||
)
|
||||
return status == 201
|
||||
|
||||
def create_variable(self, variable_name: str, value: str) -> bool:
|
||||
"""
|
||||
:calls: `POST /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#create-a-repository-variable>`_
|
||||
:calls: `POST /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#create-a-repository-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:rtype: bool
|
||||
@@ -1611,50 +1644,44 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
"name": variable_name,
|
||||
"value": value,
|
||||
}
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"POST", f"{self.url}/actions/variables", input=post_parameters
|
||||
self._requester.requestJsonAndCheck("POST", f"{self.url}/actions/variables", input=post_parameters)
|
||||
return github.Variable.Variable(
|
||||
self._requester,
|
||||
headers={},
|
||||
attributes={
|
||||
"name": variable_name,
|
||||
"value": value,
|
||||
"url": self.url,
|
||||
},
|
||||
completed=False,
|
||||
)
|
||||
return status == 201
|
||||
|
||||
def update_variable(self, variable_name: str, value: str) -> bool:
|
||||
def get_variables(self):
|
||||
"""
|
||||
:calls: `PATCH /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#update-a-repository-variable>`_
|
||||
Gets all repository variables
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Variable.Variable`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.Variable.Variable,
|
||||
self._requester,
|
||||
f"{self.url}/actions/variables",
|
||||
None,
|
||||
list_item="variables",
|
||||
)
|
||||
|
||||
def get_variable(self, variable_name: str):
|
||||
"""
|
||||
:calls: 'GET /orgs/{org}/actions/variables/{variable_name} <https://docs.github.com/en/rest/actions/variables#get-an-organization-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:rtype: bool
|
||||
:rtype: github.Variable.Variable
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
assert isinstance(value, str), value
|
||||
patch_parameters = {
|
||||
"name": variable_name,
|
||||
"value": value,
|
||||
}
|
||||
status, headers, data = self._requester.requestJson(
|
||||
"PATCH",
|
||||
f"{self.url}/actions/variables/{variable_name}",
|
||||
input=patch_parameters,
|
||||
return github.Variable.Variable(
|
||||
requester=self._requester,
|
||||
headers={},
|
||||
attributes={"url": f"{self.url}/actions/variables/{variable_name}"},
|
||||
completed=False,
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def delete_secret(self, secret_name):
|
||||
"""
|
||||
:calls: `DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/reference/actions#delete-a-repository-secret>`_
|
||||
:param secret_name: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(secret_name, str), secret_name
|
||||
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/secrets/{secret_name}")
|
||||
return status == 204
|
||||
|
||||
def delete_variable(self, variable_name: str) -> bool:
|
||||
"""
|
||||
:calls: `DELETE /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions#delete-a-repository-variable>`_
|
||||
:param variable_name: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(variable_name, str), variable_name
|
||||
status, headers, data = self._requester.requestJson("DELETE", f"{self.url}/actions/variables/{variable_name}")
|
||||
return status == 204
|
||||
|
||||
def create_source_import(
|
||||
self,
|
||||
|
||||
@@ -57,6 +57,7 @@ from github.RepositoryAdvisoryVulnerability import (
|
||||
)
|
||||
from github.RepositoryKey import RepositoryKey
|
||||
from github.RepositoryPreferences import RepositoryPreferences
|
||||
from github.Secret import Secret
|
||||
from github.SelfHostedActionsRunner import SelfHostedActionsRunner
|
||||
from github.SourceImport import SourceImport
|
||||
from github.Stargazer import Stargazer
|
||||
@@ -67,6 +68,7 @@ from github.StatsParticipation import StatsParticipation
|
||||
from github.StatsPunchCard import StatsPunchCard
|
||||
from github.Tag import Tag
|
||||
from github.Team import Team
|
||||
from github.Variable import Variable
|
||||
from github.View import View
|
||||
from github.Workflow import Workflow
|
||||
from github.WorkflowRun import WorkflowRun
|
||||
@@ -282,9 +284,12 @@ class Repository(CompletableGithubObject):
|
||||
def create_repository_dispatch(
|
||||
self, event_type: str, client_payload: Union[Dict[str, Any], _NotSetType] = ...
|
||||
) -> bool: ...
|
||||
def create_secret(self, secret_name: str, unencrypted_value: str) -> bool: ...
|
||||
def create_variable(self, variable_name: str, value: str) -> bool: ...
|
||||
def update_variable(self, variable_name: str, value: str) -> bool: ...
|
||||
def get_secrets(self) -> PaginatedList[Secret]: ...
|
||||
def get_secret(self, secret_name: str) -> Secret: ...
|
||||
def create_secret(self, secret_name: str, unencrypted_value: str) -> Secret: ...
|
||||
def get_variables(self) -> PaginatedList[Variable]: ...
|
||||
def get_variable(self, variable_name: str) -> Variable: ...
|
||||
def create_variable(self, variable_name: str, value: str) -> Variable: ...
|
||||
def delete_secret(self, secret_name: str) -> bool: ...
|
||||
def delete_variable(self, variable_name: str) -> bool: ...
|
||||
def create_source_import(
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> #
|
||||
# #
|
||||
# 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 datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from github.GithubObject import Attribute, CompletableGithubObject, NotSet
|
||||
|
||||
|
||||
class Secret(CompletableGithubObject):
|
||||
"""
|
||||
This class represents a GitHub secret. The reference can be found here https://docs.github.com/en/rest/actions/secrets
|
||||
"""
|
||||
|
||||
def _initAttributes(self) -> None:
|
||||
self._name: Attribute[str] = NotSet
|
||||
self._created_at: Attribute[datetime] = NotSet
|
||||
self._updated_at: Attribute[datetime] = NotSet
|
||||
self._url: Attribute[str] = NotSet
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.get__repr__({"name": self.name})
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._name)
|
||||
return self._name.value
|
||||
|
||||
@property
|
||||
def created_at(self) -> datetime:
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._created_at)
|
||||
return self._created_at.value
|
||||
|
||||
@property
|
||||
def updated_at(self) -> datetime:
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._updated_at)
|
||||
return self._updated_at.value
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
return self._url.value
|
||||
|
||||
def delete(self) -> None:
|
||||
"""
|
||||
:calls: `DELETE {secret_url} <https://docs.github.com/en/rest/actions/secrets>`_
|
||||
:rtype: None
|
||||
"""
|
||||
self._requester.requestJsonAndCheck("DELETE", self.url)
|
||||
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
|
||||
if "name" in attributes:
|
||||
self._name = self._makeStringAttribute(attributes["name"])
|
||||
if "created_at" in attributes:
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "updated_at" in attributes:
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "url" in attributes:
|
||||
self._url = self._makeStringAttribute(attributes["url"])
|
||||
@@ -0,0 +1,121 @@
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> #
|
||||
# #
|
||||
# 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 datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from github.GithubObject import Attribute, CompletableGithubObject, NotSet
|
||||
|
||||
|
||||
class Variable(CompletableGithubObject):
|
||||
"""
|
||||
This class represents a GitHub variable. The reference can be found here https://docs.github.com/en/rest/actions/variables
|
||||
"""
|
||||
|
||||
def _initAttributes(self) -> None:
|
||||
self._name: Attribute[str] = NotSet
|
||||
self._value: Attribute[str] = NotSet
|
||||
self._created_at: Attribute[datetime] = NotSet
|
||||
self._updated_at: Attribute[datetime] = NotSet
|
||||
self._url: Attribute[str] = NotSet
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.get__repr__({"name": self.name})
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._name)
|
||||
return self._name.value
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._value)
|
||||
return self._value.value
|
||||
|
||||
@property
|
||||
def created_at(self) -> datetime:
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._created_at)
|
||||
return self._created_at.value
|
||||
|
||||
@property
|
||||
def updated_at(self) -> datetime:
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._updated_at)
|
||||
return self._updated_at.value
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
return self._url.value
|
||||
|
||||
def edit(self, value: str) -> bool:
|
||||
"""
|
||||
:calls: `PATCH /repos/{owner}/{repo}/actions/variables/{variable_name} <https://docs.github.com/en/rest/reference/actions/variables#update-a-repository-variable>`_
|
||||
:param variable_name: string
|
||||
:param value: string
|
||||
:rtype: bool
|
||||
"""
|
||||
assert isinstance(value, str), value
|
||||
patch_parameters = {
|
||||
"name": self.name,
|
||||
"value": value,
|
||||
}
|
||||
status, _, _ = self._requester.requestJson(
|
||||
"PATCH",
|
||||
f"{self.url}/actions/variables/{self.name}",
|
||||
input=patch_parameters,
|
||||
)
|
||||
return status == 204
|
||||
|
||||
def delete(self) -> None:
|
||||
"""
|
||||
:calls: `DELETE {variable_url} <https://docs.github.com/en/rest/actions/variables>`_
|
||||
:rtype: None
|
||||
"""
|
||||
self._requester.requestJsonAndCheck("DELETE", f"{self.url}/actions/variables/{self.name}")
|
||||
|
||||
def _useAttributes(self, attributes: dict[str, Any]) -> None:
|
||||
if "name" in attributes:
|
||||
self._name = self._makeStringAttribute(attributes["name"])
|
||||
if "value" in attributes:
|
||||
self._value = self._makeStringAttribute(attributes["value"])
|
||||
if "created_at" in attributes:
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "updated_at" in attributes:
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "url" in attributes:
|
||||
self._url = self._makeStringAttribute(attributes["url"])
|
||||
Reference in New Issue
Block a user