Skip to content

Commit 82b1237

Browse files
Fix some missing params for gitlab repos.
1 parent f3dbe3c commit 82b1237

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

criticality_score/run.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,23 @@ def comment_frequency(self):
9696

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

101117

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

253-
@property
254-
def dependents_count(self):
255-
repo_name = self.url.replace('https://github.com/', '')
256-
dependents_url = (
257-
f'https://github.com/search?q="{repo_name}"&type=commits')
258-
content = b''
259-
for i in range(FAIL_RETRIES):
260-
result = requests.get(dependents_url)
261-
if result.status_code == 200:
262-
content = result.content
263-
break
264-
time.sleep(2**i)
265-
match = DEPENDENTS_REGEX.match(content)
266-
if not match:
267-
return 0
268-
return int(match.group(1).replace(b',', b''))
269-
270269

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

278277
@property
279278
def name(self):
280-
return self._repo.namespace['name']
279+
return self._repo.name
281280

282281
@property
283282
def url(self):
284-
return self._repo.namespace['web_url']
283+
return self._repo.web_url
285284

286285
@property
287286
def language(self):
@@ -317,7 +316,7 @@ def contributor_count(self):
317316
def org_count(self):
318317
# Not possible to calculate as this feature restricted to admins only.
319318
# https://docs.gitlab.com/ee/api/users.html#user-memberships-admin-only
320-
return 0
319+
return 1
321320

322321
@property
323322
def commit_frequency(self):
@@ -374,13 +373,6 @@ def comment_frequency(self):
374373
pass
375374
return round(comments_count / self.updated_issues_count, 1)
376375

377-
@property
378-
def dependents_count(self):
379-
# TODO: Implement this once this feature is stable and available to
380-
# general users.
381-
# https://docs.gitlab.com/ee/api/dependencies.html
382-
return 0
383-
384376

385377
def get_param_score(param, max_value, weight=1):
386378
"""Return paramater score given its current value, max value and

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setuptools.setup(
2121
name='criticality_score',
22-
version='1.0.6',
22+
version='1.0.7',
2323
author='Abhishek Arya',
2424
author_email='',
2525
description='Gives criticality score for an open source project',

0 commit comments

Comments
 (0)