Skip to content

Commit

Permalink
Improved summary with branch and path
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclotruc committed Dec 8, 2024
1 parent a98945b commit 214efff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ def create_file_content_string(files: List[Dict]) -> str:

return output

def create_summary_string(result: Dict, files: List[Dict]) -> str:
def create_summary_string(result: Dict, files: List[Dict], query: dict) -> str:
"""Creates a summary string with file counts and content size."""
total_lines = sum(len(file["content"].splitlines()) for file in files)

return (
f"Files analyzed: {result['file_count']}\n"
f"Directories analyzed: {result['dir_count']}\n"
f"Total lines of content: {total_lines:,}\n"
f"branch: {query['branch'] if len(query['branch']) < 20 else query['branch'][:20] + '...'}\n"
f"path: {query['subpath']}\n"
)

def create_tree_structure(node: Dict, prefix: str = "", is_last: bool = True) -> str:
Expand All @@ -139,19 +141,19 @@ def create_tree_structure(node: Dict, prefix: str = "", is_last: bool = True) ->
return tree


def ingest_from_path(id: str, ignore_patterns: List[str] = DEFAULT_IGNORE_PATTERNS, max_file_size: int = MAX_FILE_SIZE, base_path: str = TMP_BASE_PATH) -> Dict:
def ingest_from_path(query: dict, path: str, ignore_patterns: List[str] = DEFAULT_IGNORE_PATTERNS, max_file_size: int = MAX_FILE_SIZE, base_path: str = TMP_BASE_PATH) -> Dict:
"""Main entry point for analyzing a codebase directory."""

path = f"{base_path}/{id}"
path = f"{base_path}/{path}"
if not os.path.exists(path):
raise ValueError(f"Path {path} does not exist")


nodes = analyze_directory(path, ignore_patterns, base_path)
files = get_all_files(nodes, max_file_size)
summary = create_summary_string(nodes, files)
tree = create_tree_structure(nodes)
summary = create_summary_string(nodes, files, query)
tree = "Directory structure:\n" + create_tree_structure(nodes)

formatted_content = create_file_content_string(files)
files_content = create_file_content_string(files)

return (summary, tree, formatted_content)
return (summary, tree, files_content)
2 changes: 1 addition & 1 deletion src/process_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async def process_query(query: dict) -> str:
print(query)
await clone_repo(query['url'], query['id'])

result = ingest_from_path(query['id'])
result = ingest_from_path(query, query['id'])

txt_dump = result[1] + "\n" + result[2]
with open(f"{TMP_BASE_PATH}/{query['id']}.txt", "w") as f:
Expand Down
2 changes: 1 addition & 1 deletion src/templates/components/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h3 class="text-lg font-bold text-gray-900">Summary</h3>
class="w-full h-full rounded bg-gray-900 translate-y-1 translate-x-1 absolute inset-0">
</div>
<textarea
class="w-full h-[150px] p-4 bg-[#fff4da] border-[3px] border-gray-900 rounded font-mono text-sm resize-none focus:outline-none relative z-10"
class="w-full h-[160px] p-4 bg-[#fff4da] border-[3px] border-gray-900 rounded font-mono text-sm resize-none focus:outline-none relative z-10"
readonly>{{ summary }}</textarea>
</div>
{% if ingest_id %}
Expand Down
16 changes: 9 additions & 7 deletions src/utils/parse_url.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

def parse_url(url: str) -> dict:
parsed = {
"url": None,

"user_name": None,
"repo_name": None,
"tree": False,
"type": None,
"branch": None,
"path": "/",
"subpath": "/",
"url": None,
}


Expand All @@ -23,13 +24,14 @@ def parse_url(url: str) -> dict:

parsed["user_name"] = path_parts[0]
parsed["repo_name"] = path_parts[1]


parsed["url"] = f"https://github.com/{parsed['user_name']}/{parsed['repo_name']}"
parsed['id'] = parsed["url"].replace("https://github.com/", "").replace("/", "-")

if len(path_parts) > 2:
if path_parts[2] == "tree":
parsed["tree"] = True
parsed["path"] = "/".join(path_parts[3:])
if len(path_parts) > 3:
parsed["type"] = path_parts[2]
parsed["branch"] = path_parts[3]
parsed["subpath"] = "/" + "/".join(path_parts[4:])
print(parsed)
return parsed

0 comments on commit 214efff

Please sign in to comment.