Contributing to FileSyncHub
Thank you for your interest in contributing to FileSyncHub! This document provides guidelines and instructions for contributing to the project.
Table of Contents
- Code of Conduct
- Getting Started
- Development Setup
- Making Contributions
- Code Style
- Testing
- Documentation
- Pull Request Process
Code of Conduct
We follow the Rust Code of Conduct. Please read it before contributing.
Getting Started
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/FileSyncHub.git cd FileSyncHub
- Add the upstream remote:
git remote add upstream https://github.com/original-owner/FileSyncHub.git
Development Setup
Prerequisites
- Rust 1.70.0 or higher
- Cargo
- Git
Setting Up the Development Environment
- Install development dependencies:
cargo install cargo-watch cargo-audit cargo-tarpaulin
- Set up pre-commit hooks:
cp hooks/pre-commit .git/hooks/ chmod +x .git/hooks/pre-commit
- Create test credentials:
mkdir -p credentials cp examples/credentials/* credentials/
Making Contributions
Branch Naming Convention
- Feature:
feature/description
- Bug fix:
fix/issue-description
- Documentation:
docs/description
- Performance:
perf/description
Commit Messages
Follow the Conventional Commits specification:
type(scope): description
[optional body]
[optional footer]
Types:
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Code style changes
- refactor: Code refactoring
- perf: Performance improvements
- test: Adding or modifying tests
- chore: Maintenance tasks
Code Style
We follow the Rust standard style guide with some additional rules:
General Guidelines
- Use meaningful variable names
- Keep functions small and focused
- Document public APIs
- Use type inference when obvious
- Prefer early returns
Specific Rules
- Error Handling:
// Good let result = operation().context("Failed to perform operation")?; // Avoid let result = operation().unwrap();
- Async/Await:
// Good async fn process_file(path: &Path) -> Result<()> { let data = read_file(path).await?; process_data(data).await }
- Error Types:
// Good #[derive(Debug, thiserror::Error)] pub enum Error { #[error("IO error: {0}")] Io(#[from] std::io::Error), }
Testing
Running Tests
# Run all tests
cargo test
# Run specific test
cargo test test_name
# Run tests with coverage
cargo tarpaulin
Writing Tests
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_file_upload() -> Result<()> {
// Arrange
let client = create_test_client().await?;
let test_file = create_temp_file()?;
// Act
let result = client.upload_file(&test_file).await;
// Assert
assert!(result.is_ok());
Ok(())
}
}
Documentation
Code Documentation
- Document all public items
- Include examples in doc comments
- Use markdown in doc comments
Example:
/// Uploads a file to the cloud storage.
///
/// # Arguments
///
/// * `path` - Path to the file to upload
/// * `chunk_size` - Size of each chunk in bytes
///
/// # Examples
///
/// ```
/// # use filesynchub::upload_file;
/// # async fn example() -> Result<()> {
/// let result = upload_file("path/to/file", 1024).await?;
/// # Ok(())
/// # }
/// ```
pub async fn upload_file(path: &Path, chunk_size: usize) -> Result<()> {
// Implementation
}
User Documentation
- Keep it clear and concise
- Include examples
- Update when adding features
- Use proper formatting
Pull Request Process
- Update documentation
- Add tests for new features
- Ensure CI passes
- Update CHANGELOG.md
- Request review
- Address feedback
PR Template
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Performance improvement
## Testing
Describe how you tested the changes
## Checklist
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] CHANGELOG.md updated
- [ ] Formatting checked