Skip to content

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

Merged
merged 2 commits into from
Mar 6, 2025
Merged

Add list commits #84

merged 2 commits into from
Mar 6, 2025

Conversation

AviAvni
Copy link
Contributor

@AviAvni AviAvni commented Mar 5, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an API endpoint enabling users to retrieve commit history for a specified repository with clear error guidance for missing input.
  • Chores

    • Updated the project version from 0.4.1 to 0.4.2.

Copy link

vercel bot commented Mar 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
code-graph-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 1:59pm

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This update introduces a new API endpoint /list_commits in the api/index.py file that accepts POST requests. The endpoint validates JSON input for a required repo parameter, uses a GitGraph object to retrieve commit data, and returns the commits in a structured response. Additionally, the project version in pyproject.toml has been bumped from 0.4.1 to 0.4.2.

Changes

File Change Summary
api/index.py Added the /list_commits endpoint with POST request handling, input validation for the repo parameter, and commit retrieval using GitGraph.
pyproject.toml Updated the project version from 0.4.1 to 0.4.2.

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
Loading

Suggested Reviewers

  • gkorland

Poem

I'm a hopping rabbit, leaping through the code,
New commits and magic, oh what a fun mode!
With carrots of logic and bits of delight,
I celebrate changes both coding and bright.
Hop on, dear coder, our journey's in sight!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 from api.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 a GitGraph object, fetches the commits, and returns them in a JSON response.
  • 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c40e43 and 42d13df.

📒 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.

Comment on lines +453 to +489
@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
Copy link
Contributor

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:

  1. Missing repository existence check before attempting to fetch commits
  2. No error handling for potential GitGraph operations failures
  3. 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)

@gkorland gkorland merged commit 2d71c19 into main Mar 6, 2025
4 checks passed
@gkorland gkorland deleted the add-list-commits branch March 6, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants