diff --git a/persper/analytics/graph_server.py b/persper/analytics/graph_server.py index 29d8e81f213..049c721166b 100644 --- a/persper/analytics/graph_server.py +++ b/persper/analytics/graph_server.py @@ -6,7 +6,7 @@ from persper.analytics.call_commit_graph import CallCommitGraph JS_FILENAME_REGEXES = [ - r'.+\.(js|vue)$', + r'.+\.(js|vue|ts|tsx)$', r'^(?!dist/).+', r'^(?!test(s)?/).+', r'^(?!spec/).+', diff --git a/persper/analytics/multi_analyzer.py b/persper/analytics/multi_analyzer.py index 6b424aa81c8..cc1328a1f57 100644 --- a/persper/analytics/multi_analyzer.py +++ b/persper/analytics/multi_analyzer.py @@ -1,7 +1,9 @@ import os import json import pickle +import logging from git import Repo +from enum import Enum from Naked.toolshed.shell import muterun_rb from persper.util.path import root_path from persper.analytics.c import CGraphServer @@ -12,6 +14,23 @@ from persper.analytics.analyzer2 import Analyzer, AnalyzerObserver, emptyAnalyzerObserver +_logger = logging.getLogger(__name__) + + +class Linguist(Enum): + """ + Encodes the relationship between a language and its name in linguist's output + https://github.com/github/linguist/blob/master/lib/linguist/languages.yml + """ + C = "C" + CPP = "C++" + GO = "Go" + JAVA = "Java" + JAVASCRIPT = "JavaScript" + TYPESCRIPT = "TypeScript" + VUE = "Vue" + + class MultiAnalyzer: LANGUAGE_THRESHOLD = 0.3 @@ -35,21 +54,36 @@ def _set_linguist(self): for k in lang_dict.keys(): lang_dict[k] = lang_dict[k] * 1.0 / total_lines + js = Linguist.JAVASCRIPT.value + ts = Linguist.TYPESCRIPT.value + vue = Linguist.VUE.value + + _logger.info(lang_dict) + if vue in lang_dict: + _logger.info("Merging Vue to Javascript...") + if js not in lang_dict: + lang_dict[js] = 0 + lang_dict[js] += lang_dict[vue] + del lang_dict[vue] + _logger.info(lang_dict) + + if ts in lang_dict: + _logger.info("Merging TypeScript to JavaScript...") + if js not in lang_dict: + lang_dict[js] = 0 + lang_dict[js] += lang_dict[ts] + del lang_dict[ts] + _logger.info(lang_dict) + + # intersect with what languages we support for lang, value in lang_dict.items(): if lang in self._supported_analyzers().keys(): self._linguist[lang] = value - print(self._linguist) - if "Vue" in self._linguist: - print("Merging Vue to Javascript...") - if "JavaScript" not in self._linguist: - self._linguist["JavaScript"] = 0 - self._linguist["JavaScript"] += self._linguist["Vue"] - del self._linguist["Vue"] - print(self._linguist) + _logger.info(self._linguist) else: - print('Analyzing Language Error from Linguist') + _logger.info('Analyzing Language Error from Linguist') def _set_analyzers(self): for language, value in self._linguist.items(): diff --git a/test/test_analytics/test_multi_analyzer.py b/test/test_analytics/test_multi_analyzer.py index 1e9b70d1942..c2bbaa6ae56 100644 --- a/test/test_analytics/test_multi_analyzer.py +++ b/test/test_analytics/test_multi_analyzer.py @@ -6,7 +6,7 @@ @pytest.fixture(scope='module') -def repo_path(): +def vue_repo_path(): repo_path = os.path.join(root_path, "repos/vue-realworld-example-app") repo_url = 'https://github.com/gothinkster/vue-realworld-example-app' if not os.path.exists(repo_path): @@ -14,5 +14,20 @@ def repo_path(): return repo_path -def test_set_linguist(repo_path): - maz = MultiAnalyzer(repo_path) +@pytest.fixture(scope='module') +def ts_repo_path(): + repo_path = os.path.join(root_path, "repos/TypeScriptSamples") + repo_url = 'https://github.com/microsoft/TypeScriptSamples' + if not os.path.exists(repo_path): + Repo.clone_from(repo_url, repo_path) + return repo_path + + +def test_set_linguist_vue(vue_repo_path): + # _set_linguist is called during the initialization of MultiAnalyzer + maz = MultiAnalyzer(vue_repo_path) + + +def test_set_linguist_ts(ts_repo_path): + # _set_linguist is called during the initialization of MultiAnalyzer + maz = MultiAnalyzer(ts_repo_path)