Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Bug #111 + Enhancements #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion starcli/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions starcli/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from random import randint
from sys import maxsize
from time import time

# import re
import os
import shutil
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down