Skip to content

Commit dd8f33b

Browse files
committed
renamed main to app, added some endpoint docs
1 parent cf20131 commit dd8f33b

File tree

1 file changed

+81
-52
lines changed

1 file changed

+81
-52
lines changed

main.py renamed to app.py

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,47 @@ def graph_entities():
6363
logging.error(f"Error retrieving sub-graph for repo '{repo}': {e}")
6464
return jsonify({"error": "Internal server error"}), 500
6565

66+
6667
@app.route('/get_neighbors', methods=['GET'])
6768
def get_neighbors():
6869
"""
6970
Endpoint to get neighbors of a specific node in the graph.
7071
Expects 'repo' and 'node_id' as query parameters.
72+
73+
Returns:
74+
JSON response containing neighbors or error messages.
7175
"""
7276

73-
repo = request.args.get('repo')
77+
# Get query parameters
78+
repo = request.args.get('repo')
7479
node_id = request.args.get('node_id')
7580

81+
# Validate 'repo' parameter
7682
if not repo:
7783
logging.error("Repository name is missing in the request.")
7884
return jsonify({"error": "Repository name is required."}), 400
7985

86+
# Validate 'node_id' parameter
8087
if not node_id:
8188
logging.error("Node ID is missing in the request.")
8289
return jsonify({"error": "Node ID is required."}), 400
8390

91+
# Try converting node_id to an integer
8492
try:
85-
# Validate and convert node_id to integer
8693
node_id = int(node_id)
8794
except ValueError:
8895
logging.error(f"Invalid node ID: {node_id}. It must be an integer.")
8996
return jsonify({"error": "Invalid node ID. It must be an integer."}), 400
9097

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)
97100

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)
100103

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
104107

105108

106109
@app.route('/process_repo', methods=['POST'])
@@ -200,68 +203,65 @@ def process_local_repo():
200203

201204
@app.route('/process_code_coverage', methods=['POST'])
202205
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+
"""
203212

204213
# Get JSON data from the request
205214
data = request.get_json()
206215

207-
# Process the data
216+
# Validate that 'repo' is provided
208217
repo = data.get('repo')
209-
lcov = data.get('lcov')
210-
211218
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')
213224
if lcov is None:
225+
logging.warning("Missing mandatory parameter 'lcov'")
214226
return jsonify({'status': f'Missing mandatory parameter "lcov"'}), 400
215227

228+
# Process the lcov data for the repository
216229
process_lcov(repo, lcov)
217230

218-
# Create a response
231+
# Create a success response
219232
response = {
220233
'status': 'success',
221234
}
222235

223236
return jsonify(response), 200
224237

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()
230238

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.
246243
244+
Returns:
245+
JSON response with the change set or an error message.
246+
"""
247247

248-
@app.route('/switch_commit', methods=['POST'])
249-
def process_switch_commit():
250248
# Get JSON data from the request
251249
data = request.get_json()
252250

253-
# path to local repository
251+
# Validate that 'repo' is provided
254252
repo = data.get('repo')
255253
if repo is None:
256254
return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400
257255

256+
# Validate that 'commit' is provided
258257
commit = data.get('commit')
259258
if commit is None:
260259
return jsonify({'status': f'Missing mandatory parameter "commit"'}), 400
261260

261+
# Attempt to switch the repository to the specified commit
262262
change_set = switch_commit(repo, commit)
263263

264-
# Create a response
264+
# Create a success response
265265
response = {
266266
'status': 'success',
267267
'change_set': change_set
@@ -270,21 +270,31 @@ def process_switch_commit():
270270
return jsonify(response), 200
271271

272272
@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+
274281
# Get JSON data from the request
275282
data = request.get_json()
276283

277-
# path to local repository
284+
# Validate that 'repo' is provided
278285
repo = data.get('repo')
279286
if repo is None:
280287
return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400
281288

289+
# Validate that 'prefix' is provided
282290
prefix = data.get('prefix')
283291
if prefix is None:
284292
return jsonify({'status': f'Missing mandatory parameter "prefix"'}), 400
285293

294+
# Fetch auto-completion results
286295
completions = auto_complete(repo, prefix)
287-
# Create a response
296+
297+
# Create a success response
288298
response = {
289299
'status': 'success',
290300
'completions': completions
@@ -294,12 +304,18 @@ def process_auto_complete():
294304

295305

296306
@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+
"""
299314

315+
# Fetch list of repositories
300316
repos = list_repos()
301317

302-
# Create a response
318+
# Create a success response with the list of repositories
303319
response = {
304320
'status': 'success',
305321
'repositories': repos
@@ -309,21 +325,34 @@ def process_list_repos():
309325

310326

311327
@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+
313341
# Get JSON data from the request
314342
data = request.get_json()
315343

316-
# name of repository
344+
# Validate the presence of the 'repo' parameter
317345
repo = data.get('repo')
318346
if repo is None:
319347
return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400
320348

321-
# Get JSON data from the request
349+
# Initialize GitGraph object to interact with the repository
322350
git_graph = GitGraph(GitRepoName(repo))
323351

352+
# Fetch commits from the repository
324353
commits = git_graph.list_commits()
325354

326-
# Create a response
355+
# Return success response with the list of commits
327356
response = {
328357
'status': 'success',
329358
'commits': commits

0 commit comments

Comments
 (0)