Thank you for your interest in contributing to Mergebot! This guide will help you get started.
- Python 3.12
- Poetry 2.1.2+
- Git
-
Clone the repository
git clone https://github.com/thehapyone/Mergebot.git cd Mergebot -
Install dependencies
poetry install --with dev
-
Install pre-commit hooks (strongly recommended)
make pre-commit-install
This will automatically run code quality checks before each commit.
Mergebot follows strict Python code quality standards to ensure maintainability and consistency.
We use the following tools to enforce code quality:
- Ruff - Fast Python linter and formatter
- Codespell - Spelling checker
- Pre-commit - Git hooks for automated checks
Before submitting a PR, ensure your code passes all checks:
# Format code
make format
# Run linting
make lint
# Check spelling
make spell_check
# Run all pre-commit checks
make pre-commit-run-
Naming Conventions (PEP 8)
snake_casefor functions, variables, and methodsPascalCasefor classesUPPER_CASEfor true module-level constants only- Class attributes should use
lowercase_with_underscores, notCAPITALS
# Good class GitHubAPIWrapper: request_timeout = (5, 30) # class attribute # Bad class GitHubAPIWrapper: REQUEST_TIMEOUT = (5, 30) # looks like a constant but isn't
-
Request Timeouts
- Always add timeouts to
requests.get()andrequests.post()calls
resp = requests.get(url, headers=headers, timeout=self.request_timeout)
- Always add timeouts to
-
Error Handling
- Use try-except blocks for network calls
- Log warnings/errors appropriately
try: resp = requests.get(url, timeout=timeout) except Exception as e: logger.warning(f"Failed to fetch: {e}")
-
Pagination
- Always handle pagination for API calls that could return large datasets
- Use configurable page sizes
-
Magic Numbers
- Extract hardcoded values to named constants
# Good log_tail_lines = 30 snippet[-log_tail_lines:] # Bad snippet[-30:]
Pre-commit hooks automatically run on every commit. They will:
- Format your code with Ruff
- Check for common issues
- Verify YAML/TOML syntax
- Check for large files
- Fix trailing whitespace
If a check fails, the commit is blocked. Fix the issues and try again.
Every pull request automatically runs:
- Linting - Ruff checks for code quality issues
- Formatting - Ensures consistent code style
- Spell checking - Catches typos in code and docs
- Docker build - Verifies the image builds correctly
PRs must pass all checks before merging.
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
- Write clean, well-documented code
- Follow the code style guidelines above
- Add tests if applicable
-
Run checks locally
make format make lint make spell_check
-
Commit your changes
git add . git commit -m "feat: your descriptive commit message"
Pre-commit hooks will run automatically.
-
Push and create a PR
git push origin feature/your-feature-name
Our Ruff configuration (in pyproject.toml) enforces:
- PEP 8 naming conventions (rule
N) - Modern Python idioms (rule
UP) - Bug detection (rule
B) - Code simplification (rule
SIM) - Pylint rules (rule
PL)
These rules catch common issues like:
- Non-Pythonic naming (e.g.,
REQUEST_TIMEOUTfor class attributes) - Missing error handling
- Unused imports
- Code complexity issues
- Check the documentation
- Open a GitHub discussion
- Report bugs via GitHub issues
Thank you for contributing to Mergebot! 🚀