@@ -63,44 +63,47 @@ def graph_entities():
63
63
logging .error (f"Error retrieving sub-graph for repo '{ repo } ': { e } " )
64
64
return jsonify ({"error" : "Internal server error" }), 500
65
65
66
+
66
67
@app .route ('/get_neighbors' , methods = ['GET' ])
67
68
def get_neighbors ():
68
69
"""
69
70
Endpoint to get neighbors of a specific node in the graph.
70
71
Expects 'repo' and 'node_id' as query parameters.
72
+
73
+ Returns:
74
+ JSON response containing neighbors or error messages.
71
75
"""
72
76
73
- repo = request .args .get ('repo' )
77
+ # Get query parameters
78
+ repo = request .args .get ('repo' )
74
79
node_id = request .args .get ('node_id' )
75
80
81
+ # Validate 'repo' parameter
76
82
if not repo :
77
83
logging .error ("Repository name is missing in the request." )
78
84
return jsonify ({"error" : "Repository name is required." }), 400
79
85
86
+ # Validate 'node_id' parameter
80
87
if not node_id :
81
88
logging .error ("Node ID is missing in the request." )
82
89
return jsonify ({"error" : "Node ID is required." }), 400
83
90
91
+ # Try converting node_id to an integer
84
92
try :
85
- # Validate and convert node_id to integer
86
93
node_id = int (node_id )
87
94
except ValueError :
88
95
logging .error (f"Invalid node ID: { node_id } . It must be an integer." )
89
96
return jsonify ({"error" : "Invalid node ID. It must be an integer." }), 400
90
97
91
- try :
92
- # Initialize the graph with the provided repo and credentials
93
- g = Graph (repo )
94
-
95
- # Get neighbors of the given node
96
- neighbors = g .get_neighbors (node_id )
98
+ # Initialize the graph with the provided repository
99
+ g = Graph (repo )
97
100
98
- logging . info ( f"Successfully retrieved neighbors for node ID { node_id } in repo ' { repo } '." )
99
- return jsonify ( neighbors ), 200
101
+ # Fetch the neighbors of the specified node
102
+ neighbors = g . get_neighbors ( node_id )
100
103
101
- except Exception as e :
102
- logging .error (f"Error retrieving node neighbors for repo '{ repo } ': { e } " )
103
- return jsonify ({ "error" : "Internal server error" } ), 500
104
+ # Log and return the neighbors
105
+ logging .info (f"Successfully retrieved neighbors for node ID { node_id } in repo '{ repo } '. " )
106
+ return jsonify (neighbors ), 200
104
107
105
108
106
109
@app .route ('/process_repo' , methods = ['POST' ])
@@ -200,68 +203,65 @@ def process_local_repo():
200
203
201
204
@app .route ('/process_code_coverage' , methods = ['POST' ])
202
205
def process_code_coverage ():
206
+ """
207
+ Endpoint to process code coverage data for a given repository.
208
+
209
+ Returns:
210
+ JSON response indicating success or an error message.
211
+ """
203
212
204
213
# Get JSON data from the request
205
214
data = request .get_json ()
206
215
207
- # Process the data
216
+ # Validate that 'repo' is provided
208
217
repo = data .get ('repo' )
209
- lcov = data .get ('lcov' )
210
-
211
218
if repo is None :
212
- return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
219
+ logging .warning ("Missing mandatory parameter 'repo'" )
220
+ return jsonify ({'status' : 'error' , 'message' : 'Missing mandatory parameter "repo"' }), 400
221
+
222
+ # Validate that 'lcov' is provided
223
+ lcov = data .get ('lcov' )
213
224
if lcov is None :
225
+ logging .warning ("Missing mandatory parameter 'lcov'" )
214
226
return jsonify ({'status' : f'Missing mandatory parameter "lcov"' }), 400
215
227
228
+ # Process the lcov data for the repository
216
229
process_lcov (repo , lcov )
217
230
218
- # Create a response
231
+ # Create a success response
219
232
response = {
220
233
'status' : 'success' ,
221
234
}
222
235
223
236
return jsonify (response ), 200
224
237
225
- @app .route ('/process_git_history' , methods = ['POST' ])
226
- def process_git_history ():
227
-
228
- # Get JSON data from the request
229
- data = request .get_json ()
230
238
231
- # path to local repository
232
- repo = data .get ('repo' )
233
- if repo is None :
234
- return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
235
-
236
- ignore_list = data .get ('ignore' ) or []
237
-
238
- build_commit_graph (repo , ignore_list )
239
-
240
- # Create a response
241
- response = {
242
- 'status' : 'success' ,
243
- }
244
-
245
- return jsonify (response ), 200
239
+ @app .route ('/switch_commit' , methods = ['POST' ])
240
+ def switch_commit ():
241
+ """
242
+ Endpoint to switch a repository to a specific commit.
246
243
244
+ Returns:
245
+ JSON response with the change set or an error message.
246
+ """
247
247
248
- @app .route ('/switch_commit' , methods = ['POST' ])
249
- def process_switch_commit ():
250
248
# Get JSON data from the request
251
249
data = request .get_json ()
252
250
253
- # path to local repository
251
+ # Validate that 'repo' is provided
254
252
repo = data .get ('repo' )
255
253
if repo is None :
256
254
return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
257
255
256
+ # Validate that 'commit' is provided
258
257
commit = data .get ('commit' )
259
258
if commit is None :
260
259
return jsonify ({'status' : f'Missing mandatory parameter "commit"' }), 400
261
260
261
+ # Attempt to switch the repository to the specified commit
262
262
change_set = switch_commit (repo , commit )
263
263
264
- # Create a response
264
+ # Create a success response
265
265
response = {
266
266
'status' : 'success' ,
267
267
'change_set' : change_set
@@ -270,21 +270,31 @@ def process_switch_commit():
270
270
return jsonify (response ), 200
271
271
272
272
@app .route ('/auto_complete' , methods = ['POST' ])
273
- def process_auto_complete ():
273
+ def auto_complete ():
274
+ """
275
+ Endpoint to process auto-completion requests for a repository based on a prefix.
276
+
277
+ Returns:
278
+ JSON response with auto-completion suggestions or an error message.
279
+ """
280
+
274
281
# Get JSON data from the request
275
282
data = request .get_json ()
276
283
277
- # path to local repository
284
+ # Validate that 'repo' is provided
278
285
repo = data .get ('repo' )
279
286
if repo is None :
280
287
return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
281
288
289
+ # Validate that 'prefix' is provided
282
290
prefix = data .get ('prefix' )
283
291
if prefix is None :
284
292
return jsonify ({'status' : f'Missing mandatory parameter "prefix"' }), 400
285
293
294
+ # Fetch auto-completion results
286
295
completions = auto_complete (repo , prefix )
287
- # Create a response
296
+
297
+ # Create a success response
288
298
response = {
289
299
'status' : 'success' ,
290
300
'completions' : completions
@@ -294,12 +304,18 @@ def process_auto_complete():
294
304
295
305
296
306
@app .route ('/list_repos' , methods = ['GET' ])
297
- def process_list_repos ():
298
- # Get JSON data from the request
307
+ def list_repos ():
308
+ """
309
+ Endpoint to list all available repositories.
310
+
311
+ Returns:
312
+ JSON response with a list of repositories or an error message.
313
+ """
299
314
315
+ # Fetch list of repositories
300
316
repos = list_repos ()
301
317
302
- # Create a response
318
+ # Create a success response with the list of repositories
303
319
response = {
304
320
'status' : 'success' ,
305
321
'repositories' : repos
@@ -309,21 +325,34 @@ def process_list_repos():
309
325
310
326
311
327
@app .route ('/list_commits' , methods = ['POST' ])
312
- def process_list_commits ():
328
+ def list_commits ():
329
+ """
330
+ Endpoint to list all commits of a specified repository.
331
+
332
+ Request JSON Structure:
333
+ {
334
+ "repo": "repository_name"
335
+ }
336
+
337
+ Returns:
338
+ JSON response with a list of commits or an error message.
339
+ """
340
+
313
341
# Get JSON data from the request
314
342
data = request .get_json ()
315
343
316
- # name of repository
344
+ # Validate the presence of the 'repo' parameter
317
345
repo = data .get ('repo' )
318
346
if repo is None :
319
347
return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
320
348
321
- # Get JSON data from the request
349
+ # Initialize GitGraph object to interact with the repository
322
350
git_graph = GitGraph (GitRepoName (repo ))
323
351
352
+ # Fetch commits from the repository
324
353
commits = git_graph .list_commits ()
325
354
326
- # Create a response
355
+ # Return success response with the list of commits
327
356
response = {
328
357
'status' : 'success' ,
329
358
'commits' : commits
0 commit comments