Skip to content

Commit 1d1e8b4

Browse files
committed
feat: add unit tests for output formatting and enhance file system schema
1 parent df54878 commit 1d1e8b4

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

src/gitingest/output_formatter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def summary(self, node: Source, query):
324324

325325
@summary.register
326326
def _(self, node: FileSystemDirectory, query):
327-
template = """
327+
template = """ \
328328
Directory structure:
329329
{{ node.tree }}
330330
"""
@@ -334,7 +334,9 @@ def _(self, node: FileSystemDirectory, query):
334334
@summary.register
335335
def _(self, context: Context, query):
336336
template = """
337-
{{ context.summary }}
337+
Repository: {{ context.query.user_name }}/{{ context.query.repo_name }}
338+
Commit: {{ context.query.commit }}
339+
Files analyzed: {{ context.sources[0].file_count }}
338340
"""
339341
summary_template = self.env.from_string(template)
340342
return summary_template.render(context=context, query=query)

src/gitingest/schemas/filesystem.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class FileSystemDirectory(FileSystemNode):
7070
children: list[FileSystemNode] = field(default_factory=list)
7171
file_count: int = 0
7272
dir_count: int = 0
73+
file_count_total: int = 0
7374
type: FileSystemNodeType = FileSystemNodeType.DIRECTORY
7475

7576
def sort_children(self) -> None:

src/server/query_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from gitingest.clone import clone_repo
99
from gitingest.ingestion import ingest_query
10-
from gitingest.output_formatter import DefaultFormatter, SummaryFormatter
10+
from gitingest.output_formatter import DebugFormatter, DefaultFormatter, SummaryFormatter
1111
from gitingest.query_parser import parse_remote_repo
1212
from gitingest.utils.git_utils import resolve_commit, validate_github_token
1313
from gitingest.utils.logging_config import get_logger

test_formatting.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pathlib import Path
2+
from unittest.mock import Mock
3+
from gitingest.output_formatter import DefaultFormatter
4+
from gitingest.schemas.filesystem import Context, GitRepository, FileSystemFile
5+
6+
# Create a mock query
7+
mock_query = Mock()
8+
mock_query.user_name = "test_user"
9+
mock_query.repo_name = "test_repo"
10+
11+
# Create a simple file
12+
mock_file = FileSystemFile(
13+
name="test.py",
14+
path_str="test.py",
15+
path=Path("test.py"),
16+
)
17+
mock_file.content = "print('hello world')"
18+
19+
# Create a git repository with the file
20+
mock_repo = GitRepository(
21+
name="test_repo",
22+
path_str="",
23+
path=Path("."),
24+
children=[mock_file]
25+
)
26+
27+
# Create context
28+
context = Context([mock_repo], mock_query)
29+
30+
# Test formatting
31+
formatter = DefaultFormatter()
32+
result = formatter.format(context, mock_query)
33+
print("RESULT:")
34+
print(repr(result))
35+
print("\nFORMATTED:")
36+
print(result)

0 commit comments

Comments
 (0)