Skip to content

Commit 2b4594c

Browse files
committed
Update github3.repos.deployment for consistency
1 parent 5aa47f1 commit 2b4594c

File tree

1 file changed

+119
-52
lines changed

1 file changed

+119
-52
lines changed

github3/repos/deployment.py

+119-52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
"""The module containing deployment logic."""
23
from __future__ import unicode_literals
34

45
from .. import users
@@ -7,57 +8,91 @@
78

89

910
class Deployment(GitHubCore):
11+
"""Representation of a deployment of a repository at a point in time.
1012
11-
def _update_attributes(self, deployment):
12-
self._api = self._get_attribute(deployment, 'url')
13+
See also: https://developer.github.com/v3/repos/deployments/
1314
14-
#: GitHub's id of this deployment
15-
self.id = self._get_attribute(deployment, 'id')
15+
This object has the following attributes:
1616
17-
#: SHA of the branch on GitHub
18-
self.sha = self._get_attribute(deployment, 'sha')
17+
.. attribute:: created_at
1918
20-
#: The reference used to create the Deployment, e.g.,
21-
#: `deploy-20140526`
22-
self.ref = self._get_attribute(deployment, 'ref')
19+
A :class:`~datetime.datetime` representing the date and time when this
20+
deployment was created.
2321
24-
#: User object representing the creator of the deployment
25-
self.creator = self._class_attribute(
26-
deployment, 'creator', users.ShortUser, self
27-
)
22+
.. attribute:: creator
2823
29-
#: JSON string payload of the Deployment
30-
self.payload = self._get_attribute(deployment, 'payload')
24+
A :class:`~github3.users.ShortUser` representing the user who created
25+
this deployment.
3126
32-
#: Date the Deployment was created
33-
self.created_at = self._strptime_attribute(deployment, 'created_at')
27+
.. attribute:: description
3428
35-
#: Date the Deployment was updated
36-
self.updated_at = self._strptime_attribute(deployment, 'updated_at')
29+
The description of this deployment as provided by the :attr:`creator`.
3730
38-
#: Description of the deployment
39-
self.description = self._get_attribute(deployment, 'description')
31+
.. attribute:: environment
32+
33+
The environment targeted for this deployment, e.g., ``'production'``,
34+
``'staging'``.
35+
36+
.. attribute:: id
37+
38+
The unique identifier of this deployment.
39+
40+
.. attribute:: payload
41+
42+
The JSON payload string sent as part to trigger this deployment.
43+
44+
.. attribute:: ref
45+
46+
The reference used to create this deployment, e.g.,
47+
``'deploy-20140526'``.
4048
41-
#: Target for the deployment, e.g., 'production', 'staging'
42-
self.environment = self._get_attribute(deployment, 'environment')
49+
.. attribute:: sha
4350
44-
#: URL to get the statuses of this deployment
45-
self.statuses_url = self._get_attribute(deployment, 'statuses_url')
51+
The SHA1 of the branch on GitHub when it was deployed.
52+
53+
.. attribute:: statuses_url
54+
55+
The URL to retrieve the statuses of this deployment from the API.
56+
57+
.. attribute:: updated_at
58+
59+
A :class:`~datetime.datetime` object representing the date and time
60+
when this deployment was most recently updated.
61+
"""
62+
63+
def _update_attributes(self, deployment):
64+
self._api = deployment['url']
65+
self.created_at = self._strptime(deployment['created_at'])
66+
self.creator = users.ShortUser(deployment['creator'], self)
67+
self.description = deployment['description']
68+
self.environment = deployment['environment']
69+
self.id = deployment['id']
70+
self.payload = deployment['payload']
71+
self.ref = deployment['ref']
72+
self.sha = deployment['sha']
73+
self.statuses_url = deployment['statuses_url']
74+
self.updated_at = self._strptime(deployment['updated_at'])
4675

4776
def _repr(self):
4877
return '<Deployment [{0} @ {1}]>'.format(self.id, self.sha)
4978

