Skip to content

Commit 5e1eecb

Browse files
committed
commit post catastrophe
1 parent 2a0d6cb commit 5e1eecb

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

src/gitingest/entrypoint.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from gitingest.clone import clone_repo
1616
from gitingest.config import MAX_FILE_SIZE
1717
from gitingest.ingestion import ingest_query
18+
from gitingest.output_formatter import generate_digest
1819
from gitingest.query_parser import parse_local_dir_path, parse_remote_repo
1920
from gitingest.utils.auth import resolve_token
2021
from gitingest.utils.compat_func import removesuffix
@@ -51,7 +52,7 @@ async def ingest_async(
5152
This function analyzes a source (URL or local path), clones the corresponding repository (if applicable),
5253
and processes its files according to the specified query parameters. It returns a single digest string.
5354
54-
The output is generated lazily using a Context object and its .generate_digest() method.
55+
The output is generated lazily using a Context object and the generate_digest() function.
5556
5657
Parameters
5758
----------
@@ -142,7 +143,7 @@ async def ingest_async(
142143
if output:
143144
logger.debug("Writing output to file", extra={"output_path": output})
144145
context = ingest_query(query)
145-
digest = context.generate_digest()
146+
digest = generate_digest(context)
146147
await _write_output(digest, content=None, target=output)
147148
logger.info("Ingestion completed successfully")
148149
return digest
@@ -166,7 +167,7 @@ def ingest(
166167
This function analyzes a source (URL or local path), clones the corresponding repository (if applicable),
167168
and processes its files according to the specified query parameters. It returns a single digest string.
168169
169-
The output is generated lazily using a Context object and its .generate_digest() method.
170+
The output is generated lazily using a Context object and the generate_digest() function.
170171
171172
Parameters
172173
----------
@@ -204,7 +205,7 @@ def ingest(
204205
``ingest_async`` : The asynchronous version of this function.
205206
206207
"""
207-
context = asyncio.run(ingest_async(
208+
digest = asyncio.run(ingest_async(
208209
source,
209210
max_file_size=max_file_size,
210211
include_patterns=include_patterns,
@@ -216,7 +217,7 @@ def ingest(
216217
token=token,
217218
output=output,
218219
))
219-
return context.generate_digest()
220+
return digest
220221

221222

222223
def _override_branch_and_tag(query: IngestionQuery, branch: str | None, tag: str | None) -> None:

src/gitingest/ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def ingest_query(query: IngestionQuery) -> Context:
3333
Returns
3434
-------
3535
Context
36-
A Context object representing the ingested file system nodes. Call .generate_digest() to get the summary, directory structure, and file contents.
36+
A Context object representing the ingested file system nodes. Use generate_digest(context) to get the summary, directory structure, and file contents.
3737
3838
Raises
3939
------

src/gitingest/output_formatter.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from gitingest.utils.compat_func import readlink
1313
from functools import singledispatchmethod
1414
from gitingest.schemas import Source, FileSystemFile, FileSystemDirectory, FileSystemSymlink, FileSystemTextFile
15-
from gitingest.schemas.filesystem import SEPARATOR, FileSystemNodeType
15+
from gitingest.schemas.filesystem import SEPARATOR, FileSystemNodeType, CONTEXT_HEADER, CONTEXT_FOOTER
1616
from gitingest.utils.logging_config import get_logger
1717
from jinja2 import Environment, BaseLoader
1818

@@ -291,3 +291,27 @@ def _(node: FileSystemFile, query):
291291
"""
292292
file_template = self.env.from_string(template)
293293
return file_template.render(SEPARATOR=SEPARATOR, node=node, query=query, formatter=self)
294+
295+
296+
def generate_digest(context) -> str:
297+
"""Generate a digest from a Context object.
298+
299+
Parameters
300+
----------
301+
context : Context
302+
The context object containing nodes, formatter, and query.
303+
304+
Returns
305+
-------
306+
str
307+
The formatted digest string with header, content, and footer.
308+
"""
309+
if context.query.user_name and context.query.repo_name:
310+
context_header = CONTEXT_HEADER.format(f"/{context.query.user_name}/{context.query.repo_name}")
311+
else:
312+
context_header = CONTEXT_HEADER.format("")
313+
context_footer = CONTEXT_FOOTER
314+
formatted = []
315+
for node in context.nodes:
316+
formatted.append(context.formatter.format(node, context.query))
317+
return context_header + "\n".join(formatted) + context_footer

src/gitingest/schemas/filesystem.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,31 +129,22 @@ def _(self: 'FileSystemSymlink'):
129129

130130

131131
class Context:
132-
"""Context for holding a list of Source objects and generating a digest on demand using a Formatter.
132+
"""Context for holding a list of Source objects that can be formatted using a Formatter.
133133
134134
Attributes
135135
----------
136136
nodes : list[Source]
137-
The list of source objects to generate a digest for.
137+
The list of source objects to format.
138138
formatter : Formatter
139139
The formatter to use for formatting sources.
140140
query : IngestionQuery
141141
The query context.
142142
"""
143-
nodes: list[Source]
144-
formatter: Formatter
145-
query: IngestionQuery
146-
147-
def generate_digest(self) -> str:
148-
if self.query.user_name and self.query.repo_name:
149-
context_header = CONTEXT_HEADER.format(f"/{self.query.user_name}/{self.query.repo_name}")
150-
else:
151-
context_header = CONTEXT_HEADER.format("")
152-
context_footer = CONTEXT_FOOTER
153-
formatted = []
154-
for node in self.nodes:
155-
formatted.append(self.formatter.format(node, self.query))
156-
return context_header + "\n".join(formatted) + context_footer
143+
144+
def __init__(self, nodes: list[Source], formatter: Formatter, query: IngestionQuery):
145+
self.nodes = nodes
146+
self.formatter = formatter
147+
self.query = query
157148

158149
@property
159150
def summary(self):

src/server/query_processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from gitingest.clone import clone_repo
1010
from gitingest.ingestion import ingest_query
11+
from gitingest.output_formatter import generate_digest
1112
from gitingest.query_parser import parse_remote_repo
1213
from gitingest.utils.git_utils import resolve_commit, validate_github_token
1314
from gitingest.utils.logging_config import get_logger
@@ -301,7 +302,7 @@ async def process_query(
301302

302303
try:
303304
context = ingest_query(query)
304-
digest = context.generate_digest()
305+
digest = generate_digest(context)
305306

306307
# Store digest based on S3 configuration
307308
if is_s3_enabled():
@@ -355,7 +356,7 @@ async def process_query(
355356
summary="",
356357
digest_url=digest_url,
357358
tree="",
358-
content=content,
359+
content=digest,
359360
default_max_file_size=max_file_size,
360361
pattern_type=pattern_type,
361362
pattern=pattern,

0 commit comments

Comments
 (0)