Skip to content

Commit

Permalink
Implement deleting environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
alson committed Feb 17, 2023
1 parent 988380e commit 173d755
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
17 changes: 15 additions & 2 deletions github/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
# Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> #
# Copyright 2022 Aleksei Fedotov <aleksei@fedotov.email> #
# Copyright 2022 Eric Nieuwland <eric.nieuwland@gmail.com> #
# Copyright 2022 Alson van der Meulen <alson.vandermeulen@dearhealth.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
Expand Down Expand Up @@ -3838,8 +3839,8 @@ def create_environment(
deployment_branch_policy=None,
):
"""
:calls: `PUT /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/pulls>`_
:param name: string
:calls: `PUT /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/deployments#create-or-update-an-environment>`_
:param environment_name: string
:param wait_timer: int
:param reviews: List[:class:github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams]
:param deployment_branch_policy: Optional[:class:github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams`]
Expand Down Expand Up @@ -3881,6 +3882,18 @@ def create_environment(

update_environment = create_environment

def delete_environment(self, environment_name):
"""
:calls: `DELETE /repos/{owner}/{repo}/environments/{environment_name} <https://docs.github.com/en/rest/reference/deployments#delete-an-environment>`_
:param environment_name: string
:rtype: None
"""
assert isinstance(environment_name, str), environment_name

headers, data = self._requester.requestJsonAndCheck(
"DELETE", f"{self.url}/environments/{environment_name}"
)

def _initAttributes(self):
self._allow_forking = github.GithubObject.NotSet
self._allow_merge_commit = github.GithubObject.NotSet
Expand Down
15 changes: 8 additions & 7 deletions github/Repository.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ class Repository(CompletableGithubObject):
reviewers: List[ReviewerParams] = ...,
deployment_branch_policy: Optional[EnvironmentDeploymentBranchPolicyParams] = ...,
) -> Environment: ...
def update_environment(
self,
environment_name: str,
wait_timer: int = ...,
reviewers: List[ReviewerParams] = ...,
deployment_branch_policy: Optional[EnvironmentDeploymentBranchPolicyParams] = ...,
) -> Environment: ...
def create_file(
self,
path: str,
Expand Down Expand Up @@ -274,6 +267,7 @@ class Repository(CompletableGithubObject):
@property
def default_branch(self) -> str: ...
def delete(self) -> None: ...
def delete_environment(self, environment_name: str) -> None: ...
def delete_file(
self,
path: str,
Expand Down Expand Up @@ -624,6 +618,13 @@ class Repository(CompletableGithubObject):
@property
def trees_url(self) -> str: ...
def unsubscribe_from_hub(self, event: str, callback: str) -> None: ...
def update_environment(
self,
environment_name: str,
wait_timer: int = ...,
reviewers: List[ReviewerParams] = ...,
deployment_branch_policy: Optional[EnvironmentDeploymentBranchPolicyParams] = ...,
) -> Environment: ...
def update_file(
self,
path: str,
Expand Down
9 changes: 9 additions & 0 deletions tests/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import datetime

import pytest

import github
import github.EnvironmentDeploymentBranchPolicy
import github.EnvironmentProtectionRule
import github.EnvironmentProtectionRuleReviewer
Expand Down Expand Up @@ -76,6 +79,7 @@ def testProtectionRules(self):
self.assertEqual(protection_rules[2].wait_timer, 15)

def testReviewers(self):
# This is necessary so we can maintain our own expectations, which have been manually editted, for this test.
reviewers = self.repo.get_environment("dev").protection_rules[1].reviewers
self.assertEqual(len(reviewers), 2)
self.assertEqual(reviewers[0].type, "User")
Expand Down Expand Up @@ -168,3 +172,8 @@ def testUpdateEnvironment(self):
self.assertEqual(environment.protection_rules[2].type, "branch_policy")
self.assertTrue(environment.deployment_branch_policy.protected_branches)
self.assertFalse(environment.deployment_branch_policy.custom_branch_policies)

def testDeleteEnvironment(self):
self.repo.delete_environment("test")
with pytest.raises(github.UnknownObjectException):
self.repo.get_environment("test")

0 comments on commit 173d755

Please sign in to comment.