From 3aa54d91ca109469fca7188415d05f78edc57b24 Mon Sep 17 00:00:00 2001 From: Gowtham Kishore Date: Sun, 19 Jan 2025 11:02:27 -0800 Subject: [PATCH 1/5] Fixing lint changes --- src/config.py | 4 +++- src/gitingest/cli.py | 4 ++-- tests/test_cli.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/test_cli.py diff --git a/src/config.py b/src/config.py index 7365ab8b..2be0c498 100644 --- a/src/config.py +++ b/src/config.py @@ -8,9 +8,11 @@ MAX_TOTAL_SIZE_BYTES = 500 * 1024 * 1024 # 500 MB MAX_DISPLAY_SIZE: int = 300_000 -TMP_BASE_PATH = Path("/tmp/gitingest") DELETE_REPO_AFTER: int = 60 * 60 # In seconds +OUTPUT_FILE_PATH = "digest.txt" +TMP_BASE_PATH = Path("/tmp/gitingest") + EXAMPLE_REPOS: list[dict[str, str]] = [ {"name": "Gitingest", "url": "https://github.com/cyclotruc/gitingest"}, {"name": "FastAPI", "url": "https://github.com/tiangolo/fastapi"}, diff --git a/src/gitingest/cli.py b/src/gitingest/cli.py index a21a4533..18a0e106 100644 --- a/src/gitingest/cli.py +++ b/src/gitingest/cli.py @@ -6,7 +6,7 @@ import click -from config import MAX_FILE_SIZE +from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH from gitingest.repository_ingest import ingest @@ -84,7 +84,7 @@ async def _async_main( include_patterns = set(include_pattern) if not output: - output = "digest.txt" + output = OUTPUT_FILE_PATH summary, _, _ = await ingest(source, max_size, include_patterns, exclude_patterns, output=output) click.echo(f"Analysis complete! Output written to: {output}") diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 00000000..bef35bf8 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,41 @@ +""" Tests for the gitingest cli """ + +import os + +from click.testing import CliRunner + +from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH +from gitingest.cli import main + + +def test_gitingest_cli_with_default_options(): + runner = CliRunner() + result = runner.invoke(main, ["../"]) + output_lines = result.output.strip().split("\n") + assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines + assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" + + os.remove(OUTPUT_FILE_PATH) + + +def test_gitingest_cli_with_options(): + runner = CliRunner() + result = runner.invoke( + main, + [ + "../", + "--output", + OUTPUT_FILE_PATH, + "--max-size", + MAX_FILE_SIZE, + "--exclude-pattern", + "tests/", + "--include-pattern", + "src/", + ], + ) + output_lines = result.output.strip().split("\n") + assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines + assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" + + os.remove(OUTPUT_FILE_PATH) From 198c6358d58ce6b0cc9039e787a63db41d530dc5 Mon Sep 17 00:00:00 2001 From: Gowtham Kishore Date: Sun, 19 Jan 2025 15:14:18 -0800 Subject: [PATCH 2/5] Refactoring function name --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index bef35bf8..c0104208 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -8,7 +8,7 @@ from gitingest.cli import main -def test_gitingest_cli_with_default_options(): +def test_cli_with_default_options(): runner = CliRunner() result = runner.invoke(main, ["../"]) output_lines = result.output.strip().split("\n") @@ -18,7 +18,7 @@ def test_gitingest_cli_with_default_options(): os.remove(OUTPUT_FILE_PATH) -def test_gitingest_cli_with_options(): +def test_cli_with_options(): runner = CliRunner() result = runner.invoke( main, From 8e28c20a9fb11aeb1102fd98ff983714a904291d Mon Sep 17 00:00:00 2001 From: Gowtham Kishore Date: Sun, 19 Jan 2025 15:29:29 -0800 Subject: [PATCH 3/5] Refactoring test case name --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index c0104208..b06386c8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -35,7 +35,7 @@ def test_cli_with_options(): ], ) output_lines = result.output.strip().split("\n") - assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines + assert f"Analysis complete! Output written to:s {OUTPUT_FILE_PATH}" in output_lines assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" os.remove(OUTPUT_FILE_PATH) From dc1ea7c2101fbce402a1d63e76c954cf9b14c396 Mon Sep 17 00:00:00 2001 From: Gowtham Kishore Date: Sun, 19 Jan 2025 15:50:31 -0800 Subject: [PATCH 4/5] Fixing Test Cases; --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index b06386c8..c0104208 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -35,7 +35,7 @@ def test_cli_with_options(): ], ) output_lines = result.output.strip().split("\n") - assert f"Analysis complete! Output written to:s {OUTPUT_FILE_PATH}" in output_lines + assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" os.remove(OUTPUT_FILE_PATH) From 68e78a6497c1ee741974ddc8e74bcfec5c3605d1 Mon Sep 17 00:00:00 2001 From: Gowtham Kishore Date: Mon, 20 Jan 2025 19:39:27 -0800 Subject: [PATCH 5/5] Fixing path --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index c0104208..86bd2271 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -10,7 +10,7 @@ def test_cli_with_default_options(): runner = CliRunner() - result = runner.invoke(main, ["../"]) + result = runner.invoke(main, ["./"]) output_lines = result.output.strip().split("\n") assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" @@ -23,7 +23,7 @@ def test_cli_with_options(): result = runner.invoke( main, [ - "../", + "./", "--output", OUTPUT_FILE_PATH, "--max-size",