additions from backlog and removals because of unclear license status that could not be resolved and a bit of gitlab statistics
This commit is contained in:
41
code/utils/osg_gitlab.py
Normal file
41
code/utils/osg_gitlab.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
Everything specific to the Gitlab API (via Python GitLab https://python-gitlab.readthedocs.io/en/stable/)
|
||||
"""
|
||||
|
||||
from dateutil import parser
|
||||
from gitlab import Gitlab
|
||||
|
||||
def normalize_repo_name(repo):
|
||||
"""
|
||||
Bring repo to style xxx/yyy
|
||||
"""
|
||||
prefix = 'https://gitlab.com/'
|
||||
if repo.startswith(prefix):
|
||||
repo = repo[len(prefix):]
|
||||
suffix = '.git'
|
||||
if repo.endswith(suffix):
|
||||
repo = repo[:-len(suffix)]
|
||||
return repo
|
||||
|
||||
|
||||
def retrieve_repo_info(repos, token=None):
|
||||
"""
|
||||
|
||||
:param repos:
|
||||
:param token:
|
||||
:return:
|
||||
"""
|
||||
single_repo = isinstance(repos, str)
|
||||
if single_repo:
|
||||
repos = (repos,)
|
||||
result = []
|
||||
gl = Gitlab('https://gitlab.com')
|
||||
for repo in repos:
|
||||
repo = normalize_repo_name(repo)
|
||||
# get project
|
||||
p = gl.projects.get(repo)
|
||||
e = {'description': p.description, 'created': parser.parse(p.created_at), 'contributors': p.repository_contributors(), 'forks': p.forks_count, 'name': p.name, 'last modified': parser.parse(p.last_activity_at), 'stars': p.star_count, 'languages': p.languages()}
|
||||
result.append(e)
|
||||
if single_repo:
|
||||
result = result[0]
|
||||
return result
|
||||
Reference in New Issue
Block a user