|
1
|
|
|
import re |
|
2
|
|
|
import shlex |
|
3
|
|
|
|
|
4
|
|
|
import uritemplate |
|
|
|
|
|
|
5
|
|
|
import requests |
|
6
|
|
|
import giturlparse |
|
|
|
|
|
|
7
|
|
|
from plumbum.cmd import git |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
MERGED_PULL_REQUEST = re.compile( |
|
10
|
|
|
r'^([0-9a-f]{5,40}) Merge pull request #(\w+)' |
|
11
|
|
|
) |
|
12
|
|
|
|
|
13
|
|
|
PULL_REQUEST_API = 'https://api.github.com/repos{/owner}{/repo}/pulls{/number}' |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class PullRequest: |
|
17
|
|
|
title = None |
|
18
|
|
|
description = None |
|
19
|
|
|
author = None |
|
20
|
|
|
labels = [] |
|
21
|
|
|
|
|
22
|
|
|
def __init__(self, pr_number, committish, title, description, author): |
|
23
|
|
|
self.number = pr_number |
|
24
|
|
|
self.committish = committish |
|
25
|
|
|
self.title = title |
|
26
|
|
|
self.description = description |
|
27
|
|
|
self.author = author |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
class GitRepository: |
|
31
|
|
|
auth_token = None |
|
32
|
|
|
|
|
33
|
|
|
def __init__(self, url=None): |
|
34
|
|
|
self.parsed_repo = url or giturlparse.parse( |
|
35
|
|
|
git(shlex.split('config --get remote.origin.url')) |
|
36
|
|
|
) |
|
37
|
|
|
self.commit_history = git(shlex.split( |
|
38
|
|
|
'log --oneline --merges --no-color' |
|
39
|
|
|
)).split('\n') |
|
40
|
|
|
|
|
41
|
|
|
self.tags = git(shlex.split('tag --list')).split('\n') |
|
42
|
|
|
print(self.tags) |
|
43
|
|
|
import semantic_version |
|
|
|
|
|
|
44
|
|
|
self.versions = sorted([ |
|
45
|
|
|
semantic_version.Version(tag) |
|
46
|
|
|
for tag in self.tags |
|
47
|
|
|
if tag |
|
48
|
|
|
]) |
|
49
|
|
|
|
|
50
|
|
|
def get_pull_request(self, pr_num): |
|
51
|
|
|
return requests.get( |
|
52
|
|
|
uritemplate.expand( |
|
53
|
|
|
PULL_REQUEST_API, |
|
54
|
|
|
dict( |
|
55
|
|
|
owner=self.owner, |
|
56
|
|
|
repo=self.repo, |
|
57
|
|
|
number=pr_num |
|
58
|
|
|
), |
|
59
|
|
|
), |
|
60
|
|
|
headers={ |
|
61
|
|
|
'Authorization': 'token {}'.format(self.auth_token) |
|
62
|
|
|
}, |
|
63
|
|
|
).json() |
|
64
|
|
|
|
|
65
|
|
|
@property |
|
66
|
|
|
def pull_requests(self): |
|
67
|
|
|
pull_requests = [] |
|
68
|
|
|
|
|
69
|
|
|
for index, commit_msg in enumerate(self.commit_history): |
|
70
|
|
|
matches = MERGED_PULL_REQUEST.findall(commit_msg) |
|
71
|
|
|
if matches: |
|
72
|
|
|
committish, pr_number = matches[0] |
|
73
|
|
|
title = description = author = None |
|
74
|
|
|
if self.auth_token: |
|
75
|
|
|
pr = self.get_pull_request(pr_number) |
|
|
|
|
|
|
76
|
|
|
title = pr['title'] |
|
77
|
|
|
description = pr['body'] |
|
78
|
|
|
author = pr['user']['login'] |
|
79
|
|
|
|
|
80
|
|
|
pull_requests.append( |
|
81
|
|
|
PullRequest( |
|
82
|
|
|
pr_number, |
|
83
|
|
|
committish, |
|
84
|
|
|
title, |
|
85
|
|
|
description, |
|
86
|
|
|
author, |
|
87
|
|
|
) |
|
88
|
|
|
) |
|
89
|
|
|
|
|
90
|
|
|
return pull_requests |
|
91
|
|
|
|
|
92
|
|
|
@property |
|
93
|
|
|
def repo(self): |
|
94
|
|
|
return self.parsed_repo.repo |
|
95
|
|
|
|
|
96
|
|
|
@property |
|
97
|
|
|
def owner(self): |
|
98
|
|
|
return self.parsed_repo.owner |
|
99
|
|
|
|
|
100
|
|
|
@property |
|
101
|
|
|
def github(self): |
|
102
|
|
|
return self.parsed_repo.github |
|
103
|
|
|
|
|
104
|
|
|
@property |
|
105
|
|
|
def bitbucket(self): |
|
106
|
|
|
return self.parsed_repo.bitbucket |
|
107
|
|
|
|
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.