/ github / EnvironmentDeploymentBranchPolicy.py
EnvironmentDeploymentBranchPolicy.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2022 Alson van der Meulen <alson.vandermeulen@dearhealth.com>      #
 4  #                                                                              #
 5  # This file is part of PyGithub.                                               #
 6  # http://pygithub.readthedocs.io/                                              #
 7  #                                                                              #
 8  # PyGithub is free software: you can redistribute it and/or modify it under    #
 9  # the terms of the GNU Lesser General Public License as published by the Free  #
10  # Software Foundation, either version 3 of the License, or (at your option)    #
11  # any later version.                                                           #
12  #                                                                              #
13  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
15  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
16  # details.                                                                     #
17  #                                                                              #
18  # You should have received a copy of the GNU Lesser General Public License     #
19  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
20  #                                                                              #
21  ################################################################################
22  from typing import Any, Dict
23  
24  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
25  
26  
27  class EnvironmentDeploymentBranchPolicy(NonCompletableGithubObject):
28      """
29      This class represents a deployment branch policy for an environment. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments
30      """
31  
32      def _initAttributes(self) -> None:
33          self._protected_branches: Attribute[bool] = NotSet
34          self._custom_branch_policies: Attribute[bool] = NotSet
35  
36      def __repr__(self) -> str:
37          return self.get__repr__({})
38  
39      @property
40      def protected_branches(self) -> bool:
41          return self._protected_branches.value
42  
43      @property
44      def custom_branch_policies(self) -> bool:
45          return self._custom_branch_policies.value
46  
47      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
48          if "protected_branches" in attributes:  # pragma no branch
49              self._protected_branches = self._makeBoolAttribute(attributes["protected_branches"])
50          if "custom_branch_policies" in attributes:  # pragma no branch
51              self._custom_branch_policies = self._makeBoolAttribute(attributes["custom_branch_policies"])
52  
53  
54  class EnvironmentDeploymentBranchPolicyParams:
55      """
56      This class presents the deployment branch policy parameters as can be configured for an Environment.
57      """
58  
59      def __init__(self, protected_branches: bool = False, custom_branch_policies: bool = False):
60          assert isinstance(protected_branches, bool)
61          assert isinstance(custom_branch_policies, bool)
62          self.protected_branches = protected_branches
63          self.custom_branch_policies = custom_branch_policies
64  
65      def _asdict(self) -> dict:
66          return {
67              "protected_branches": self.protected_branches,
68              "custom_branch_policies": self.custom_branch_policies,
69          }