66
66
"""
67
67
68
68
import copy
69
- import hashlib
70
69
import json
71
70
import math
72
71
import re
@@ -82,34 +81,34 @@ def run(API, environ, indata, session):
82
81
now = time .time ()
83
82
84
83
# First, fetch the view if we have such a thing enabled
85
- viewList = []
84
+ view_list = []
86
85
if indata .get ("view" ):
87
- viewList = session .getView (indata .get ("view" ))
86
+ view_list = session .getView (indata .get ("view" ))
88
87
if indata .get ("subfilter" ):
89
- viewList = session .subFilter (indata .get ("subfilter" ), view = viewList )
88
+ view_list = session .subFilter (indata .get ("subfilter" ), view = view_list )
90
89
91
- dateTo = indata .get ("to" , int (time .time ()))
92
- dateFrom = indata .get (
93
- "from" , dateTo - (86400 * 30 * 6 )
90
+ date_to = indata .get ("to" , int (time .time ()))
91
+ date_from = indata .get (
92
+ "from" , date_to - (86400 * 30 * 6 )
94
93
) # Default to a 6 month span
95
94
96
- which = "committer_email"
97
- role = "committer"
98
- if indata .get ("author" , False ):
99
- which = "author_email"
100
- role = "author"
95
+ # which = "committer_email"
96
+ # role = "committer"
97
+ # if indata.get("author", False):
98
+ # which = "author_email"
99
+ # role = "author"
101
100
102
101
interval = indata .get ("interval" , "day" )
103
102
104
103
####################################################################
105
104
####################################################################
106
- dOrg = session .user ["defaultOrganisation" ] or "apache"
105
+ d_org = session .user ["defaultOrganisation" ] or "apache"
107
106
query = {
108
107
"query" : {
109
108
"bool" : {
110
109
"must" : [
111
- {"range" : {"tsday" : {"from" : dateFrom , "to" : dateTo }}},
112
- {"term" : {"organisation" : dOrg }},
110
+ {"range" : {"tsday" : {"from" : date_from , "to" : date_to }}},
111
+ {"term" : {"organisation" : d_org }},
113
112
]
114
113
}
115
114
}
@@ -119,8 +118,8 @@ def run(API, environ, indata, session):
119
118
query ["query" ]["bool" ]["must" ].append (
120
119
{"term" : {"sourceID" : indata .get ("source" )}}
121
120
)
122
- elif viewList :
123
- query ["query" ]["bool" ]["must" ].append ({"terms" : {"sourceID" : viewList }})
121
+ elif view_list :
122
+ query ["query" ]["bool" ]["must" ].append ({"terms" : {"sourceID" : view_list }})
124
123
if indata .get ("email" ):
125
124
query ["query" ]["bool" ]["must" ].append (
126
125
{
@@ -140,16 +139,15 @@ def run(API, environ, indata, session):
140
139
141
140
repos = {}
142
141
repo_commits = {}
143
- authorlinks = {}
144
142
max_commits = 0
145
143
max_links = 0
146
144
max_shared = 0
147
145
max_authors = 0
148
- minLinks = indata .get ("links" , 1 )
146
+ min_links = indata .get ("links" , 1 )
149
147
150
148
# For each repo, count commits and gather data on authors
151
149
for doc in res ["aggregations" ]["per_repo" ]["buckets" ]:
152
- sourceID = doc ["key" ]
150
+ source_id = doc ["key" ]
153
151
commits = doc ["doc_count" ]
154
152
155
153
# Gather the unique authors/committers
@@ -164,7 +162,7 @@ def run(API, environ, indata, session):
164
162
}
165
163
}
166
164
xquery = copy .deepcopy (query )
167
- xquery ["query" ]["bool" ]["must" ].append ({"term" : {"sourceID" : sourceID }})
165
+ xquery ["query" ]["bool" ]["must" ].append ({"term" : {"sourceID" : source_id }})
168
166
xres = session .DB .ES .search (
169
167
index = session .DB .dbname , doc_type = "code_commit" , size = 0 , body = xquery
170
168
)
@@ -173,8 +171,8 @@ def run(API, environ, indata, session):
173
171
authors .append (person ["key" ])
174
172
if commits > max_commits :
175
173
max_commits = commits
176
- repos [sourceID ] = authors
177
- repo_commits [sourceID ] = commits
174
+ repos [source_id ] = authors
175
+ repo_commits [source_id ] = commits
178
176
179
177
# Now, figure out which repos share the same contributors
180
178
repo_links = {}
@@ -184,7 +182,6 @@ def run(API, environ, indata, session):
184
182
185
183
# Grab data of all sources
186
184
for ID , repo in repos .items ():
187
- mylinks = {}
188
185
if not session .DB .ES .exists (index = session .DB .dbname , doc_type = "source" , id = ID ):
189
186
continue
190
187
repodatas [ID ] = session .DB .ES .get (
@@ -193,7 +190,7 @@ def run(API, environ, indata, session):
193
190
194
191
for ID , repo in repos .items ():
195
192
mylinks = {}
196
- if not ID in repodatas :
193
+ if ID not in repodatas :
197
194
continue
198
195
repodata = repodatas [ID ]
199
196
oID = ID
@@ -221,7 +218,7 @@ def run(API, environ, indata, session):
221
218
xlinks .append (author )
222
219
lname = "%s@%s" % (ID , xID ) # Link name
223
220
rname = "%s@%s" % (xID , ID ) # Reverse link name
224
- if len (xlinks ) >= minLinks and not rname in repo_links :
221
+ if len (xlinks ) >= min_links and not rname in repo_links :
225
222
mylinks [xID ] = len (xlinks )
226
223
repo_links [lname ] = repo_links .get (lname , 0 ) + len (
227
224
xlinks
@@ -255,25 +252,25 @@ def run(API, environ, indata, session):
255
252
nodes = []
256
253
links = []
257
254
existing_repos = []
258
- for sourceID in repo_notoriety . keys () :
255
+ for source_id in repo_notoriety :
259
256
lsize = 0
260
- for k in repo_links . keys () :
257
+ for k in repo_links :
261
258
fr , to = k .split ("@" )
262
- if fr == sourceID or to == sourceID :
259
+ if source_id in ( fr , to ) :
263
260
lsize += 1
264
- asize = len (repo_authors [sourceID ])
261
+ asize = len (repo_authors [source_id ])
265
262
doc = {
266
- "id" : sourceID ,
267
- "name" : sourceID ,
268
- "commits" : repo_commits [sourceID ],
263
+ "id" : source_id ,
264
+ "name" : source_id ,
265
+ "commits" : repo_commits [source_id ],
269
266
"authors" : asize ,
270
267
"links" : lsize ,
271
268
"size" : max (5 , (1 - abs (math .log10 (asize / max_authors ))) * 45 ),
272
269
"tooltip" : "%u connections, %u contributors, %u commits"
273
- % (lsize , asize , repo_commits [sourceID ]),
270
+ % (lsize , asize , repo_commits [source_id ]),
274
271
}
275
272
nodes .append (doc )
276
- existing_repos .append (sourceID )
273
+ existing_repos .append (source_id )
277
274
278
275
for k , s in repo_links .items ():
279
276
size = s
0 commit comments