Skip to content

Commit

Permalink
Fix some missing params for gitlab repos.
Browse files Browse the repository at this point in the history
  • Loading branch information
inferno-chromium committed Dec 28, 2020
1 parent f3dbe3c commit 82b1237
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
48 changes: 20 additions & 28 deletions criticality_score/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,23 @@ def comment_frequency(self):

@property
def dependents_count(self):
raise NotImplementedError
# TODO: Take package manager dependency trees into account. If we decide
# to replace this, then find a solution for C/C++ as well.
parsed_url = urllib.parse.urlparse(self.url)
repo_name = parsed_url.path.strip('/')
dependents_url = (
f'https://github.com/search?q="{repo_name}"&type=commits')
content = b''
for i in range(FAIL_RETRIES):
result = requests.get(dependents_url)
if result.status_code == 200:
content = result.content
break
time.sleep(2**i)
match = DEPENDENTS_REGEX.match(content)
if not match:
return 0
return int(match.group(1).replace(b',', b''))


class GitHubRepository(Repository):
Expand Down Expand Up @@ -250,23 +266,6 @@ def comment_frequency(self):
since=issues_since_time).totalCount
return round(comment_count / issue_count, 1)

@property
def dependents_count(self):
repo_name = self.url.replace('https://github.com/', '')
dependents_url = (
f'https://github.com/search?q="{repo_name}"&type=commits')
content = b''
for i in range(FAIL_RETRIES):
result = requests.get(dependents_url)
if result.status_code == 200:
content = result.content
break
time.sleep(2**i)
match = DEPENDENTS_REGEX.match(content)
if not match:
return 0
return int(match.group(1).replace(b',', b''))


class GitLabRepository(Repository):
"""Source repository hosted on GitLab."""
Expand All @@ -277,11 +276,11 @@ def _date_from_string(date_string):

@property
def name(self):
return self._repo.namespace['name']
return self._repo.name

@property
def url(self):
return self._repo.namespace['web_url']
return self._repo.web_url

@property
def language(self):
Expand Down Expand Up @@ -317,7 +316,7 @@ def contributor_count(self):
def org_count(self):
# Not possible to calculate as this feature restricted to admins only.
# https://docs.gitlab.com/ee/api/users.html#user-memberships-admin-only
return 0
return 1

@property
def commit_frequency(self):
Expand Down Expand Up @@ -374,13 +373,6 @@ def comment_frequency(self):
pass
return round(comments_count / self.updated_issues_count, 1)

@property
def dependents_count(self):
# TODO: Implement this once this feature is stable and available to
# general users.
# https://docs.gitlab.com/ee/api/dependencies.html
return 0


def get_param_score(param, max_value, weight=1):
"""Return paramater score given its current value, max value and
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setuptools.setup(
name='criticality_score',
version='1.0.6',
version='1.0.7',
author='Abhishek Arya',
author_email='',
description='Gives criticality score for an open source project',
Expand Down

0 comments on commit 82b1237

Please sign in to comment.