Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gitingest/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async def ingest_async(
from_web=False,
include_patterns=include_patterns,
ignore_patterns=exclude_patterns,
token=token,
)

if query.url:
Expand Down
8 changes: 6 additions & 2 deletions src/gitingest/query_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async def parse_query(
from_web: bool,
include_patterns: Optional[Union[str, Set[str]]] = None,
ignore_patterns: Optional[Union[str, Set[str]]] = None,
token: Optional[str] = None,
) -> IngestionQuery:
"""
Parse the input source (URL or path) to extract relevant details for the query.
Expand All @@ -49,7 +50,10 @@ async def parse_query(
Patterns to include, by default None. Can be a set of strings or a single string.
ignore_patterns : Union[str, Set[str]], optional
Patterns to ignore, by default None. Can be a set of strings or a single string.

token : str, optional
GitHub personal-access token (PAT). Needed when *source* refers to a
**private** repository. Can also be set via the ``GITHUB_TOKEN`` env var.
Must start with 'github_pat_' or 'gph_' for GitHub repositories.
Returns
-------
IngestionQuery
Expand All @@ -59,7 +63,7 @@ async def parse_query(
# Determine the parsing method based on the source type
if from_web or urlparse(source).scheme in ("https", "http") or any(h in source for h in KNOWN_GIT_HOSTS):
# We either have a full URL or a domain-less slug
query = await _parse_remote_repo(source)
query = await _parse_remote_repo(source, token=token)
else:
# Local path scenario
query = _parse_local_dir_path(source)
Expand Down
9 changes: 8 additions & 1 deletion src/server/query_processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Process a query by parsing input, cloning a repository, and generating a summary."""

from functools import partial
from typing import Optional

from fastapi import Request
from starlette.templating import _TemplateResponse
Expand All @@ -19,6 +20,7 @@ async def process_query(
pattern_type: str = "exclude",
pattern: str = "",
is_index: bool = False,
token: Optional[str] = None,
) -> _TemplateResponse:
"""
Process a query by parsing input, cloning a repository, and generating a summary.
Expand All @@ -40,6 +42,9 @@ async def process_query(
Pattern to include or exclude in the query, depending on the pattern type.
is_index : bool
Flag indicating whether the request is for the index page (default is False).
token : str, optional
GitHub personal-access token (PAT). Needed when *input_text* refers to a
**private** repository.

Returns
-------
Expand Down Expand Up @@ -71,6 +76,7 @@ async def process_query(
"default_file_size": slider_position,
"pattern_type": pattern_type,
"pattern": pattern,
"token": token,
}

try:
Expand All @@ -80,12 +86,13 @@ async def process_query(
from_web=True,
include_patterns=include_patterns,
ignore_patterns=exclude_patterns,
token=token,
)
if not query.url:
raise ValueError("The 'url' parameter is required.")

clone_config = query.extract_clone_config()
await clone_repo(clone_config)
await clone_repo(clone_config, token=token)
summary, tree, content = ingest_query(query)
with open(f"{clone_config.local_path}.txt", "w", encoding="utf-8") as f:
f.write(tree + "\n" + content)
Expand Down
7 changes: 6 additions & 1 deletion src/server/routers/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def process_catch_all(
max_file_size: int = Form(...),
pattern_type: str = Form(...),
pattern: str = Form(...),
token: str = Form(...),
) -> HTMLResponse:
"""
Process the form submission with user input for query parameters.
Expand All @@ -69,18 +70,22 @@ async def process_catch_all(
The type of pattern used for the query, specified by the user.
pattern : str
The pattern string used in the query, specified by the user.

token : str
GitHub personal-access token (PAT). Needed when *input_text* refers to a
**private** repository.
Returns
-------
HTMLResponse
An HTML response generated after processing the form input and query logic,
which will be rendered and returned to the user.
"""
resolved_token = None if token == "" else token
return await process_query(
request,
input_text,
max_file_size,
pattern_type,
pattern,
is_index=False,
token=resolved_token,
)
7 changes: 6 additions & 1 deletion src/server/routers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def index_post(
max_file_size: int = Form(...),
pattern_type: str = Form(...),
pattern: str = Form(...),
token: str = Form(...),
) -> HTMLResponse:
"""
Process the form submission with user input for query parameters.
Expand All @@ -67,18 +68,22 @@ async def index_post(
The type of pattern used for the query, specified by the user.
pattern : str
The pattern string used in the query, specified by the user.

token : str
GitHub personal-access token (PAT). Needed when *input_text* refers to a
**private** repository.
Returns
-------
HTMLResponse
An HTML response containing the results of processing the form input and query logic,
which will be rendered and returned to the user.
"""
resolved_token = None if token == "" else token
return await process_query(
request,
input_text,
max_file_size,
pattern_type,
pattern,
is_index=True,
token=resolved_token,
)
Loading
Loading