|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
|
|
15
|
|
|
import time |
|
16
|
|
|
import datetime |
|
17
|
|
|
|
|
18
|
|
|
from lib.base import BaseGithubAction |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
class CreateDeploymentAction(BaseGithubAction): |
|
22
|
|
|
def run(self, api_user, repository, deployment_id, state, |
|
23
|
|
|
description, github_type): |
|
24
|
|
|
|
|
25
|
|
|
valid_states = ['pending', 'success', 'error', 'failure'] |
|
26
|
|
|
|
|
27
|
|
|
enterprise = self._is_enterprise(github_type) |
|
28
|
|
|
|
|
29
|
|
|
if api_user: |
|
30
|
|
|
self.token = self._get_user_token(api_user, |
|
31
|
|
|
enterprise) |
|
32
|
|
|
|
|
33
|
|
|
if state not in valid_states: |
|
34
|
|
|
raise ValueError("Invalid state: {}".format(state)) |
|
35
|
|
|
|
|
36
|
|
|
payload = {"state": state, |
|
37
|
|
|
"description": description} |
|
38
|
|
|
|
|
39
|
|
|
response = self._request("POST", |
|
40
|
|
|
"/repos/{}/deployments/{}/statuses".format( |
|
41
|
|
|
repository, |
|
42
|
|
|
deployment_id), |
|
43
|
|
|
payload, |
|
44
|
|
|
self.token, |
|
45
|
|
|
enterprise) |
|
46
|
|
|
|
|
47
|
|
|
ts_created_at = time.mktime( |
|
48
|
|
|
datetime.datetime.strptime( |
|
49
|
|
|
response['created_at'], |
|
50
|
|
|
"%Y-%m-%dT%H:%M:%SZ").timetuple()) |
|
51
|
|
|
|
|
52
|
|
|
ts_updated_at = time.mktime( |
|
53
|
|
|
datetime.datetime.strptime( |
|
54
|
|
|
response['updated_at'], |
|
55
|
|
|
"%Y-%m-%dT%H:%M:%SZ").timetuple()) |
|
56
|
|
|
|
|
57
|
|
|
results = {'creator': response['creator']['login'], |
|
58
|
|
|
'id': response['id'], |
|
59
|
|
|
'url': response['url'], |
|
60
|
|
|
'description': response['description'], |
|
61
|
|
|
'repository_url': response['repository_url'], |
|
62
|
|
|
'created_at': response['created_at'], |
|
63
|
|
|
'updated_at': response['updated_at'], |
|
64
|
|
|
'ts_created_at': ts_created_at, |
|
65
|
|
|
'ts_updated_at': ts_updated_at} |
|
66
|
|
|
results['response'] = response |
|
67
|
|
|
|
|
68
|
|
|
return results |
|
69
|
|
|
|