|
1
|
|
|
|
|
2
|
|
|
import time |
|
3
|
|
|
import datetime |
|
4
|
|
|
|
|
5
|
|
|
from lib.base import BaseGithubAction |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class CreateDeploymentAction(BaseGithubAction): |
|
9
|
|
|
def run(self, api_user, repository, deployment_id, state, description): |
|
10
|
|
|
|
|
11
|
|
|
valid_states = ["pending", "success", "error", "failure"] |
|
12
|
|
|
|
|
13
|
|
|
if api_user: |
|
14
|
|
|
self.token = self._get_user_token(api_user) |
|
15
|
|
|
|
|
16
|
|
|
if state not in valid_states: |
|
17
|
|
|
raise ValueError("Invalid state: {}".format(state)) |
|
18
|
|
|
|
|
19
|
|
|
payload = {"state": state, |
|
20
|
|
|
"description": description} |
|
21
|
|
|
|
|
22
|
|
|
response = self._request("POST", |
|
23
|
|
|
"/repos/{}/deployments/{}/statuses".format( |
|
24
|
|
|
repository, |
|
25
|
|
|
deployment_id), |
|
26
|
|
|
payload, |
|
27
|
|
|
self.token) |
|
28
|
|
|
|
|
29
|
|
|
ts_created_at = time.mktime( |
|
30
|
|
|
datetime.datetime.strptime( |
|
31
|
|
|
response['created_at'], |
|
32
|
|
|
"%Y-%m-%dT%H:%M:%SZ").timetuple()) |
|
33
|
|
|
|
|
34
|
|
|
ts_updated_at = time.mktime( |
|
35
|
|
|
datetime.datetime.strptime( |
|
36
|
|
|
response['updated_at'], |
|
37
|
|
|
"%Y-%m-%dT%H:%M:%SZ").timetuple()) |
|
38
|
|
|
|
|
39
|
|
|
results = {'creator': response['creator']['login'], |
|
40
|
|
|
'id': response['id'], |
|
41
|
|
|
'url': response['url'], |
|
42
|
|
|
'description': response['description'], |
|
43
|
|
|
'repository_url': response['repository_url'], |
|
44
|
|
|
'created_at': response['created_at'], |
|
45
|
|
|
'updated_at': response['updated_at'], |
|
46
|
|
|
'ts_created_at': ts_created_at, |
|
47
|
|
|
'ts_updated_at': ts_updated_at} |
|
48
|
|
|
results['response'] = response |
|
49
|
|
|
|
|
50
|
|
|
return results |
|
51
|
|
|
|