Add Secret and Variable classes (#2623)

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
Mauricio Alejandro Martínez Pacheco
2023-08-10 10:06:44 +02:00
committed by GitHub
co-authored by Enrico Minack
parent 7cfa476187
commit bcca758d13
19 changed files with 865 additions and 157 deletions
+71 -44
View File
@@ -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,