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}/issues{/number}' |
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class PullRequest: |
18
|
|
|
title = None |
19
|
|
|
description = None |
20
|
|
|
author = None |
21
|
|
|
labels = [] |
22
|
|
|
|
23
|
|
|
def __init__(self, **kwargs): |
24
|
|
|
# github |
25
|
|
|
self.number = kwargs['number'] |
26
|
|
|
self.title = kwargs['title'] |
27
|
|
|
self.description = kwargs['body'] |
28
|
|
|
self.author = kwargs['user']['login'] |
29
|
|
|
self.labels = [ |
30
|
|
|
label['name'] |
31
|
|
|
for label in kwargs['labels'] |
32
|
|
|
] |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class GitRepository: |
36
|
|
|
auth_token = None |
37
|
|
|
|
38
|
|
|
def __init__(self, url=None): |
39
|
|
|
self.parsed_repo = ( |
40
|
|
|
url or |
41
|
|
|
# TODO: handle multiple remotes (cookiecutter [non-owner maintainer]) |
|
|
|
|
42
|
|
|
# giturlparse.parse( |
43
|
|
|
# git(shlex.split('config --get remote.upstream.url')) |
44
|
|
|
# ) or |
45
|
|
|
giturlparse.parse( |
46
|
|
|
git(shlex.split('config --get remote.origin.url')) |
47
|
|
|
) |
48
|
|
|
) |
49
|
|
|
self.commit_history = [ |
50
|
|
|
commit_message |
51
|
|
|
for commit_message in git(shlex.split( |
52
|
|
|
'log --oneline --no-color' |
53
|
|
|
)).split('\n') |
54
|
|
|
if commit_message |
55
|
|
|
] |
56
|
|
|
|
57
|
|
|
self.first_commit_sha = git( |
58
|
|
|
'rev-list', '--max-parents=0', 'HEAD' |
59
|
|
|
) |
60
|
|
|
self.tags = git(shlex.split('tag --list')).split('\n') |
61
|
|
|
|
62
|
|
|
@property |
63
|
|
|
def versions(self): |
64
|
|
|
versions = [] |
65
|
|
|
for tag in self.tags: |
66
|
|
|
try: |
67
|
|
|
versions.append(semantic_version.Version(tag)) |
68
|
|
|
except ValueError: |
69
|
|
|
pass |
70
|
|
|
return versions |
71
|
|
|
|
72
|
|
|
@property |
73
|
|
|
def latest_version(self) -> semantic_version.Version: |
74
|
|
|
return max(self.versions) if self.versions else semantic_version.Version('0.0.0') |
|
|
|
|
75
|
|
|
|
76
|
|
|
def merges_since(self, version=None): |
77
|
|
|
print('merged since') |
78
|
|
|
print(version) |
79
|
|
|
|
80
|
|
|
if version == semantic_version.Version('0.0.0'): |
81
|
|
|
print('not a real version') |
82
|
|
|
# version = self.first_commit_sha |
83
|
|
|
|
84
|
|
|
revision_range = ' {}..HEAD'.format(version) if version else '' |
85
|
|
|
|
86
|
|
|
merge_commits = git(shlex.split( |
87
|
|
|
'log --oneline --merges --no-color{}'.format(revision_range) |
88
|
|
|
)).split('\n') |
89
|
|
|
return merge_commits |
90
|
|
|
|
91
|
|
|
# TODO: pull_requests_since(version=None) |
92
|
|
|
@property |
93
|
|
|
def changes_since_last_version(self): |
94
|
|
|
pull_requests = [] |
95
|
|
|
|
96
|
|
|
for index, commit_msg in enumerate(self.merges_since(self.latest_version)): |
|
|
|
|
97
|
|
|
matches = MERGED_PULL_REQUEST.findall(commit_msg) |
98
|
|
|
|
99
|
|
|
if matches: |
100
|
|
|
_, pull_request_number = matches[0] |
101
|
|
|
|
102
|
|
|
pr = self.get_pull_request(pull_request_number) |
|
|
|
|
103
|
|
|
pull_requests.append( |
104
|
|
|
PullRequest( |
105
|
|
|
**pr |
106
|
|
|
) |
107
|
|
|
) |
108
|
|
|
return pull_requests |
109
|
|
|
|
110
|
|
|
# github api |
111
|
|
|
def get_pull_request(self, pr_num): |
112
|
|
|
return requests.get( |
113
|
|
|
uritemplate.expand( |
114
|
|
|
PULL_REQUEST_API, |
115
|
|
|
dict( |
116
|
|
|
owner=self.owner, |
117
|
|
|
repo=self.repo, |
118
|
|
|
number=pr_num |
119
|
|
|
), |
120
|
|
|
), |
121
|
|
|
headers={ |
122
|
|
|
'Authorization': 'token {}'.format(self.auth_token) |
123
|
|
|
}, |
124
|
|
|
).json() |
125
|
|
|
|
126
|
|
|
@property |
127
|
|
|
def repo(self): |
128
|
|
|
return self.parsed_repo.repo |
129
|
|
|
|
130
|
|
|
@property |
131
|
|
|
def owner(self): |
132
|
|
|
return self.parsed_repo.owner |
133
|
|
|
|
134
|
|
|
@property |
135
|
|
|
def github(self): |
136
|
|
|
return self.parsed_repo.github |
137
|
|
|
|
138
|
|
|
@property |
139
|
|
|
def bitbucket(self): |
140
|
|
|
return self.parsed_repo.bitbucket |
141
|
|
|
|
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.