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 LatestReleaseAction(BaseGithubAction): |
22
|
|
|
def run(self, api_user, repository, 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
|
|
|
release = self._request("GET", |
30
|
|
|
"/repos/{}/releases/latest".format(repository), |
31
|
|
|
None, |
32
|
|
|
token=self.token, |
33
|
|
|
enterprise=enterprise) |
34
|
|
|
|
35
|
|
|
ts_published_at = time.mktime( |
36
|
|
|
datetime.datetime.strptime( |
37
|
|
|
release['published_at'], |
38
|
|
|
"%Y-%m-%dT%H:%M:%SZ").timetuple()) |
39
|
|
|
|
40
|
|
|
results = {'author': release['author']['login'], |
41
|
|
|
'avatar_url': release['author']['avatar_url'], |
42
|
|
|
'html_url': release['html_url'], |
43
|
|
|
'tag_name': release['tag_name'], |
44
|
|
|
'target_commitish': release['target_commitish'], |
45
|
|
|
'name': release['name'], |
46
|
|
|
'body': release['body'], |
47
|
|
|
'draft': release['draft'], |
48
|
|
|
'prerelease': release['prerelease'], |
49
|
|
|
'created_at': release['created_at'], |
50
|
|
|
'published_at': release['published_at'], |
51
|
|
|
'ts_published_at': ts_published_at, |
52
|
|
|
'total_assets': len(release['assets'])} |
53
|
|
|
|
54
|
|
|
return results |
55
|
|
|
|