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