-
Notifications
You must be signed in to change notification settings - Fork 10
Add list commits #84
Add list commits #84
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| from api.analyzers.source_analyzer import SourceAnalyzer | ||
| from api.git_utils import git_utils | ||
| from api.git_utils.git_graph import GitGraph | ||
| from api.graph import Graph, get_repos, graph_exists | ||
| from api.info import get_repo_info | ||
| from api.llm import ask | ||
|
|
@@ -448,3 +449,41 @@ def switch_commit(): | |
| } | ||
|
|
||
| return jsonify(response), 200 | ||
|
|
||
| @app.route('/list_commits', methods=['POST']) | ||
| @public_access # Apply public access decorator | ||
| @token_required # Apply token authentication decorator | ||
| def list_commits(): | ||
| """ | ||
| Endpoint to list all commits of a specified repository. | ||
|
|
||
| Request JSON Structure: | ||
| { | ||
| "repo": "repository_name" | ||
| } | ||
|
|
||
| Returns: | ||
| JSON response with a list of commits or an error message. | ||
| """ | ||
|
|
||
| # Get JSON data from the request | ||
| data = request.get_json() | ||
|
|
||
| # Validate the presence of the 'repo' parameter | ||
| repo = data.get('repo') | ||
| if repo is None: | ||
| return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 | ||
|
|
||
| # Initialize GitGraph object to interact with the repository | ||
| git_graph = GitGraph(git_utils.GitRepoName(repo)) | ||
|
|
||
| # Fetch commits from the repository | ||
| commits = git_graph.list_commits() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be beneficial to add error handling around the try:
commits = git_graph.list_commits()
except Exception as e:
return jsonify({'status': f'Failed to list commits: {str(e)}'}), 500 |
||
|
|
||
| # Return success response with the list of commits | ||
| response = { | ||
| 'status': 'success', | ||
| 'commits': commits | ||
| } | ||
|
|
||
| return jsonify(response), 200 | ||
|
Comment on lines
+453
to
+489
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Good implementation of the new endpoint with a few improvements needed. The new endpoint for listing commits is well-structured and follows the established patterns in the codebase. However, there are a few issues to address:
Here's how to address these issues: @app.route('/list_commits', methods=['POST'])
@public_access # Apply public access decorator
@token_required # Apply token authentication decorator
def list_commits():
"""
Endpoint to list all commits of a specified repository.
Request JSON Structure:
{
"repo": "repository_name"
}
Returns:
JSON response with a list of commits or an error message.
"""
# Get JSON data from the request
data = request.get_json()
# Validate the presence of the 'repo' parameter
repo = data.get('repo')
if repo is None:
- return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400
+ return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400
+ # Validate repo exists
+ if not graph_exists(repo):
+ logging.error("Missing project %s", repo)
+ return jsonify({"status": f"Missing project {repo}"}), 400
# Initialize GitGraph object to interact with the repository
- git_graph = GitGraph(git_utils.GitRepoName(repo))
-
- # Fetch commits from the repository
- commits = git_graph.list_commits()
+ try:
+ git_graph = GitGraph(git_utils.GitRepoName(repo))
+
+ # Fetch commits from the repository
+ commits = git_graph.list_commits()
+ except Exception as e:
+ logging.error("Error retrieving commits for repo '%s': %s", repo, e)
+ return jsonify({"status": "Error retrieving commits"}), 500
# Return success response with the list of commits
response = {
'status': 'success',
'commits': commits
}
return jsonify(response), 200
🧰 Tools🪛 Ruff (0.8.2)475-475: f-string without any placeholders Remove extraneous (F541) |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
git_utils.GitRepoName(repo).namedirectly to avoid creating an intermediateGitRepoNameobject if you only need the name. This can improve readability and potentially reduce object creation overhead.