diff --git a/grimoire_elk/enriched/colic.py b/grimoire_elk/enriched/colic.py index fad933fdf..2c273102a 100644 --- a/grimoire_elk/enriched/colic.py +++ b/grimoire_elk/enriched/colic.py @@ -167,8 +167,8 @@ def extract_modules(self, file_path): return modules @metadata - def get_rich_item(self, file_analysis): - # TODO: requires adjustments regarding category of backend used + def __get_rich_scancode(self, file_analysis): + # Scancode and Scancode-CLI Implementation eitem = {} eitem["file_path"] = file_analysis["file_path"] @@ -192,14 +192,43 @@ def get_rich_item(self, file_analysis): return eitem + @metadata + def __get_rich_nomossa(self, file_analysis): + # NOMOS analyzer implementation + + eitem = {} + eitem["file_path"] = file_analysis["file_path"] + eitem["modules"] = self.extract_modules(eitem["file_path"]) + eitem["license_name"] = [] + eitem["has_license"] = 0 + + if file_analysis["licenses"] != "No_license_found": + eitem["has_license"] = 1 + for _license in file_analysis["licenses"]: + eitem["licenses"].append(_license) + eitem["license_name"].append(_license) + + # NOMOS doesn't provide copyright information. + eitem["copyrights"] = [] + eitem["has_copyright"] = 0 + + return eitem + def get_rich_items(self, item): - # The real data - entry = item['data'] + """ + :category: code_license_scancode_cli(default) + """ + if item["category"] == "code_license_nomos": + get_rich_item = self.__get_rich_nomossa + else: + get_rich_item = self.__get_rich_scancode + + entry = item['data'] enriched_items = [] for file_analysis in entry["analysis"]: - eitem = self.get_rich_item(file_analysis) + eitem = get_rich_item(file_analysis) for f in self.RAW_FIELDS_COPY: if f in item: @@ -208,13 +237,14 @@ def get_rich_items(self, item): eitem[f] = None # common attributes - eitem['commit_sha'] = entry['commit'] eitem['author'] = entry['Author'] - eitem['committer'] = entry['Commit'] - eitem['commit'] = entry['commit'] - eitem['message'] = entry['message'] eitem['author_date'] = fix_field_date(entry['AuthorDate']) + eitem["category"] = item["category"] + eitem['commit'] = entry['commit'] + eitem['committer'] = entry['Commit'] eitem['commit_date'] = fix_field_date(entry['CommitDate']) + eitem['commit_sha'] = entry['commit'] + eitem['message'] = entry['message'] if self.prjs_map: eitem.update(self.get_item_project(eitem)) diff --git a/tests/data/colic.json b/tests/data/colic.json index bbbc60f6d..f559075de 100644 --- a/tests/data/colic.json +++ b/tests/data/colic.json @@ -185,5 +185,135 @@ "timestamp": 1562563562.34835, "updated_on": 1525607811.0, "uuid": "ce7c47568fd87100aff497dd7677b0736d85db1e" + }, + { + "backend_name": "CoLic", + "backend_version": "0.5.0", + "category": "code_license_scancode", + "data": { + "Author": "Valerio Cosentino ", + "AuthorDate": "Sun May 6 13:56:51 2018 +0200", + "Commit": "Valerio Cosentino ", + "CommitDate": "Sun May 6 13:56:51 2018 +0200", + "analysis": [{ + "copyrights": [{ + "end_line": 3, + "start_line": 3, + "value": "Copyright (c) 2015-2018 Bitergia" + }], + "file_path": "graal/codecomplexity.py", + "licenses": [{ + "category": "Copyleft", + "end_line": 17, + "homepage_url": "http://www.gnu.org/licenses/gpl-3.0-standalone.html", + "is_exception": false, + "key": "gpl-3.0-plus", + "matched_rule": { + "identifier": "gpl-3.0-plus_117.RULE", + "is_license_notice": true, + "is_license_reference": false, + "is_license_tag": false, + "is_license_text": false, + "license_expression": "gpl-3.0-plus", + "licenses": [ + "gpl-3.0-plus" + ], + "match_coverage": 97.35, + "matched_length": 110, + "matcher": "3-seq", + "rule_length": 113, + "rule_relevance": 100.0 + }, + "name": "GNU General Public License 3.0 or later", + "owner": "Free Software Foundation (FSF)", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:gpl-3.0-plus", + "score": 97.35, + "short_name": "GPL 3.0 or later", + "spdx_license_key": "GPL-3.0-or-later", + "spdx_url": "https://spdx.org/licenses/GPL-3.0-or-later", + "start_line": 5, + "text_url": "http://www.gnu.org/licenses/gpl-3.0-standalone.html" + }] + }], + "analyzer": "scancode", + "commit": "a957488c9bd95e3b72a30611edc61496ee152430", + "message": "[codecomplexity] Enable analysis with no file filtering\n\nThis patch allows to handle analysis without file filtering." + }, + "graal_version": "0.2.1", + "origin": "https://github.com/chaoss/grimoirelab-graal", + "tag": "https://github.com/chaoss/grimoirelab-graal", + "timestamp": 1565108843.015344, + "updated_on": 1525607811.0, + "uuid": "ce7c47568fd87100aff497dd7677b0736d85db1e" + }, + { + "backend_name": "CoLic", + "backend_version": "0.5.0", + "category": "code_license_scancode", + "data": { + "Author": "valerio ", + "AuthorDate": "Sun May 6 14:02:36 2018 +0200", + "Commit": "GitHub ", + "CommitDate": "Sun May 6 14:02:36 2018 +0200", + "analysis": [{ + "copyrights": [], + "file_path": "README.md", + "licenses": [] + }], + "analyzer": "scancode", + "commit": "8aedf09e36008fee19192985c0eb51879c6c61e4", + "message": "Create README.md" + }, + "graal_version": "0.2.1", + "origin": "https://github.com/chaoss/grimoirelab-graal", + "tag": "https://github.com/chaoss/grimoirelab-graal", + "timestamp": 1565108866.965087, + "updated_on": 1525608156.0, + "uuid": "856beb87d6b324b136e718295cc6ad69343a1066" + }, + { + "backend_name": "CoLic", + "backend_version": "0.5.0", + "category": "code_license_nomos", + "data": { + "Author": "inishchith ", + "AuthorDate": "Mon Feb 25 21:44:23 2019 +0530", + "Commit": "Valerio Cosentino ", + "CommitDate": "Tue Feb 26 16:24:43 2019 +0100", + "analysis": [{ + "file_path": "tests/test_colic.py", + "licenses": [ + "GPL-3.0" + ] + }, + { + "file_path": "tests/test_nomos.py", + "licenses": [ + "GPL-3.0" + ] + }, + { + "file_path": "tests/test_scancode.py", + "licenses": [ + "GPL-3.0" + ] + }, + { + "file_path": "tests/utils.py", + "licenses": [ + "GPL-3.0" + ] + } + ], + "analyzer": "nomos", + "commit": "dda651a12eb05b2d604522b4fbdbf07d3e213eff", + "message": "[tests] Move executable path to utils.py\n\nMove executable paths - NOMOS_PATH and SCANCODE_PATH to utils.py" + }, + "graal_version": "0.2.1", + "origin": "https://github.com/chaoss/grimoirelab-graal", + "tag": "https://github.com/chaoss/grimoirelab-graal", + "timestamp": 1565204679.302685, + "updated_on": 1551194683.0, + "uuid": "79a561015d5d49c3ec6754a05db24735f957814e" } ] diff --git a/tests/test_colic.py b/tests/test_colic.py index db0c441f2..7410ea600 100644 --- a/tests/test_colic.py +++ b/tests/test_colic.py @@ -82,6 +82,36 @@ def test_raw_to_enrich(self): self.assertEqual(eitem['modules'], ["graal"]) self.assertEqual(eitem['file_path'], "graal/codecomplexity.py") + item = self.items[2] + eitem = enrich_backend.get_rich_items(item)[0] + self.assertEqual(eitem['licenses'], ["gpl-3.0-plus"]) + self.assertEqual(eitem['has_license'], 1) + self.assertEqual(eitem['license_name'], ["GNU General Public License 3.0 or later"]) + self.assertEqual(eitem['copyrights'], ["Copyright (c) 2015-2018 Bitergia"]) + self.assertEqual(eitem['has_copyright'], 1) + self.assertEqual(eitem['modules'], ["graal"]) + self.assertEqual(eitem['file_path'], "graal/codecomplexity.py") + + item = self.items[3] + eitem = enrich_backend.get_rich_items(item)[0] + self.assertEqual(eitem['licenses'], []) + self.assertEqual(eitem['has_license'], 0) + self.assertEqual(eitem['license_name'], []) + self.assertEqual(eitem['copyrights'], []) + self.assertEqual(eitem['has_copyright'], 0) + self.assertEqual(eitem['modules'], []) + self.assertEqual(eitem['file_path'], "README.md") + + item = self.items[4] + eitem = enrich_backend.get_rich_items(item)[0] + self.assertEqual(eitem['licenses'], ["GPL-3.0"]) + self.assertEqual(eitem['has_license'], 1) + self.assertEqual(eitem['license_name'], ["GPL-3.0"]) + self.assertEqual(eitem['copyrights'], []) + self.assertEqual(eitem['has_copyright'], 0) + self.assertEqual(eitem['modules'], ["tests"]) + self.assertEqual(eitem['file_path'], "tests/test_colic.py") + def test_colic_analysis_study(self): """ Test that the colic analysis study works correctly """