Skip to content

Commit 197e065

Browse files
Add missing preview features of Deployment and Deployment Statuses API (PyGithub#1674)
* Add missing preview features of Deployment and Deployment Statuses API - Enable support for deployment status states in_progress and queued - Add arguments production_environment and transient_environment to Repository.create_deployment() - Add attributes production_environment and transient_environment to Deployment - Use correct type in assertion for Deployment.payload - Fix incorrect assertion for description in Deployment.create_status() - Add arguments environment, environment_url, auto_inactive to Deployment.create_status() - Add attribute environment_url to DeploymentStatus
1 parent fcdd9ea commit 197e065

16 files changed

+233
-77
lines changed

github/Consts.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Copyright 2018 Wan Liuyang <[email protected]> #
1212
# Copyright 2018 sfdye <[email protected]> #
1313
# Copyright 2019 Nick Campbell <[email protected]> #
14+
# Copyright 2020 Pascal Hofmann <[email protected]> #
1415
# #
1516
# This file is part of PyGithub. #
1617
# http://pygithub.readthedocs.io/ #
@@ -123,3 +124,6 @@
123124

124125
# https://developer.github.com/changes/2016-04-06-deployment-and-deployment-status-enhancements/
125126
deploymentEnhancementsPreview = "application/vnd.github.ant-man-preview+json"
127+
128+
# https://developer.github.com/changes/2018-10-16-deployments-environments-states-and-auto-inactive-updates/
129+
deploymentStatusEnhancementsPreview = "application/vnd.github.flash-preview+json"

github/Deployment.py

+63-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# #
55
# Copyright 2020 Steve Kowalik <[email protected]> #
66
# Copyright 2020 Colby Gallup <[email protected]> #
7+
# Copyright 2020 Pascal Hofmann <[email protected]> #
78
# #
89
# This file is part of PyGithub. #
910
# http://pygithub.readthedocs.io/ #
@@ -92,6 +93,22 @@ def environment(self):
9293
self._completeIfNotSet(self._environment)
9394
return self._environment.value
9495

96+
@property
97+
def production_environment(self):
98+
"""
99+
:type: bool
100+
"""
101+
self._completeIfNotSet(self._production_environment)
102+
return self._production_environment.value
103+
104+
@property
105+
def transient_environment(self):
106+
"""
107+
:type: bool
108+
"""
109+
self._completeIfNotSet(self._transient_environment)
110+
return self._transient_environment.value
111+
95112
@property
96113
def description(self):
97114
"""
@@ -150,6 +167,7 @@ def get_statuses(self):
150167
self._requester,
151168
self.url + "/statuses",
152169
None,
170+
headers={"Accept": self._get_accept_header()},
153171
)
154172

155173
def get_status(self, id_):
@@ -162,7 +180,7 @@ def get_status(self, id_):
162180
headers, data = self._requester.requestJsonAndCheck(
163181
"GET",
164182
self.url + "/statuses/" + str(id_),
165-
headers={"Accept": github.Consts.deploymentEnhancementsPreview},
183+
headers={"Accept": self._get_accept_header()},
166184
)
167185
return github.DeploymentStatus.DeploymentStatus(
168186
self._requester, headers, data, completed=True
@@ -173,12 +191,18 @@ def create_status(
173191
state,
174192
target_url=github.GithubObject.NotSet,
175193
description=github.GithubObject.NotSet,
194+
environment=github.GithubObject.NotSet,
195+
environment_url=github.GithubObject.NotSet,
196+
auto_inactive=github.GithubObject.NotSet,
176197
):
177198
"""
178199
:calls: `POST /repos/:owner/:repo/deployments/:deployment_id/statuses <https://developer.github.com/v3/repos/deployments/#create-a-deployment-status>`_
179200
:param: state: string
180201
:param: target_url: string
181202
:param: description: string
203+
:param: environment: string
204+
:param: environment_url: string
205+
:param: auto_inactive: bool
182206
:rtype: :class:`github.DeploymentStatus.DeploymentStatus`
183207
"""
184208
assert isinstance(state, str), state
@@ -187,23 +211,52 @@ def create_status(
187211
), target_url
188212
assert description is github.GithubObject.NotSet or isinstance(
189213
description, str
190-
), target_url
214+
), description
215+
assert environment is github.GithubObject.NotSet or isinstance(
216+
environment, str
217+
), environment
218+
assert environment_url is github.GithubObject.NotSet or isinstance(
219+
environment_url, str
220+
), environment_url
221+
assert auto_inactive is github.GithubObject.NotSet or isinstance(
222+
auto_inactive, bool
223+
), auto_inactive
224+
191225
post_parameters = {"state": state}
192226
if target_url is not github.GithubObject.NotSet:
193227
post_parameters["target_url"] = target_url
194228
if description is not github.GithubObject.NotSet:
195229
post_parameters["description"] = description
230+
if environment is not github.GithubObject.NotSet:
231+
post_parameters["environment"] = environment
232+
if environment_url is not github.GithubObject.NotSet:
233+
post_parameters["environment_url"] = environment_url
234+
if auto_inactive is not github.GithubObject.NotSet:
235+
post_parameters["auto_inactive"] = auto_inactive
236+
196237
headers, data = self._requester.requestJsonAndCheck(
197238
"POST",
198239
self.url + "/statuses",
199240
input=post_parameters,
241+
headers={"Accept": self._get_accept_header()},
200242
)
201243
return github.DeploymentStatus.DeploymentStatus(
202244
self._requester, headers, data, completed=True
203245
)
204246

247+
@staticmethod
248+
def _get_accept_header():
249+
return ", ".join(
250+
[
251+
github.Consts.deploymentEnhancementsPreview,
252+
github.Consts.deploymentStatusEnhancementsPreview,
253+
]
254+
)
255+
205256
def _initAttributes(self):
206257
self._id = github.GithubObject.NotSet
258+
self._production_environment = github.GithubObject.NotSet
259+
self._transient_environment = github.GithubObject.NotSet
207260
self._url = github.GithubObject.NotSet
208261
self._sha = github.GithubObject.NotSet
209262
self._task = github.GithubObject.NotSet
@@ -220,6 +273,14 @@ def _initAttributes(self):
220273
def _useAttributes(self, attributes):
221274
if "id" in attributes: # pragma no branch
222275
self._id = self._makeIntAttribute(attributes["id"])
276+
if "production_environment" in attributes: # pragma no branch
277+
self._production_environment = self._makeBoolAttribute(
278+
attributes["production_environment"]
279+
)
280+
if "transient_environment" in attributes: # pragma no branch
281+
self._transient_environment = self._makeBoolAttribute(
282+
attributes["transient_environment"]
283+
)
223284
if "url" in attributes: # pragma no branch
224285
self._url = self._makeStringAttribute(attributes["url"])
225286
if "sha" in attributes: # pragma no branch

github/Deployment.pyi

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ from github.PaginatedList import PaginatedList
88

99
class Deployment(CompletableGithubObject):
1010
def __repr__(self) -> str: ...
11+
@staticmethod
12+
def _get_accept_header() -> str: ...
1113
def _initAttributes(self) -> None: ...
1214
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
1315
def get_statuses(self) -> PaginatedList[DeploymentStatus]: ...
@@ -17,6 +19,9 @@ class Deployment(CompletableGithubObject):
1719
state: str,
1820
target_url: Union[str, _NotSetType] = ...,
1921
description: Union[str, _NotSetType] = ...,
22+
environment: Union[str, _NotSetType] = ...,
23+
environment_url: Union[str, _NotSetType] = ...,
24+
auto_inactive: Union[bool, _NotSetType] = ...,
2025
) -> DeploymentStatus: ...
2126
@property
2227
def id(self) -> int: ...
@@ -33,6 +38,10 @@ class Deployment(CompletableGithubObject):
3338
@property
3439
def environment(self) -> str: ...
3540
@property
41+
def production_environment(self) -> bool: ...
42+
@property
43+
def transient_environment(self) -> bool: ...
44+
@property
3645
def description(self) -> str: ...
3746
@property
3847
def creator(self) -> NamedUser: ...

github/DeploymentStatus.py

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
############################ Copyrights and license ############################
44
# #
55
# Copyright 2020 Colby Gallup <[email protected]> #
6+
# Copyright 2020 Pascal Hofmann <[email protected]> #
67
# #
78
# This file is part of PyGithub. #
89
# http://pygithub.readthedocs.io/ #
@@ -73,6 +74,14 @@ def environment(self):
7374
self._completeIfNotSet(self._environment)
7475
return self._environment.value
7576

77+
@property
78+
def environment_url(self):
79+
"""
80+
:type: string
81+
"""
82+
self._completeIfNotSet(self._environment_url)
83+
return self._environment_url.value
84+
7685
@property
7786
def repository_url(self):
7887
"""
@@ -135,6 +144,7 @@ def _initAttributes(self):
135144
self._deployment_url = github.GithubObject.NotSet
136145
self._description = github.GithubObject.NotSet
137146
self._environment = github.GithubObject.NotSet
147+
self._environment_url = github.GithubObject.NotSet
138148
self._repository_url = github.GithubObject.NotSet
139149
self._state = github.GithubObject.NotSet
140150
self._target_url = github.GithubObject.NotSet
@@ -144,6 +154,10 @@ def _initAttributes(self):
144154
self._node_id = github.GithubObject.NotSet
145155

146156
def _useAttributes(self, attributes):
157+
if "environment_url" in attributes: # pragma no branch
158+
self._environment_url = self._makeStringAttribute(
159+
attributes["environment_url"]
160+
)
147161
if "url" in attributes: # pragma no branch
148162
self._url = self._makeStringAttribute(attributes["url"])
149163
if "id" in attributes: # pragma no branch

github/DeploymentStatus.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DeploymentStatus(CompletableGithubObject):
2020
@property
2121
def environment(self) -> str: ...
2222
@property
23+
def environment_url(self) -> str: ...
24+
@property
2325
def repository_url(self) -> str: ...
2426
@property
2527
def state(self) -> str: ...

github/Repository.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
# Copyright 2018 Zilei Gu <[email protected]> #
6767
# Copyright 2018 Yves Zumbach <[email protected]> #
6868
# Copyright 2018 Leying Chen <[email protected]> #
69+
# Copyright 2020 Pascal Hofmann <[email protected]> #
6970
# #
7071
# This file is part of PyGithub. #
7172
# http://pygithub.readthedocs.io/ #
@@ -1812,6 +1813,7 @@ def get_deployments(
18121813
self._requester,
18131814
self.url + "/deployments",
18141815
parameters,
1816+
headers={"Accept": Consts.deploymentEnhancementsPreview},
18151817
)
18161818

18171819
def get_deployment(self, id_):
@@ -1822,7 +1824,9 @@ def get_deployment(self, id_):
18221824
"""
18231825
assert isinstance(id_, int), id_
18241826
headers, data = self._requester.requestJsonAndCheck(
1825-
"GET", self.url + "/deployments/" + str(id_)
1827+
"GET",
1828+
self.url + "/deployments/" + str(id_),
1829+
headers={"Accept": Consts.deploymentEnhancementsPreview},
18261830
)
18271831
return github.Deployment.Deployment(
18281832
self._requester, headers, data, completed=True
@@ -1837,15 +1841,20 @@ def create_deployment(
18371841
payload=github.GithubObject.NotSet,
18381842
environment=github.GithubObject.NotSet,
18391843
description=github.GithubObject.NotSet,
1844+
transient_environment=github.GithubObject.NotSet,
1845+
production_environment=github.GithubObject.NotSet,
18401846
):
18411847
"""
18421848
:calls: `POST /repos/:owner/:repo/deployments <https://developer.github.com/v3/repos/deployments/>`_
18431849
:param: ref: string
1850+
:param: task: string
18441851
:param: auto_merge: bool
1845-
:param: required_contexts: list of statuses
1846-
:param: payload: json
1852+
:param: required_contexts: list of status contexts
1853+
:param: payload: dict
18471854
:param: environment: string
18481855
:param: description: string
1856+
:param: transient_environment: bool
1857+
:param: production_environment: bool
18491858
:rtype: :class:`github.Deployment.Deployment`
18501859
"""
18511860
assert isinstance(ref, str), ref
@@ -1857,14 +1866,21 @@ def create_deployment(
18571866
required_contexts, list
18581867
), required_contexts # need to do better checking here
18591868
assert payload is github.GithubObject.NotSet or isinstance(
1860-
payload, str
1861-
), payload # How to assert it's JSON?
1869+
payload, dict
1870+
), payload
18621871
assert environment is github.GithubObject.NotSet or isinstance(
18631872
environment, str
18641873
), environment
18651874
assert description is github.GithubObject.NotSet or isinstance(
18661875
description, str
18671876
), description
1877+
assert transient_environment is github.GithubObject.NotSet or isinstance(
1878+
transient_environment, bool
1879+
), transient_environment
1880+
assert production_environment is github.GithubObject.NotSet or isinstance(
1881+
production_environment, bool
1882+
), production_environment
1883+
18681884
post_parameters = {"ref": ref}
18691885
if task is not github.GithubObject.NotSet:
18701886
post_parameters["task"] = task
@@ -1878,11 +1894,18 @@ def create_deployment(
18781894
post_parameters["environment"] = environment
18791895
if description is not github.GithubObject.NotSet:
18801896
post_parameters["description"] = description
1897+
if transient_environment is not github.GithubObject.NotSet:
1898+
post_parameters["transient_environment"] = transient_environment
1899+
if production_environment is not github.GithubObject.NotSet:
1900+
post_parameters["production_environment"] = production_environment
1901+
18811902
headers, data = self._requester.requestJsonAndCheck(
18821903
"POST",
18831904
self.url + "/deployments",
18841905
input=post_parameters,
1906+
headers={"Accept": Consts.deploymentEnhancementsPreview},
18851907
)
1908+
18861909
return github.Deployment.Deployment(
18871910
self._requester, headers, data, completed=True
18881911
)

github/Repository.pyi

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from github.Commit import Commit
99
from github.CommitComment import CommitComment
1010
from github.Comparison import Comparison
1111
from github.ContentFile import ContentFile
12+
from github.Deployment import Deployment
1213
from github.Download import Download
1314
from github.Event import Event
1415
from github.GitBlob import GitBlob
@@ -112,6 +113,18 @@ class Repository(CompletableGithubObject):
112113
output: Union[_NotSetType, Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]] = ...,
113114
actions: Union[_NotSetType, List[Dict[str, str]]] = ...,
114115
) -> CheckRun: ...
116+
def create_deployment(
117+
self,
118+
ref: str,
119+
task: Union[str, _NotSetType] = ...,
120+
auto_merge: Union[bool, _NotSetType] = ...,
121+
required_contexts: Union[List[str], _NotSetType] = ...,
122+
payload: Union[Dict[str, Any], _NotSetType] = ...,
123+
environment: Union[str, _NotSetType] = ...,
124+
description: Union[str, _NotSetType] = ...,
125+
transient_environment: Union[bool, _NotSetType] = ...,
126+
production_environment: Union[bool, _NotSetType] = ...,
127+
) -> Deployment: ...
115128
def create_file(
116129
self,
117130
path: str,
@@ -295,6 +308,14 @@ class Repository(CompletableGithubObject):
295308
def get_contributors(
296309
self, anon: Union[str, _NotSetType] = ...
297310
) -> PaginatedList[NamedUser]: ...
311+
def get_deployment(self, id_: int) -> Any: ...
312+
def get_deployments(
313+
self,
314+
sha: Union[str, _NotSetType] = ...,
315+
ref: Union[str, _NotSetType] = ...,
316+
task: Union[str, _NotSetType] = ...,
317+
environment: Union[str, _NotSetType] = ...,
318+
) -> PaginatedList[Deployment]: ...
298319
def get_dir_contents(
299320
self, path: str, ref: Union[str, _NotSetType] = ...
300321
) -> List[ContentFile]: ...

0 commit comments

Comments
 (0)