/ github / CodeScanAlert.py
CodeScanAlert.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2022 Eric Nieuwland <eric.nieuwland@gmail.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 Any
 26  
 27  import github.CodeScanAlertInstance
 28  import github.CodeScanRule
 29  import github.CodeScanTool
 30  import github.GithubObject
 31  import github.NamedUser
 32  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
 33  from github.PaginatedList import PaginatedList
 34  
 35  
 36  class CodeScanAlert(NonCompletableGithubObject):
 37      """
 38      This class represents alerts from code scanning.
 39      The reference can be found here https://docs.github.com/en/rest/reference/code-scanning.
 40      """
 41  
 42      def _initAttributes(self) -> None:
 43          self._number: Attribute[int] = NotSet
 44          self._rule: Attribute[github.CodeScanRule.CodeScanRule] = NotSet
 45          self._tool: Attribute[github.CodeScanTool.CodeScanTool] = NotSet
 46          self._created_at: Attribute[datetime] = NotSet
 47          self._dismissed_at: Attribute[datetime | None] = NotSet
 48          self._dismissed_by: Attribute[github.NamedUser.NamedUser | None] = NotSet
 49          self._dismissed_reason: Attribute[str | None] = NotSet
 50          self._url: Attribute[str] = NotSet
 51          self._html_url: Attribute[str] = NotSet
 52          self._instances_url: Attribute[str] = NotSet
 53          self._most_recent_instance: Attribute[github.CodeScanAlertInstance.CodeScanAlertInstance] = NotSet
 54          self._state: Attribute[str] = NotSet
 55  
 56      def __repr__(self) -> str:
 57          return self.get__repr__({"number": self.number})
 58  
 59      @property
 60      def number(self) -> int:
 61          return self._number.value
 62  
 63      @property
 64      def rule(self) -> github.CodeScanRule.CodeScanRule:
 65          return self._rule.value
 66  
 67      @property
 68      def tool(self) -> github.CodeScanTool.CodeScanTool:
 69          return self._tool.value
 70  
 71      @property
 72      def created_at(self) -> datetime:
 73          return self._created_at.value
 74  
 75      @property
 76      def dismissed_at(self) -> datetime | None:
 77          return self._dismissed_at.value
 78  
 79      @property
 80      def dismissed_by(self) -> github.NamedUser.NamedUser | None:
 81          return self._dismissed_by.value
 82  
 83      @property
 84      def dismissed_reason(self) -> str | None:
 85          return self._dismissed_reason.value
 86  
 87      @property
 88      def url(self) -> str:
 89          return self._url.value
 90  
 91      @property
 92      def html_url(self) -> str:
 93          return self._html_url.value
 94  
 95      @property
 96      def instances_url(self) -> str:
 97          return self._instances_url.value
 98  
 99      @property
100      def most_recent_instance(self) -> github.CodeScanAlertInstance.CodeScanAlertInstance:
101          return self._most_recent_instance.value
102  
103      @property
104      def state(self) -> str:
105          return self._state.value
106  
107      def get_instances(self) -> PaginatedList[github.CodeScanAlertInstance.CodeScanAlertInstance]:
108          """
109          :calls: `GET` on the URL for instances as provided by Github
110          """
111          return PaginatedList(
112              github.CodeScanAlertInstance.CodeScanAlertInstance,
113              self._requester,
114              self.instances_url,
115              None,
116          )
117  
118      def _useAttributes(self, attributes: dict[str, Any]) -> None:
119          if "number" in attributes:  # pragma no branch
120              self._number = self._makeIntAttribute(attributes["number"])
121          if "rule" in attributes:  # pragma no branch
122              self._rule = self._makeClassAttribute(github.CodeScanRule.CodeScanRule, attributes["rule"])
123          if "tool" in attributes:  # pragma no branch
124              self._tool = self._makeClassAttribute(github.CodeScanTool.CodeScanTool, attributes["tool"])
125  
126          if "created_at" in attributes:  # pragma no branch
127              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
128          if "dismissed_at" in attributes:  # pragma no branch
129              self._dismissed_at = self._makeDatetimeAttribute(attributes["dismissed_at"])
130          if "dismissed_by" in attributes:  # pragma no branch
131              self._dismissed_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["dismissed_by"])
132          if "dismissed_reason" in attributes:  # pragma no branch
133              self._dismissed_reason = self._makeStringAttribute(attributes["dismissed_reason"])
134  
135          if "url" in attributes:  # pragma no branch
136              self._url = self._makeStringAttribute(attributes["url"])
137          if "html_url" in attributes:  # pragma no branch
138              self._html_url = self._makeStringAttribute(attributes["html_url"])
139          if "instances_url" in attributes:  # pragma no branch
140              self._instances_url = self._makeStringAttribute(attributes["instances_url"])
141  
142          if "most_recent_instance" in attributes:  # pragma no branch
143              self._most_recent_instance = self._makeClassAttribute(
144                  github.CodeScanAlertInstance.CodeScanAlertInstance,
145                  attributes["most_recent_instance"],
146              )
147          if "state" in attributes:  # pragma no branch
148              self._state = self._makeStringAttribute(attributes["state"])