forked from fabric8-analytics/fabric8-analytics-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibraries_io.py
54 lines (41 loc) · 1.81 KB
/
libraries_io.py
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
"""Task to collects statistics from Libraries.io."""
from operator import itemgetter
from urllib.parse import quote
from selinon import StoragePool
from f8a_worker.base import BaseTask
from f8a_worker.models import Ecosystem
from f8a_worker.utils import get_response
from f8a_worker.schemas import SchemaRef
class LibrariesIoTask(BaseTask):
"""Collects statistics from Libraries.io."""
_analysis_name = "libraries_io"
schema_ref = SchemaRef(_analysis_name, '2-0-0')
@staticmethod
def recent_releases(versions, count=10):
"""Sort versions by 'published_at' and return 'count' latest."""
return sorted(versions, key=itemgetter('published_at'))[-count:]
def execute(self, arguments):
"""Task code.
:param arguments: dictionary with task arguments
:return: {}, results
"""
self._strict_assert(arguments.get('ecosystem'))
self._strict_assert(arguments.get('name'))
rdb_session = StoragePool.get_connected_storage('BayesianPostgres').session
name = arguments['name']
ecosystem = arguments['ecosystem']
if ecosystem == 'go':
name = quote(name, safe='')
project_url = self.configuration.libraries_io_project_url(
Ecosystem.by_name(rdb_session, ecosystem), name)
project = get_response(project_url)
versions = project['versions']
details = {'dependent_repositories': {'count': project['dependent_repos_count']},
'dependents': {'count': project['dependents_count']},
'releases': {'count': len(versions),
'recent': self.recent_releases(versions)
}
}
return {'status': 'success',
'summary': [],
'details': details}