/ github / EnvironmentProtectionRuleReviewer.py
EnvironmentProtectionRuleReviewer.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  
23  from __future__ import annotations
24  
25  from typing import Any
26  
27  import github.NamedUser
28  import github.Team
29  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
30  
31  
32  class EnvironmentProtectionRuleReviewer(NonCompletableGithubObject):
33      """
34      This class represents a reviewer for an EnvironmentProtectionRule. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments
35      """
36  
37      def _initAttributes(self) -> None:
38          self._type: Attribute[str] = NotSet
39          self._reviewer: Attribute[github.NamedUser.NamedUser | github.Team.Team] = NotSet
40  
41      def __repr__(self) -> str:
42          return self.get__repr__({"type": self._type.value})
43  
44      @property
45      def type(self) -> str:
46          return self._type.value
47  
48      @property
49      def reviewer(self) -> github.NamedUser.NamedUser | github.Team.Team:
50          return self._reviewer.value
51  
52      def _useAttributes(self, attributes: dict[str, Any]) -> None:
53          if "type" in attributes:  # pragma no branch
54              self._type = self._makeStringAttribute(attributes["type"])
55          if "reviewer" in attributes:  # pragma no branch
56              assert self._type.value in ("User", "Team")
57              if self._type.value == "User":
58                  self._reviewer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["reviewer"])
59              elif self._type.value == "Team":
60                  self._reviewer = self._makeClassAttribute(github.Team.Team, attributes["reviewer"])
61  
62  
63  class ReviewerParams:
64      """
65      This class presents reviewers as can be configured for an Environment.
66      """
67  
68      def __init__(self, type_: str, id_: int):
69          assert isinstance(type_, str) and type_ in ("User", "Team")
70          assert isinstance(id_, int)
71          self.type = type_
72          self.id = id_
73  
74      def _asdict(self) -> dict:
75          return {
76              "type": self.type,
77              "id": self.id,
78          }