in src/plugins/scanners/github-stats.py [0:0]
def scan(KibbletBit, source):
# Get some vars, construct a data path for the repo
path = source['sourceID']
url = source['sourceURL']
auth=None
people = {}
if 'creds' in source:
KibbleBit.pprint("Using auth for repo %s" % source['sourceURL'])
creds = source['creds']
if creds and 'username' in creds:
auth = (creds['username'], creds['password'])
else:
KibbleBit.pprint("GitHub stats requires auth, none provided. Ignoring this repo.")
return
try:
source['steps']['stats'] = {
'time': time.time(),
'status': 'Fetching statistics from source location...',
'running': True,
'good': True
}
KibbletBit.updateSource(source)
# Get views
views = plugins.utils.github.views(url, auth)
if 'views' in views:
for el in views['views']:
ts = getTime(el['timestamp'])
shash = hashlib.sha224( ("%s-%s-%s-clones" %(source['organisation'], url, el['timestamp'])).encode('ascii', errors = 'replace')).hexdigest()
bit = {
'organisation': source['organisation'],
'sourceURL': source['sourceURL'],
'sourceID': source['sourceID'],
'date': time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(ts)),
'count': el['count'],
'uniques': el['uniques'],
'ghtype': 'views',
'id': shash
}
KibbleBit.append('ghstats', bit)
# Get clones
clones = plugins.utils.github.clones(url, auth)
if 'clones' in clones:
for el in clones['clones']:
ts = getTime(el['timestamp'])
shash = hashlib.sha224( ("%s-%s-%s-clones" %(source['organisation'], url, el['timestamp'])).encode('ascii', errors = 'replace')).hexdigest()
bit = {
'organisation': source['organisation'],
'sourceURL': source['sourceURL'],
'sourceID': source['sourceID'],
'date': time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(ts)),
'count': el['count'],
'uniques': el['uniques'],
'ghtype': 'clones',
'id': shash
}
KibbleBit.append('ghstats', bit)
# Get referrers
refs = plugins.utils.github.referrers(url, auth)
if refs:
for el in refs:
el['timestamp'] = time.strftime("%Y-%m-%dT%H:%M:%S", time.time())
ts = getTime(el['timestamp'])
shash = hashlib.sha224( ("%s-%s-%s-refs" %(source['organisation'], url, el['timestamp'])).encode('ascii', errors = 'replace')).hexdigest()
bit = {
'organisation': source['organisation'],
'sourceURL': source['sourceURL'],
'sourceID': source['sourceID'],
'date': time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(ts)),
'count': el['count'],
'uniques': el['uniques'],
'ghtype': 'referrers',
'id': shash
}
KibbleBit.append('ghstats', bit)
except:
pass