Skip to content

Commit 8fbcb11

Browse files
committed
list commits
1 parent f935277 commit 8fbcb11

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

code_graph/git_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .git_utils import build_commit_graph, switch_commit, GitGraph
1+
from .git_utils import *

code_graph/git_utils/git_graph.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from falkordb import FalkorDB
1+
from falkordb import FalkorDB, Node
22
from typing import List, Optional
33

44
class GitGraph():
@@ -23,6 +23,15 @@ def __init__(self, name: str, host: str = 'localhost', port: int = 6379,
2323
except Exception:
2424
pass
2525

26+
def _commit_from_node(self, node:Node) -> dict:
27+
"""
28+
Returns a dict representing a commit node
29+
"""
30+
31+
return {'hash': node.properties['hash'],
32+
'date': node.properties['date'],
33+
'author': node.properties['author'],
34+
'message': node.properties['message']}
2635

2736
def add_commit(self, commit_hash: str, author: str, message: str, date: int) -> None:
2837
"""
@@ -32,6 +41,16 @@ def add_commit(self, commit_hash: str, author: str, message: str, date: int) ->
3241
params = {'hash': commit_hash, 'author': author, 'message': message, 'date': date}
3342
self.g.query(q, params)
3443

44+
def list_commits(self) -> List[Node]:
45+
"""
46+
List all commits
47+
"""
48+
49+
q = "MATCH (c:Commit) RETURN c ORDER BY c.date"
50+
result_set = self.g.query(q).result_set
51+
52+
return [self._commit_from_node(row[0]) for row in result_set]
53+
3554
def get_commits(self, hashes: List[str]) -> List[dict]:
3655
q = """MATCH (c:Commit)
3756
WHERE c.hash IN $hashes
@@ -42,12 +61,7 @@ def get_commits(self, hashes: List[str]) -> List[dict]:
4261

4362
commits = []
4463
for row in res:
45-
commit = row[0]
46-
commit = {'hash': commit.properties['hash'],
47-
'date': commit.properties['date'],
48-
'author': commit.properties['author'],
49-
'message': commit.properties['message']}
50-
64+
commit = self._commit_from_node(row[0])
5165
commits.append(commit)
5266

5367
return commits

code_graph/graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def list_repos() -> List[str]:
1717
username=FALKORDB_USERNAME, password=FALKORDB_PASSWORD)
1818

1919
graphs = db.list_graphs()
20-
print(f"graphs: {graphs}")
2120
graphs = [g for g in graphs if not g.endswith('_git')]
2221
return graphs
2322

main.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,9 @@ def process_auto_complete():
288288

289289
@app.route('/list_repos', methods=['GET'])
290290
def process_list_repos():
291-
print("Hello!")
292291
# Get JSON data from the request
293292

294293
repos = list_repos()
295-
print(f"repos: {repos}")
296294

297295
# Create a response
298296
response = {
@@ -303,6 +301,30 @@ def process_list_repos():
303301
return jsonify(response), 200
304302

305303

304+
@app.route('/list_commits', methods=['POST'])
305+
def process_list_commits():
306+
# Get JSON data from the request
307+
data = request.get_json()
308+
309+
# name of repository
310+
repo = data.get('repo')
311+
if repo is None:
312+
return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400
313+
314+
# Get JSON data from the request
315+
git_graph = GitGraph(GitRepoName(repo), host=FALKORDB_HOST, port=FALKORDB_PORT,
316+
username=FALKORDB_USERNAME, password=FALKORDB_PASSWORD)
317+
318+
commits = git_graph.list_commits()
319+
320+
# Create a response
321+
response = {
322+
'status': 'success',
323+
'commits': commits
324+
}
325+
326+
return jsonify(response), 200
327+
306328
if __name__ == '__main__':
307329
app.run(debug=True)
308330

0 commit comments

Comments
 (0)