Labsco
cayirtepeomer logo

Gerrit Code Review

โ˜… 37

from cayirtepeomer

Integrates with the Gerrit code review system to review code changes and details.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

Gerrit Review MCP Server

This MCP server provides integration with Gerrit code review system, allowing AI assistants to review code changes and their details through a simple interface.

Features

The server provides a streamlined toolset for code review:

Fetch Change Details

Copy & paste โ€” that's it
fetch_gerrit_change(change_id: str, patchset_number: Optional[str] = None)
  • Fetches complete change information including files and patch sets

  • Shows detailed diff information for each modified file

  • Displays file changes, insertions, and deletions

  • Supports reviewing specific patch sets

  • Returns comprehensive change details including:

  • Project and branch information

  • Author and reviewer details

  • Comments and review history

  • File modifications with diff content

  • Current patch set information

Compare Patchset Differences

Copy & paste โ€” that's it
fetch_patchset_diff(change_id: str, base_patchset: str, target_patchset: str, file_path: Optional[str] = None)
  • Compare differences between two patchsets of a change

  • View specific file differences or all changed files

  • Analyze code modifications across patchset versions

  • Track evolution of changes through review iterations

Submit Review Feedback

Copy & paste โ€” that's it
submit_gerrit_review(
 change_id: str,
 message: Optional[str] = None,
 patchset_number: Optional[str] = None,
 labels: Optional[Dict[str, int]] = None,
 comments: Optional[List[Dict[str, Any]]] = None,
 notify: str = "OWNER",
)
  • Post summary feedback, vote labels (e.g., {"Code-Review": 1}), and inline/file-level comments

  • Target a specific patchset or default to the latest revision

  • Control Gerrit's notification behaviour (notify: NONE, OWNER, OWNER_REVIEWERS, ALL)

  • Comment payloads accept dictionaries with path, message, and optional Gerrit comment fields (line, side, range, ...)

Example Usage

Review a complete change:

Copy & paste โ€” that's it
# Fetch latest patchset of change 23824
change = fetch_gerrit_change("23824")

Submit review feedback with a vote and inline comment:

Copy & paste โ€” that's it
submit_gerrit_review(
 change_id="23824",
 message="Looks good overall",
 labels={"Code-Review": 1},
 comments=[{"path": "src/app.py", "line": 42, "message": "Nice refactor."}],
 patchset_number="2", # optional: target a specific patchset
 notify="OWNER_REVIEWERS", # optional: adjust notification scope
)

Compare specific patchsets:

Copy & paste โ€” that's it
# Compare differences between patchsets 1 and 2 for change 23824
diff = fetch_patchset_diff("23824", "1", "2")

View specific file changes:

Copy & paste โ€” that's it
# Get diff for a specific file between patchsets
file_diff = fetch_patchset_diff("23824", "1", "2", "path/to/file.swift")

Implementation Details

The server uses Gerrit REST API to interact with Gerrit, providing:

  • Fast and reliable change information retrieval

  • Secure authentication using HTTP digest auth

  • Support for various Gerrit REST endpoints

  • Clean and maintainable codebase

  • HTTPS encryption for secure communication

License

This project is licensed under the MIT License.

Testing

This project includes comprehensive Docker integration tests using testcontainers-python for reliable cross-platform testing.

Running Tests

To run the full test suite:

Copy & paste โ€” that's it
# Install development dependencies
pip install -e ".[dev]"

# Run all tests
pytest

# Run only integration tests
pytest -m integration

# Run with verbose output
pytest -v

# Run with coverage
pytest --cov=. --cov-report=html

Test Environment Variables

The following environment variables can be used to configure test behavior:

  • TEST_STARTUP_TIMEOUT: Container startup timeout in seconds (default: 30)

  • TEST_LOGS_SETTLE_DELAY: Delay before checking logs in seconds (default: 0)

  • DOCKER_HOST: Docker daemon host for remote Docker (optional)

Example:

Copy & paste โ€” that's it
# Run tests with custom timeouts
TEST_STARTUP_TIMEOUT=60 TEST_LOGS_SETTLE_DELAY=1 pytest tests/test_docker_integration.py -v

Docker Requirements

Docker integration tests require:

  • Docker daemon running and accessible

  • Docker socket available at /var/run/docker.sock (Linux/macOS) or DOCKER_HOST set

  • Sufficient permissions to build and run containers

Tests will be automatically skipped if Docker is not available.

CI/CD Integration

For CI/CD environments, ensure:

  • Docker-in-Docker (DinD) service is available

  • Docker socket is mounted or DOCKER_HOST is configured

  • Sufficient timeout values are set for slower environments

Contributing

We welcome contributions! Please:

  • Fork the repository

  • Create a feature branch

  • Make your changes

  • Run the test suite to ensure everything works

  • Submit a pull request