5079
def create_status(self, state, target_url=None, description=None):
5180
"""Create a new deployment status for this deployment.
5281
53-
:param str state: (required), The state of the status. Can be one of
82+
:param str state:
83+
(required), The state of the status. Can be one of
5484
``pending``, ``success``, ``error``, or ``failure``.
55-
:param str target_url: The target URL to associate with this status.
85+
:param str target_url:
86+
The target URL to associate with this status.
5687
This URL should contain output to keep the user updated while the
5788
task is running or serve as historical information for what
5889
happened in the deployment. Default: ''.
59-
:param str description: A short description of the status. Default: ''.
60-
:return: partial :class:`DeploymentStatus <DeploymentStatus>`
90+
:param str description:
91+
A short description of the status. Default: ''.
92+
:return:
93+
the incomplete deployment status
94+
:rtype:
95+
:class:`~github3.repos.deployment.DeploymentStatus`
6196
"""
6297
json = None
6398

@@ -73,56 +108,88 @@ def create_status(self, state, target_url=None, description=None):
73108
def statuses(self, number=-1, etag=None):
74109
"""Iterate over the deployment statuses for this deployment.
75110
76-
:param int number: (optional), the number of statuses to return.
111+
:param int number:
112+
(optional), the number of statuses to return.
77113
Default: -1, returns all statuses.
78-
:param str etag: (optional), the ETag header value from the last time
114+
:param str etag:
115+
(optional), the ETag header value from the last time
79116
you iterated over the statuses.
80-
:returns: generator of :class:`DeploymentStatus`\ es
117+
:returns:
118+
generator of the statuses of this deployment
119+
:rtype:
120+
:class:`~github3.repos.deployment.DeploymentStatus`
81121
"""
82122
i = self._iter(int(number), self.statuses_url, DeploymentStatus,
83123
etag=etag)
84124
return i
85125

86126

87127
class DeploymentStatus(GitHubCore):
128+
"""Representation of the status of a deployment of a repository.
129+
130+
See also
131+
https://developer.github.com/v3/repos/deployments/#get-a-single-deployment-status
132+
133+
This object has the following attributes:
134+
135+
.. attribute:: created_at
136+
137+
A :class:`~datetime.datetime` representing the date and time when this
138+
deployment status was created.
139+
140+
.. attribute:: creator
141+
142+
A :class:`~github3.users.ShortUser` representing the user who created
143+
this deployment status.
144+
145+
.. attribute:: deployment_url
146+
147+
The URL to retrieve the information about the deployment from the API.
148+
149+
.. attribute:: description
150+
151+
The description of this status as provided by the :attr:`creator`.
152+
153+
.. attribute:: id
154+
155+
The unique identifier of this deployment.
156+
157+
.. attribute:: state
158+
159+
The state of the deployment, e.g., ``'success'``.
160+
161+
.. attribute:: target_url
162+
163+
The URL to associate with this status. This should link to the output
164+
of the deployment.
165+
"""
88166

89167
def _update_attributes(self, status):
90-
self._api = self._get_attribute(status, 'url')
168+
self._api = status['url']
91169

92170
#: GitHub's id for this deployment status
93-
self.id = self._get_attribute(status, 'id')
171+
self.id = status['id']
94172

95173
#: State of the deployment status
96-
self.state = self._get_attribute(status, 'state')
174+
self.state = status['state']
97175

98176
#: Creater of the deployment status
99-
self.creator = self._class_attribute(
100-
status, 'creator', users.ShortUser, self
101-
)
102-
103-
#: JSON payload as a string
104-
self.payload = self._get_attribute(status, 'payload', {})
177+
self.creator = users.ShortUser(status['creator'], self)
105178

106179
#: Target URL of the deployment
107-
self.target_url = self._get_attribute(status, 'target_url')
180+
self.target_url = status['target_url']
108181

109182
#: Date the deployment status was created
110-
self.created_at = self._strptime_attribute(status, 'created_at')
183+
self.created_at = self._strptime(status['created_at'])
111184

112185
#: Date the deployment status was updated
113-
self.updated_at = self._strptime_attribute(status, 'updated_at')
186+
self.updated_at = self._strptime(status['updated_at'])
114187

115188
#: Description of the deployment
116-
self.description = self._get_attribute(status, 'description')
117-
118-
#: :class:`Deployment` representing the deployment this status is
119-
#: associated with
120-
self.deployment = self._class_attribute(
121-
status, 'deployment', Deployment, self
122-
)
189+
self.description = status['description']
123190

124191
#: URL for the deployment this status is associated with
125-
self.deployment_url = self._get_attribute(status, 'deployment_url')
192+
self.deployment_url = status['deployment_url']
126193

127194
def _repr(self):
128195
return '<DeploymentStatus [{0}]>'.format(self.id)

0 commit comments

Comments
 (0)