-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdevNetwork.py
More file actions
205 lines (160 loc) · 5.9 KB
/
Copy pathdevNetwork.py
File metadata and controls
205 lines (160 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import sys
import os
import subprocess
import shutil
import stat
import git
import pkg_resources
import sentistrength
from configuration import parseDevNetworkArgs
from repoLoader import getRepo
from aliasWorker import replaceAliases
from commitAnalysis import commitAnalysis
import centralityAnalysis as centrality
from tagAnalysis import tagAnalysis
from devAnalysis import devAnalysis
from graphqlAnalysis.releaseAnalysis import releaseAnalysis
from graphqlAnalysis.prAnalysis import prAnalysis
from graphqlAnalysis.issueAnalysis import issueAnalysis
from smellDetection import smellDetection
from politenessAnalysis import politenessAnalysis
from dateutil.relativedelta import relativedelta
FILEBROWSER_PATH = os.path.join(os.getenv("WINDIR"), "explorer.exe")
def main(argv):
try:
# validate running in venv
if not hasattr(sys, "prefix"):
raise Exception(
"The tool does not appear to be running in the virtual environment!\nSee README for activation."
)
# validate python version
if sys.version_info.major != 3 or sys.version_info.minor != 8:
raise Exception(
"Expected Python 3.8 as runtime but got {0}.{1}, the tool might not run as expected!\nSee README for stack requirements.".format(
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro,
)
)
# validate installed modules
required = {
"wheel",
"networkx",
"pandas",
"matplotlib",
"gitpython",
"requests",
"pyyaml",
"progress",
"strsimpy",
"python-dateutil",
"sentistrength",
"joblib",
}
installed = {pkg for pkg in pkg_resources.working_set.by_key}
missing = required - installed
if len(missing) > 0:
raise Exception(
"Missing required modules: {0}.\nSee README for tool installation.".format(
missing
)
)
# parse args
config = parseDevNetworkArgs(sys.argv)
# prepare folders
if os.path.exists(config.resultsPath):
remove_tree(config.resultsPath)
os.makedirs(config.metricsPath)
# get repository reference
repo = getRepo(config)
# setup sentiment analysis
senti = sentistrength.PySentiStr()
sentiJarPath = os.path.join(config.sentiStrengthPath, "SentiStrength.jar").replace("\\", "/")
senti.setSentiStrengthPath(sentiJarPath)
sentiDataPath = os.path.join(config.sentiStrengthPath, "SentiStrength_Data").replace("\\", "/") + "/"
senti.setSentiStrengthLanguageFolderPath(sentiDataPath)
# prepare batch delta
delta = relativedelta(months=+config.batchMonths)
# handle aliases
commits = list(replaceAliases(repo.iter_commits(), config))
# run analysis
batchDates, authorInfoDict, daysActive = commitAnalysis(
senti, commits, delta, config
)
tagAnalysis(repo, delta, batchDates, daysActive, config)
coreDevs = centrality.centralityAnalysis(commits, delta, batchDates, config)
releaseAnalysis(commits, config, delta, batchDates)
prParticipantBatches, prCommentBatches = prAnalysis(
config,
senti,
delta,
batchDates,
)
issueParticipantBatches, issueCommentBatches = issueAnalysis(
config,
senti,
delta,
batchDates,
)
politenessAnalysis(config, prCommentBatches, issueCommentBatches)
for batchIdx, batchDate in enumerate(batchDates):
# get combined author lists
combinedAuthorsInBatch = (
prParticipantBatches[batchIdx] + issueParticipantBatches[batchIdx]
)
# build combined network
centrality.buildGraphQlNetwork(
batchIdx,
combinedAuthorsInBatch,
"issuesAndPRsCentrality",
config,
)
# get combined unique authors for both PRs and issues
uniqueAuthorsInPrBatch = set(
author for pr in prParticipantBatches[batchIdx] for author in pr
)
uniqueAuthorsInIssueBatch = set(
author for pr in issueParticipantBatches[batchIdx] for author in pr
)
uniqueAuthorsInBatch = uniqueAuthorsInPrBatch.union(
uniqueAuthorsInIssueBatch
)
# get batch core team
batchCoreDevs = coreDevs[batchIdx]
# run dev analysis
devAnalysis(
authorInfoDict,
batchIdx,
uniqueAuthorsInBatch,
batchCoreDevs,
config,
)
# run smell detection
smellDetection(config, batchIdx)
finally:
# close repo to avoid resource leaks
if "repo" in locals():
del repo
class Progress(git.remote.RemoteProgress):
def update(self, op_code, cur_count, max_count=None, message=""):
print(self._cur_line, end="\r")
def commitDate(tag):
return tag.commit.committed_date
def remove_readonly(fn, path, excinfo):
os.chmod(path, stat.S_IWRITE)
remove_tree(path)
def remove_tree(path):
if os.path.isdir(path):
shutil.rmtree(path, onerror=remove_readonly)
else:
os.remove(path)
# https://stackoverflow.com/a/50965628
def explore(path):
# explorer would choke on forward slashes
path = os.path.normpath(path)
if os.path.isdir(path):
subprocess.run([FILEBROWSER_PATH, path])
elif os.path.isfile(path):
subprocess.run([FILEBROWSER_PATH, "/select,", os.path.normpath(path)])
if __name__ == "__main__":
main(sys.argv[1:])