-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dockerfile and refactoring -> 0.3.0
- Loading branch information
1 parent
73a3734
commit f98cb1e
Showing
8 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.8-buster | ||
|
||
MAINTAINER Stefano Dalla Palma | ||
|
||
RUN python3.8 -m pip install --upgrade pip | ||
|
||
COPY . /app | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
ENTRYPOINT ["python3.8", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import json | ||
import sys | ||
from reposcorer.scorer import score_repository | ||
|
||
if __name__ == '__main__': | ||
scores = score_repository(sys.argv[1], sys.argv[2], sys.argv[3]) | ||
print(json.dumps(scores)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,60 @@ | ||
import git | ||
import os | ||
|
||
from typing import Union | ||
|
||
from .attributes.community import core_contributors | ||
from .attributes.continuous_integration import has_continuous_integration | ||
from .attributes.history import commit_frequency | ||
from .attributes.iac import iac_ratio | ||
from .attributes.issues import github_issue_event_frequency, gitlab_issue_event_frequency | ||
from .attributes.licensing import has_license | ||
from .attributes.loc_info import loc_info | ||
from reposcorer.attributes.community import core_contributors | ||
from reposcorer.attributes.continuous_integration import has_continuous_integration | ||
from reposcorer.attributes.history import commit_frequency | ||
from reposcorer.attributes.iac import iac_ratio | ||
from reposcorer.attributes.issues import github_issue_event_frequency, gitlab_issue_event_frequency | ||
from reposcorer.attributes.licensing import has_license | ||
from reposcorer.attributes.loc_info import loc_info | ||
|
||
|
||
def score_repository(path_to_repo: str, | ||
full_name_or_id: Union[str, int], | ||
host: str): | ||
def score_repository(host: str, | ||
full_name: Union[str, int], | ||
clone_to: str,): | ||
""" | ||
Score a repository to identify well-engineered projects. | ||
:param path_to_repo: path to the local repository | ||
:param access_token: Github access token | ||
:param full_name_or_id: the full name of a repository or its id (e.g., radon-h2020/radon-repository-scorer) | ||
:param host: the SVM hosting platform. That is, github or gitlab | ||
:param full_name: the full name of a repository (e.g., radon-h2020/radon-repository-scorer) | ||
:param clone_to: directory to clone the repository | ||
:return: a dictionary with a score for every indicator | ||
""" | ||
|
||
issues = 0 | ||
if host == 'github': | ||
issues = github_issue_event_frequency(full_name_or_id) | ||
issues = github_issue_event_frequency(full_name) | ||
|
||
if not os.path.isdir(full_name): | ||
git.Git(clone_to).clone(f'https://github.com/{full_name}.git') | ||
|
||
elif host == 'gitlab': | ||
issues = gitlab_issue_event_frequency(full_name_or_id) | ||
issues = gitlab_issue_event_frequency(full_name) | ||
if not os.path.isdir(full_name): | ||
git.Git(clone_to).clone(f'https://github.com/{full_name}.git') | ||
else: | ||
raise ValueError(f'{host} not supported. Please select github or gitlab') | ||
|
||
path_to_repo = os.path.join(clone_to, full_name.split('/')[-1]) | ||
|
||
history = commit_frequency(path_to_repo) | ||
community = core_contributors(path_to_repo) | ||
ci = has_continuous_integration(path_to_repo) | ||
license = has_license(path_to_repo) | ||
license_ = has_license(path_to_repo) | ||
cloc, sloc = loc_info(path_to_repo) | ||
ratio_comments = cloc / (cloc + sloc) if (cloc + sloc) != 0 else 0 | ||
ratio_iac = iac_ratio(path_to_repo) | ||
|
||
return { | ||
'continuous_integration': ci, | ||
'percent_comment': round(ratio_comments, 4), | ||
'has_ci': ci, | ||
'comments_ratio': round(ratio_comments, 4), | ||
'commit_frequency': round(history, 2), | ||
'core_contributors': community, | ||
'iac_ratio': round(ratio_iac, 4), | ||
'issue_frequency': round(issues, 2), | ||
'license': license, | ||
'has_license': license_, | ||
'repository_size': sloc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
GitPython~=3.1.11 | ||
python-dotenv~=0.14.0 | ||
PyDriller~=1.15.2 | ||
PyGithub~=1.53 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import shutil | ||
import unittest | ||
|
||
from dotenv import load_dotenv | ||
from reposcorer.scorer import score_repository | ||
|
||
|
||
class AttributesTestCase(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
load_dotenv() | ||
cls.tmp_dir = os.path.join('test_data', 'tmp') | ||
os.mkdir(cls.tmp_dir) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
shutil.rmtree(cls.tmp_dir) | ||
|
||
def test_score_repository(self): | ||
scores = score_repository(host='github', full_name='UoW-CPC/COLARepo', clone_to=self.tmp_dir) | ||
|
||
self.assertAlmostEqual(scores['commit_frequency'], 4.5, 0) | ||
self.assertEqual(scores['issue_frequency'], 0) | ||
self.assertEqual(scores['core_contributors'], 3) | ||
self.assertFalse(scores['has_ci']) | ||
self.assertFalse(scores['has_license']) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |