Skip to content

Commit 6f02ce4

Browse files
committed
fix list repos
1 parent 4afc53a commit 6f02ce4

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

app.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,15 @@ def process_repo():
140140
# Create source code analyzer
141141
analyzer = SourceAnalyzer()
142142

143-
try:
144-
analyzer.analyze_github_repository(git_url, repo_path, repo_name, ignore)
145-
build_commit_graph(repo_path, repo_name, ignore)
146-
except Exception as e:
147-
logger.error(f'An error occurred: {e}')
148-
return jsonify({'status': f'Failed to process repository: {git_url}'}), 400
143+
analyzer.analyze_github_repository(git_url, repo_path, repo_name, ignore)
144+
build_commit_graph(repo_path, repo_name, ignore)
145+
146+
#try:
147+
# analyzer.analyze_github_repository(git_url, repo_path, repo_name, ignore)
148+
# build_commit_graph(repo_path, repo_name, ignore)
149+
#except Exception as e:
150+
# logger.error(f'An error occurred: {e}')
151+
# return jsonify({'status': f'Failed to process repository: {git_url}'}), 400
149152

150153
save_repo_info(repo_name, repo_url)
151154

@@ -172,10 +175,7 @@ def process_local_repo():
172175
logger.debug(f"Ignoring the following paths: {ignore}")
173176

174177
# Create source code analyzer
175-
analyzer = SourceAnalyzer(host = FALKORDB_HOST,
176-
port = FALKORDB_PORT,
177-
username = FALKORDB_USERNAME,
178-
password = FALKORDB_PASSWORD)
178+
analyzer = SourceAnalyzer()
179179

180180
try:
181181
analyzer.analyze_local_repository(repo, ignore)
@@ -302,7 +302,7 @@ def list_repos():
302302
"""
303303

304304
# Fetch list of repositories
305-
repos = list_repos()
305+
repos = get_repos()
306306

307307
# Create a success response with the list of repositories
308308
response = {

code_graph/graph.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import time
33
from .entities import *
4-
from typing import Dict, List, Optional
4+
from typing import Dict, List, Optional, Tuple
55
from falkordb import FalkorDB, Path, Node, QueryResult
66

77
# Configure the logger
@@ -10,7 +10,7 @@
1010
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
1111
logger = logging.getLogger(__name__)
1212

13-
def list_repos() -> List[str]:
13+
def get_repos() -> List[str]:
1414
"""
1515
List processed repositories
1616
"""
@@ -93,15 +93,40 @@ def enable_backlog(self) -> None:
9393
Enables the backlog by initializing an empty list.
9494
"""
9595

96-
self.backlog = []
96+
print("Graph backlog is enabled")
97+
self.backlog = {'queries': [], 'params': []}
9798

9899
def disable_backlog(self) -> None:
99100
"""
100101
Disables the backlog by setting it to None.
101102
"""
102103

104+
print("Graph backlog is disabled")
103105
self.backlog = None
104106

107+
def clear_backlog(self) -> Tuple[List[str], List[dict]]:
108+
"""
109+
Clears and returns the backlog of queries and parameters.
110+
111+
Returns:
112+
Tuple[List[str], List[dict]]: A tuple containing two lists:
113+
- The first list contains the backlog of queries.
114+
- The second list contains the backlog of query parameters.
115+
"""
116+
117+
if self.backlog:
118+
queries = self.backlog['queries']
119+
params = self.backlog['params']
120+
self.backlog = {'queries': [], 'params': []}
121+
print("clear_backlog returning:")
122+
print(f"queries: {queries}")
123+
print(f"params: {params}")
124+
return queries, params
125+
else:
126+
# Return empty lists if backlog is not initialized or empty
127+
return [], []
128+
129+
105130
def _query(self, q: str, params: dict) -> QueryResult:
106131
"""
107132
Executes a query on the graph database and logs changes to the backlog if any.
@@ -116,7 +141,9 @@ def _query(self, q: str, params: dict) -> QueryResult:
116141

117142
result_set = self.g.query(q, params)
118143

144+
print(f"In _query, self.backlog: {self.backlog}")
119145
if self.backlog is not None:
146+
print("Graph backlog is enabled")
120147
# Check if any change occurred in the query results
121148
change_detected = any(
122149
getattr(result_set, attr) > 0
@@ -126,10 +153,14 @@ def _query(self, q: str, params: dict) -> QueryResult:
126153
'properties_removed', 'relationships_created'
127154
]
128155
)
156+
print(f"change_detected: {change_detected}")
129157

130158
# Append the query and parameters to the backlog if changes occurred
131159
if change_detected:
132-
self.backlog.append((q, params))
160+
print(f"logging queries: {q}")
161+
print(f"logging params: {params}")
162+
self.backlog['queries'].append(q)
163+
self.backlog['params'].append(params)
133164

134165
return result_set
135166

@@ -452,7 +483,7 @@ def add_file(self, file: File) -> None:
452483
res = self._query(q, params)
453484
file.id = res.result_set[0][0]
454485

455-
def delete_files(self, files: List[dict], log: bool = False) -> tuple[str, dict, List[int]]:
486+
def delete_files(self, files: List[dict]) -> tuple[str, dict, List[int]]:
456487
"""
457488
Deletes file(s) from the graph in addition to any other entity
458489
defined in the file
@@ -476,9 +507,6 @@ def delete_files(self, files: List[dict], log: bool = False) -> tuple[str, dict,
476507
params = {'files': files}
477508
res = self._query(q, params)
478509

479-
if log and (res.relationships_deleted > 0 or res.nodes_deleted > 0):
480-
return (q, params)
481-
482510
return None
483511

484512
def get_file(self, path: str, name: str, ext: str) -> Optional[File]:

0 commit comments

Comments
 (0)