Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77f3547

Browse files
feat: add unit tests for output formatting and enhance file system schema
1 parent 1e8547e commit 77f3547

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
@@ -295,7 +295,7 @@ def summary(self, node: Source, query):
295295

296296
@summary.register
297297
def _(self, node: FileSystemDirectory, query):
298-
template = """
298+
template = """\
299299
Directory structure:
300300
{{ node.tree }}
301301
"""
@@ -305,7 +305,9 @@ def _(self, node: FileSystemDirectory, query):
305305
@summary.register
306306
def _(self, context: Context, query):
307307
template = """
308-
{{ context.summary }}
308+
Repository: {{ context.query.user_name }}/{{ context.query.repo_name }}
309+
Commit: {{ context.query.commit }}
310+
Files analyzed: {{ context.sources[0].file_count }}
309311
"""
310312
summary_template = self.env.from_string(template)
311313
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 validate_github_token
1313
from gitingest.utils.pattern_utils import process_patterns

‎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)

AltStyle によって変換されたページ (->オリジナル) /