From 3849ad106048952fc07e4c8ce045f671f39b1c24 Mon Sep 17 00:00:00 2001 From: Eli <43382407+eli64s@users.noreply.github.com> Date: Wed, 13 Sep 2023 06:32:52 -0500 Subject: [PATCH] =?UTF-8?q?=E2=80=A3=20Fix=20local=20path=20repository=20l?= =?UTF-8?q?ogic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- readmeai/utils.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 40784ab7..dc8b3047 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "readmeai" -version = "0.3.015" +version = "0.3.016" description = "🚀 Generate awesome README.md files from the terminal, powered by OpenAI's GPT language model APIs 💫" authors = ["Eli <0x.eli.64s@gmail.com>"] license = "MIT" diff --git a/readmeai/utils.py b/readmeai/utils.py index ce8416ff..3d357610 100644 --- a/readmeai/utils.py +++ b/readmeai/utils.py @@ -83,16 +83,20 @@ def get_github_file_link(file: str, user_repo_name: str) -> str: return f"https://github.com/{user_repo_name}/blob/main/{file}" -def get_user_repository_name(url) -> str: - """Extract username and repository name from a GitHub URL.""" +def get_user_repository_name(url_or_path) -> str: + """Extract username and repository name from a GitHub URL or local path.""" + + if os.path.exists(url_or_path): + return os.path.basename(url_or_path) + pattern = r"https?://github.com/([^/]+)/([^/]+)" - match = re.match(pattern, url) + match = re.match(pattern, url_or_path) if match: username, reponame = match.groups() return f"{username}/{reponame}" else: - raise ("Error: invalid remote repository URL.") + raise ValueError("Error: invalid remote repository URL or local path.") def adjust_max_tokens(max_tokens: int, prompt: str, target: str = "Hello!") -> int: