Environment.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 __future__ import annotations 23 24 from datetime import datetime 25 from typing import TYPE_CHECKING, Any 26 27 import github.EnvironmentDeploymentBranchPolicy 28 import github.EnvironmentProtectionRule 29 from github.GithubObject import Attribute, CompletableGithubObject, NotSet 30 31 if TYPE_CHECKING: 32 from github.EnvironmentDeploymentBranchPolicy import EnvironmentDeploymentBranchPolicy 33 from github.EnvironmentProtectionRule import EnvironmentProtectionRule 34 35 36 class Environment(CompletableGithubObject): 37 """ 38 This class represents Environment. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments 39 """ 40 41 def _initAttributes(self) -> None: 42 self._created_at: Attribute[datetime] = NotSet 43 self._html_url: Attribute[str] = NotSet 44 self._id: Attribute[int] = NotSet 45 self._name: Attribute[str] = NotSet 46 self._node_id: Attribute[str] = NotSet 47 self._protection_rules: Attribute[list[EnvironmentProtectionRule]] = NotSet 48 self._updated_at: Attribute[datetime] = NotSet 49 self._url: Attribute[str] = NotSet 50 self._deployment_branch_policy: Attribute[EnvironmentDeploymentBranchPolicy] = NotSet 51 52 def __repr__(self) -> str: 53 return self.get__repr__({"name": self._name.value}) 54 55 @property 56 def created_at(self) -> datetime: 57 self._completeIfNotSet(self._created_at) 58 return self._created_at.value 59 60 @property 61 def html_url(self) -> str: 62 self._completeIfNotSet(self._html_url) 63 return self._html_url.value 64 65 @property 66 def id(self) -> int: 67 self._completeIfNotSet(self._id) 68 return self._id.value 69 70 @property 71 def name(self) -> str: 72 self._completeIfNotSet(self._name) 73 return self._name.value 74 75 @property 76 def node_id(self) -> str: 77 self._completeIfNotSet(self._node_id) 78 return self._node_id.value 79 80 @property 81 def protection_rules( 82 self, 83 ) -> list[EnvironmentProtectionRule]: 84 self._completeIfNotSet(self._protection_rules) 85 return self._protection_rules.value 86 87 @property 88 def updated_at(self) -> datetime: 89 self._completeIfNotSet(self._updated_at) 90 return self._updated_at.value 91 92 @property 93 def url(self) -> str: 94 self._completeIfNotSet(self._url) 95 return self._url.value 96 97 @property 98 def deployment_branch_policy( 99 self, 100 ) -> EnvironmentDeploymentBranchPolicy: 101 self._completeIfNotSet(self._deployment_branch_policy) 102 return self._deployment_branch_policy.value 103 104 def _useAttributes(self, attributes: dict[str, Any]) -> None: 105 if "created_at" in attributes: # pragma no branch 106 self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) 107 if "html_url" in attributes: # pragma no branch 108 self._html_url = self._makeStringAttribute(attributes["html_url"]) 109 if "id" in attributes: # pragma no branch 110 self._id = self._makeIntAttribute(attributes["id"]) 111 if "name" in attributes: # pragma no branch 112 self._name = self._makeStringAttribute(attributes["name"]) 113 if "node_id" in attributes: # pragma no branch 114 self._node_id = self._makeStringAttribute(attributes["node_id"]) 115 if "protection_rules" in attributes: # pragma no branch 116 self._protection_rules = self._makeListOfClassesAttribute( 117 github.EnvironmentProtectionRule.EnvironmentProtectionRule, 118 attributes["protection_rules"], 119 ) 120 if "updated_at" in attributes: # pragma no branch 121 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) 122 if "url" in attributes: # pragma no branch 123 self._url = self._makeStringAttribute(attributes["url"]) 124 if "deployment_branch_policy" in attributes: # pragma no branch 125 self._deployment_branch_policy = self._makeClassAttribute( 126 github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicy, 127 attributes["deployment_branch_policy"], 128 )