|
1
|
|
|
import attr |
|
|
|
|
|
|
2
|
|
|
import requests |
|
3
|
|
|
import uritemplate |
|
|
|
|
|
|
4
|
|
|
from pathlib import Path |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
EXT_TO_MIME_TYPE = { |
|
8
|
|
|
'.gz': 'application/x-gzip', |
|
9
|
|
|
'.whl': 'application/zip', |
|
10
|
|
|
'.zip': 'application/zip', |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
@attr.s |
|
15
|
|
|
class GitHub(object): |
|
16
|
|
|
ISSUE_ENDPOINT = ( |
|
17
|
|
|
'https://api.github.com/repos{/owner}{/repo}/issues{/number}' |
|
18
|
|
|
) |
|
19
|
|
|
LABELS_ENDPOINT = ( |
|
20
|
|
|
'https://api.github.com/repos{/owner}{/repo}/labels' |
|
21
|
|
|
) |
|
22
|
|
|
RELEASES_ENDPOINT = ( |
|
23
|
|
|
'https://api.github.com/repos{/owner}{/repo}/releases' |
|
24
|
|
|
) |
|
25
|
|
|
|
|
26
|
|
|
repository = attr.ib() |
|
27
|
|
|
release = attr.ib() |
|
28
|
|
|
|
|
29
|
|
|
@property |
|
30
|
|
|
def owner(self): |
|
31
|
|
|
return self.repository.owner |
|
32
|
|
|
|
|
33
|
|
|
@property |
|
34
|
|
|
def repo(self): |
|
35
|
|
|
return self.repository.repo |
|
36
|
|
|
|
|
37
|
|
|
@property |
|
38
|
|
|
def auth_token(self): |
|
39
|
|
|
return self.repository.auth_token |
|
40
|
|
|
|
|
41
|
|
|
def pull_request(self, pr_num): |
|
42
|
|
|
pull_request_api_url = uritemplate.expand( |
|
43
|
|
|
self.ISSUE_ENDPOINT, |
|
44
|
|
|
dict( |
|
45
|
|
|
owner=self.owner, |
|
46
|
|
|
repo=self.repo, |
|
47
|
|
|
number=pr_num |
|
48
|
|
|
), |
|
49
|
|
|
) |
|
50
|
|
|
|
|
51
|
|
|
return requests.get( |
|
52
|
|
|
pull_request_api_url, |
|
53
|
|
|
headers={ |
|
54
|
|
|
'Authorization': 'token {}'.format(self.auth_token) |
|
55
|
|
|
}, |
|
56
|
|
|
).json() |
|
57
|
|
|
|
|
58
|
|
|
def labels(self): |
|
59
|
|
|
labels_api_url = uritemplate.expand( |
|
60
|
|
|
self.LABELS_ENDPOINT, |
|
61
|
|
|
dict( |
|
62
|
|
|
owner=self.owner, |
|
63
|
|
|
repo=self.repo, |
|
64
|
|
|
), |
|
65
|
|
|
) |
|
66
|
|
|
|
|
67
|
|
|
return requests.get( |
|
68
|
|
|
labels_api_url, |
|
69
|
|
|
headers={ |
|
70
|
|
|
'Authorization': 'token {}'.format(self.auth_token) |
|
71
|
|
|
}, |
|
72
|
|
|
).json() |
|
73
|
|
|
|
|
74
|
|
|
def create_release(self, uploads=None): |
|
75
|
|
|
params = { |
|
76
|
|
|
'tag_name': self.release.version, |
|
77
|
|
|
'name': self.release.name, |
|
78
|
|
|
'body': self.release.description, |
|
79
|
|
|
# 'prerelease': True, |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
releases_api_url = uritemplate.expand( |
|
83
|
|
|
self.RELEASES_ENDPOINT, |
|
84
|
|
|
dict( |
|
85
|
|
|
owner=self.owner, |
|
86
|
|
|
repo=self.repo, |
|
87
|
|
|
) |
|
88
|
|
|
) |
|
89
|
|
|
|
|
90
|
|
|
return requests.post( |
|
91
|
|
|
releases_api_url, |
|
92
|
|
|
headers={ |
|
93
|
|
|
'Authorization': 'token {}'.format(self.auth_token) |
|
94
|
|
|
}, |
|
95
|
|
|
# auth=(self.auth_token, 'x-oauth-basic'), |
|
96
|
|
|
json=params, |
|
97
|
|
|
).json() |
|
98
|
|
|
|
|
99
|
|
|
upload_responses = [] |
|
100
|
|
|
upload_url = response['upload_url'] |
|
|
|
|
|
|
101
|
|
|
for upload in uploads: |
|
102
|
|
|
upload = Path(upload) |
|
103
|
|
|
upload_responses.append(requests.post( |
|
104
|
|
|
uritemplate.expand( |
|
105
|
|
|
upload_url, |
|
106
|
|
|
dict(name=upload.name) |
|
107
|
|
|
), |
|
108
|
|
|
# auth=(gh_token, 'x-oauth-basic'), |
|
109
|
|
|
headers={ |
|
110
|
|
|
'authorization': 'token {}'.format(self.auth_token), |
|
111
|
|
|
'content-type': EXT_TO_MIME_TYPE[distribution.ext], |
|
|
|
|
|
|
112
|
|
|
}, |
|
113
|
|
|
data=upload.read_bytes(), |
|
|
|
|
|
|
114
|
|
|
verify=False, |
|
115
|
|
|
)) |
|
116
|
|
|
|
|
117
|
|
|
return response, upload_responses |
|
|
|
|
|
|
118
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.