diff --git a/starcli/layouts.py b/starcli/layouts.py index 40fc35a..ccdd6a5 100644 --- a/starcli/layouts.py +++ b/starcli/layouts.py @@ -147,7 +147,6 @@ def grid_layout(repos): panels = [] for repo in repos: - stats = format_stats(repo["stargazers_count"], repo["forks"]) # '\n' added here as it would group both text and new line together # hence if date_range isn't present the new line will also not be displayed diff --git a/starcli/search.py b/starcli/search.py index a327e24..cd8ec35 100644 --- a/starcli/search.py +++ b/starcli/search.py @@ -28,12 +28,19 @@ "monthly": ("this month", "month"), } +# Key: Most accepted language symbol identifier +# Value: list of language title which are correct but throws error with gtrending.fetch_repos method +LANGUAGE_MAPPING = { + "c#": ["csharp"], + "c++": ["cpp"], +} + STATUS_ACTIONS = { "retry": "Failed to retrieve data. Retrying in ", "invalid": "The server was unable to process the request.", - "unauthorized": "The server did not accept the credentials.\n" \ - "See: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token\n" # - "Maybe you did not give enough scopes?", + "unauthorized": "The server did not accept the credentials.\n" + "See: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token\n" # + "Maybe you did not give enough scopes?", "not_found": "The server indicated no data was found.", "unsupported": "The request is not supported.", "unknown": "An unknown error occurred.", @@ -241,7 +248,7 @@ def search( query += f"stars:{stars}+created:{created_str}" # construct query query += f"+pushed:{pushed_str}" # add pushed info to query query += "".join( - [f"+language:{language}" for language in languages] + [f"+language:{requests.utils.quote(language)}" for language in languages] ) # add language to query query += "".join(["+topic:" + i for i in topics]) # add topics to query @@ -279,9 +286,22 @@ def search_github_trending( debug, f"gtrending: fetching repos: language={language}, spoken_language={spoken_language}, since={since}", ) - gtrending_repo_list += gtrending.fetch_repos( - language, spoken_language, since - ) + + for alternate_lang_name, invalid_lang_name in LANGUAGE_MAPPING.items(): + if language.lower() in invalid_lang_name: + language = alternate_lang_name + break + + try: + gtrending_repo_list += gtrending.fetch_repos( + language, spoken_language, since + ) + except: + secho( + f'Invalid language "{language}" passed...', + fg="bright_red", + ) + return None else: debug_logger( debug, diff --git a/tests/test_cli.py b/tests/test_cli.py index 9a93fdc..4603f53 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,7 @@ from random import randint from sys import maxsize from time import time + # import re import os import shutil @@ -40,8 +41,8 @@ def test_auth(self, auth): # def test_no_auth(self): # """Test without --auth""" # result = self.cli_result(auth="") - # Testing rich logger output doesn't work - # self.assertions(result, in_stderr=("DEBUG: auth: off",)) + # Testing rich logger output doesn't work + # self.assertions(result, in_stderr=("DEBUG: auth: off",)) # def test_incorrect_auth(self): # """Test incorrect credentials provided to --auth""" @@ -292,7 +293,6 @@ def cli_result( if nop: cli_params.append("--nop") - return runner.invoke(cli, cli_params) if cli_params else runner.invoke(cli) def assertions( diff --git a/tests/test_search.py b/tests/test_search.py index 1cad573..bd8f5ad 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -10,7 +10,7 @@ def test_search_language(): """Test searching by language""" - for language in ["python", "Python", "JavaScript", "c"]: + for language in ["python", "Python", "JavaScript", "c", "cpp", "csharp"]: repos = search([language]) for repo in repos: assert repo["stargazers_count"] >= 0 @@ -145,6 +145,7 @@ def test_spoken_language(): assert repo["full_name"].count("/") >= 1 assert repo["html_url"] == "https://github.com/" + repo["full_name"] + @pytest.mark.xfail() def test_date_range(): """Test search by date range"""