1
1
# -*- coding: utf-8 -*-
2
+ """The module containing deployment logic."""
2
3
from __future__ import unicode_literals
3
4
4
5
from .. import users
7
8
8
9
9
10
class Deployment (GitHubCore ):
11
+ """Representation of a deployment of a repository at a point in time.
10
12
11
- def _update_attributes (self , deployment ):
12
- self ._api = self ._get_attribute (deployment , 'url' )
13
+ See also: https://developer.github.com/v3/repos/deployments/
13
14
14
- #: GitHub's id of this deployment
15
- self .id = self ._get_attribute (deployment , 'id' )
15
+ This object has the following attributes:
16
16
17
- #: SHA of the branch on GitHub
18
- self .sha = self ._get_attribute (deployment , 'sha' )
17
+ .. attribute:: created_at
19
18
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.
23
21
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
28
23
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.
31
26
32
- #: Date the Deployment was created
33
- self .created_at = self ._strptime_attribute (deployment , 'created_at' )
27
+ .. attribute:: description
34
28
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`.
37
30
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'``.
40
48
41
- #: Target for the deployment, e.g., 'production', 'staging'
42
- self .environment = self ._get_attribute (deployment , 'environment' )
49
+ .. attribute:: sha
43
50
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' ])
46
75
47
76
def _repr (self ):
48
77
return '<Deployment [{0} @ {1}]>' .format (self .id , self .sha )
49
78
50
79
def create_status (self , state , target_url = None , description = None ):
51
80
"""Create a new deployment status for this deployment.
52
81
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
54
84
``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.
56
87
This URL should contain output to keep the user updated while the
57
88
task is running or serve as historical information for what
58
89
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`
61
96
"""
62
97
json = None
63
98
@@ -73,56 +108,88 @@ def create_status(self, state, target_url=None, description=None):
73
108
def statuses (self , number = - 1 , etag = None ):
74
109
"""Iterate over the deployment statuses for this deployment.
75
110
76
- :param int number: (optional), the number of statuses to return.
111
+ :param int number:
112
+ (optional), the number of statuses to return.
77
113
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
79
116
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`
81
121
"""
82
122
i = self ._iter (int (number ), self .statuses_url , DeploymentStatus ,
83
123
etag = etag )
84
124
return i
85
125
86
126
87
127
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
+ """
88
166
89
167
def _update_attributes (self , status ):
90
- self ._api = self . _get_attribute ( status , 'url' )
168
+ self ._api = status [ 'url' ]
91
169
92
170
#: GitHub's id for this deployment status
93
- self .id = self . _get_attribute ( status , 'id' )
171
+ self .id = status [ 'id' ]
94
172
95
173
#: State of the deployment status
96
- self .state = self . _get_attribute ( status , 'state' )
174
+ self .state = status [ 'state' ]
97
175
98
176
#: 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 )
105
178
106
179
#: Target URL of the deployment
107
- self .target_url = self . _get_attribute ( status , 'target_url' )
180
+ self .target_url = status [ 'target_url' ]
108
181
109
182
#: 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' ] )
111
184
112
185
#: 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' ] )
114
187
115
188
#: 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' ]
123
190
124
191
#: 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' ]
126
193
127
194
def _repr (self ):
128
195
return '<DeploymentStatus [{0}]>' .format (self .id )
0 commit comments