-
Notifications
You must be signed in to change notification settings - Fork 8
Add list commits #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list commits #84
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis update introduces a new API endpoint Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant API as API Endpoint (/list_commits)
participant GG as GitGraph
Client->>API: POST /list_commits {"repo": "repo_name"}
API->>API: Validate JSON and check "repo" parameter
alt Missing "repo"
API-->>Client: 400 Error (Missing "repo" parameter)
else Valid Request
API->>GG: Initialize GitGraph("repo_name")
GG-->>API: Return commit list
API-->>Client: 200 OK with commit list
end
Suggested Reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Hello @AviAvni, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces a new API endpoint, /list_commits
, which allows users to retrieve a list of commits for a specified repository. The changes include adding the new route in api/index.py
, incorporating necessary decorators for public access and token authentication, and utilizing the GitGraph
class to fetch the commit list. Additionally, the version number in pyproject.toml
has been incremented from 0.4.1 to 0.4.2.
Highlights
- New API Endpoint: A new endpoint
/list_commits
has been added to the API, enabling users to list all commits for a given repository. - Dependency Injection: The
GitGraph
class is used to interact with the repository and fetch the commit list. - Version Update: The project version has been updated from 0.4.1 to 0.4.2 in
pyproject.toml
.
Changelog
- api/index.py
- Imported the
GitGraph
class fromapi.git_utils.git_graph
. - Added a new route
/list_commits
that accepts POST requests. - Implemented the
list_commits
function to handle requests to the new endpoint. - The
list_commits
function retrieves the repository name from the request, initializes aGitGraph
object, fetches the commits, and returns them in a JSON response.
- Imported the
- pyproject.toml
- Incremented the project version from 0.4.1 to 0.4.2.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Trivia time!
What is the time complexity of listing all commits in a Git repository?
Click here for the answer
The time complexity of listing all commits in a Git repository is O(n), where n is the number of commits. This is because Git needs to traverse the commit history to retrieve all commits.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces a new endpoint to list commits for a given repository. The implementation appears straightforward and includes necessary validations and error handling. Overall, the code seems well-structured and addresses the intended functionality.
Merge Readiness
The pull request introduces a new feature and includes appropriate error handling and validation. The code appears to be well-structured and addresses the intended functionality. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. Given the absence of critical or high severity issues, the pull request seems ready for merging after addressing the comments provided.
return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 | ||
|
||
# Initialize GitGraph object to interact with the repository | ||
git_graph = GitGraph(git_utils.GitRepoName(repo)) |
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).name
directly to avoid creating an intermediate GitRepoName
object if you only need the name. This can improve readability and potentially reduce object creation overhead.
git_graph = GitGraph(git_utils.GitRepoName(repo)) | |
git_graph = GitGraph(repo) |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to add error handling around the git_graph.list_commits()
call. If this call fails (e.g., due to repository issues), the API should return an appropriate error response to the client. This enhances the robustness of the API.
try:
commits = git_graph.list_commits()
except Exception as e:
return jsonify({'status': f'Failed to list commits: {str(e)}'}), 500
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/index.py (1)
475-475
: Fix the unnecessary f-string.The f-string here doesn't contain any placeholders, so a regular string should be used instead.
- return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400🧰 Tools
🪛 Ruff (0.8.2)
475-475: f-string without any placeholders
Remove extraneous
f
prefix(F541)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
api/index.py
(2 hunks)pyproject.toml
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- pyproject.toml
🧰 Additional context used
🪛 Ruff (0.8.2)
api/index.py
475-475: f-string without any placeholders
Remove extraneous f
prefix
(F541)
🔇 Additional comments (1)
api/index.py (1)
10-10
: Nice addition of the required import.The addition of
GitGraph
import is appropriate for the new functionality being introduced.
@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() | ||
|
||
# Return success response with the list of commits | ||
response = { | ||
'status': 'success', | ||
'commits': commits | ||
} | ||
|
||
return jsonify(response), 200 |
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.
🛠️ 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:
- Missing repository existence check before attempting to fetch commits
- No error handling for potential GitGraph operations failures
- Unnecessary f-string in the error message
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
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff (0.8.2)
475-475: f-string without any placeholders
Remove extraneous f
prefix
(F541)
Summary by CodeRabbit
New Features
Chores