Add support for repo and org level actions variables (#2580)

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
Mauricio Alejandro Martínez Pacheco
2023-07-07 15:29:30 +02:00
committed by GitHub
co-authored by Enrico Minack
parent 766df993da
commit 91b3f40f79
8 changed files with 265 additions and 2 deletions
+51
View File
@@ -104,6 +104,7 @@
# Copyright 2023 Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com> #
# Copyright 2023 Sol Redfern <59831933+Tsuesun@users.noreply.github.com> #
# Copyright 2023 Mikhail f. Shiryaev <mr.felixoid@gmail.com> #
# Copyright 2023 Mauricio Martinez <mauricio.martinez@premise.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
@@ -1714,6 +1715,44 @@ class Repository(github.GithubObject.CompletableGithubObject):
)
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>`_
:param variable_name: string
:param value: string
:rtype: bool
"""
assert isinstance(variable_name, str), variable_name
assert isinstance(value, str), value
post_parameters = {
"name": variable_name,
"value": value,
}
status, headers, data = self._requester.requestJson(
"POST", f"{self.url}/actions/variables", input=post_parameters
)
return status == 201
def update_variable(self, variable_name: str, 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(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 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>`_
@@ -1726,6 +1765,18 @@ class Repository(github.GithubObject.CompletableGithubObject):
)
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,
vcs,