Completed
Push — master ( 2f8f24...c1b989 )
by Tomaz
28s
created

GetDeploymentStatusesAction.run()   B

Complexity

Conditions 3

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 33
rs 8.8571
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 GetDeploymentStatusesAction(BaseGithubAction):
22
    def run(self, api_user, repository, deployment_id, github_type):
23
24
        enterprise = self._is_enterprise(github_type)
25
26
        if api_user:
27
            self.token = self._get_user_token(api_user, enterprise)
28
29
        payload = {"id": deployment_id}
30
31
        responses = self._request("GET",
32
                                  "/repos/{}/deployments/{}/statuses".format(
33
                                      repository, deployment_id),
34
                                  payload,
35
                                  self.token,
36
                                  enterprise)
37
38
        results = []
39
        for response in responses:
40
            ts_created_at = time.mktime(
41
                datetime.datetime.strptime(
42
                    response['created_at'],
43
                    "%Y-%m-%dT%H:%M:%SZ").timetuple())
44
45
            results.append({'creator': response['creator']['login'],
46
                            'id': response['id'],
47
                            'description': response['description'],
48
                            'state': response['state'],
49
                            'target_url': response['target_url'],
50
                            'created_at': response['created_at'],
51
                            'updated_at': response['updated_at'],
52
                            'ts_created_at': ts_created_at})
53
54
        return results
55