From 64ffcc4d6979a8dd00968104f164d318a041ff0c Mon Sep 17 00:00:00 2001 From: Eli <43382407+eli64s@users.noreply.github.com> Date: Sun, 31 Dec 2023 04:59:52 -0600 Subject: [PATCH] Update git clone logic to fix bug. --- pyproject.toml | 2 +- readmeai/main.py | 16 +++++++--------- readmeai/services/git_operations.py | 10 +++------- tests/test_cli/test_commands.py | 8 ++++---- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ba84043..128bb626 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "readmeai" -version = "0.4.093" +version = "0.4.094" description = "🚀 Auto-generate beautiful README files from the terminal using GPT LLM APIs 💫" authors = ["Eli <0x.eli.64s@gmail.com>"] license = "MIT" diff --git a/readmeai/main.py b/readmeai/main.py index 0149d59c..f054c7fe 100644 --- a/readmeai/main.py +++ b/readmeai/main.py @@ -7,7 +7,6 @@ import asyncio import os import traceback -import shutil from readmeai.cli.options import prompt_for_custom_image from readmeai.config.settings import ( @@ -99,20 +98,19 @@ async def readme_agent(conf: AppConfig, conf_helper: ConfigHelper) -> None: conf.md.overview.format(conf.md.default), conf.md.default, ) - logger.info(f"Total summaries generated: {len(summaries)}") - headers.build_readme_md(conf, conf_helper, dependencies, summaries) + logger.info(f"Total summaries generated: {len(summaries)}") + + headers.build_readme_md(conf, conf_helper, dependencies, summaries) + + logger.info( + "README-AI file generated successfully: {conf.files.output}" + ) - logger.info( - "README-AI file generated successfully: {conf.files.output}" - ) except Exception as exc_info: logger.error( f"Exception occurred: {exc_info}\n{traceback.format_exc()}" ) - finally: - if temp_dir is not None: - shutil.rmtree(temp_dir) def main( diff --git a/readmeai/services/git_operations.py b/readmeai/services/git_operations.py index 62f167fb..30895b17 100644 --- a/readmeai/services/git_operations.py +++ b/readmeai/services/git_operations.py @@ -16,13 +16,9 @@ def clone_repo_to_temp_dir(repo_path: str) -> Path: return Path(repo_path) try: - with tempfile.TemporaryDirectory() as temp_dir: - git.Repo.clone_from( - repo_path, temp_dir, depth=1, single_branch=True - ) - new_temp_dir = Path(tempfile.mkdtemp()) - shutil.copytree(temp_dir, new_temp_dir, dirs_exist_ok=True) - return new_temp_dir + temp_dir = tempfile.mkdtemp() + git.Repo.clone_from(repo_path, temp_dir, depth=1, single_branch=True) + return Path(temp_dir) except git.GitCommandError as exc_info: raise ValueError(f"Git clone error: {exc_info}") from exc_info diff --git a/tests/test_cli/test_commands.py b/tests/test_cli/test_commands.py index 8d7ac274..46e1bb77 100644 --- a/tests/test_cli/test_commands.py +++ b/tests/test_cli/test_commands.py @@ -5,19 +5,19 @@ from readmeai.cli.commands import commands -def test_commands(config): +def test_commands(): """Test that the CLI command runs.""" runner = CliRunner() result = runner.invoke( commands, [ "--repository", - config.git.repository, + "https://github.com/example/repo", "--api-key", "dummy-key", ], ) - assert result.exit_code == 0 + assert result.exit_code == 0, f"Unexpected failure: {result.output}" def test_commands_with_options(): @@ -36,7 +36,7 @@ def test_commands_with_options(): "0.8", ], ) - assert result.exit_code == 1 + assert result.exit_code == 0 def test_commands_missing_repository():