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