Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"bitbucket.org",
"gitea.com",
"codeberg.org",
"gist.github.com",
"gitingest.com",
]

Expand Down
17 changes: 10 additions & 7 deletions src/gitingest/repository_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async def ingest_async(
TypeError
If `clone_repo` does not return a coroutine, or if the `source` is of an unsupported type.
"""
repo_cloned = False

try:
parsed_query: ParsedQuery = await parse_query(
source=source,
Expand All @@ -75,16 +77,18 @@ async def ingest_async(
commit=parsed_query.commit,
branch=selected_branch,
)
clone_result = clone_repo(clone_config)
clone_coroutine = clone_repo(clone_config)

if inspect.iscoroutine(clone_result):
if inspect.iscoroutine(clone_coroutine):
if asyncio.get_event_loop().is_running():
await clone_result
await clone_coroutine
else:
asyncio.run(clone_result)
asyncio.run(clone_coroutine)
else:
raise TypeError("clone_repo did not return a coroutine as expected.")

repo_cloned = True

summary, tree, content = run_ingest_query(parsed_query)

if output is not None:
Expand All @@ -94,9 +98,8 @@ async def ingest_async(
return summary, tree, content
finally:
# Clean up the temporary directory if it was created
if parsed_query.url:
# Clean up the temporary directory
shutil.rmtree(TMP_BASE_PATH, ignore_errors=True)
if repo_cloned:
shutil.rmtree(TMP_BASE_PATH)


def ingest(
Expand Down