-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
AdvisoryCredit.py
112 lines (93 loc) · 4.57 KB
/
AdvisoryCredit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
############################ Copyrights and license ############################
# #
# Copyright 2023 Enrico Minack <github@enrico.minack.dev> #
# Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> #
# Copyright 2023 Jonathan Leitschuh <jonathan.leitschuh@gmail.com> #
# Copyright 2023 Joseph Henrich <crimsonknave@gmail.com> #
# Copyright 2023 Trim21 <trim21.me@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from __future__ import annotations
from typing import Any, Union
from typing_extensions import TypedDict
import github.NamedUser
from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
class SimpleCredit(TypedDict):
"""
A simple credit for a security advisory.
"""
login: str | github.NamedUser.NamedUser
type: str
Credit = Union[SimpleCredit, "AdvisoryCredit"]
class AdvisoryCredit(NonCompletableGithubObject):
"""
This class represents a credit that is assigned to a SecurityAdvisory.
The reference can be found here
https://docs.github.com/en/rest/security-advisories/repository-advisories
"""
@property
def login(self) -> str:
"""
:type: string
"""
return self._login.value
@property
def type(self) -> str:
"""
:type: string
"""
return self._type.value
def _initAttributes(self) -> None:
self._login: Attribute[str] = NotSet
self._type: Attribute[str] = NotSet
def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "login" in attributes: # pragma no branch
self._login = self._makeStringAttribute(attributes["login"])
if "type" in attributes: # pragma no branch
self._type = self._makeStringAttribute(attributes["type"])
@staticmethod
def _validate_credit(credit: Credit) -> None:
assert isinstance(credit, (dict, AdvisoryCredit)), credit
if isinstance(credit, dict):
assert "login" in credit, credit
assert "type" in credit, credit
assert isinstance(credit["login"], (str, github.NamedUser.NamedUser)), credit["login"]
assert isinstance(credit["type"], str), credit["type"]
else:
assert isinstance(credit.login, str), credit.login
assert isinstance(credit.type, str), credit.type
@staticmethod
def _to_github_dict(credit: Credit) -> SimpleCredit:
assert isinstance(credit, (dict, AdvisoryCredit)), credit
if isinstance(credit, dict):
assert "login" in credit, credit
assert "type" in credit, credit
assert isinstance(credit["login"], (str, github.NamedUser.NamedUser)), credit["login"]
login = credit["login"]
if isinstance(login, github.NamedUser.NamedUser):
login = login.login
return {
"login": login,
"type": credit["type"],
}
else:
return {
"login": credit.login,
"type": credit.type,
}