A Python CLI tool for managing GitLab to GitHub repository mirroring with 2-way synchronization support.
- Interactive CLI: User-friendly command-line interface for managing mirrors
- 2-Way Sync: Supports GitLab-to-Github mirroring with local synchronization
- Batch Operations: Select and process multiple projects at once
- Read-Only Mode: Preview operations without making changes
- Registry Management: JSON-based state persistence for mirror tracking
- Error Handling: Robust error handling with retry mechanisms
- Local Git Integration: Manual setup of GitHub remotes in local repos via dedicated command
- Python 3.8+ - Core runtime
- python-gitlab - GitLab API client
- PyGithub - GitHub API client
- console-menu - Interactive CLI menus
- python-dotenv - Environment variable management
- Python 3.8 or higher
- Git installed and configured
- GitLab account with appropriate permissions
- GitHub account with repository creation permissions
- GitLab Personal Access Token with
apiscope - GitHub Personal Access Token with
reposcope
The easiest way to install and run lab2hub is with uv:
# Clone the repository
git clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git
cd lab2hub
# Run directly - uv handles venv creation and dependencies automatically
uv run lab2hubThat's it! The uv run lab2hub command will:
- Automatically create a virtual environment if needed
- Install all dependencies
- Run the lab2hub CLI
If you prefer to use pip or need more control over the installation:
-
Clone the repository:
git clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git cd lab2hub -
Create and activate virtual environment:
# Create virtual environment python -m venv .venv # Activate virtual environment # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate
-
Install dependencies:
pip install -e .Or with development dependencies:
pip install -e ".[dev]" -
Set up environment variables:
cp .env.example .env # Edit .env with your tokens
-
Configure your tokens in
.env:GITLAB_TOKEN=your_gitlab_token_here GITHUB_TOKEN=your_github_token_here GITLAB_URL=https://gitlab.com GITHUB_URL=https://github.com -
Run the CLI:
# With uv (recommended) uv run lab2hub # Or if installed with pip lab2hub
-
Available modes:
# Interactive mirror setup (default) uv run lab2hub # Or if installed with pip lab2hub # Read-only mode - preview without changes uv run lab2hub --read-only # Sync existing mirrors uv run lab2hub --sync # Force refresh GitLab cache uv run lab2hub --refresh # Setup local GitHub remote for 2-way sync uv run lab2hub --setup-local-remote
lab2hub/
|-- lab2hub/ # Main package
| |-- __init__.py
| |-- cli.py # Command-line interface
| |-- config.py # Configuration management
| |-- core.py # Main Lab2Hub class
| |-- client_manager.py # API client management
| |-- project_service.py # GitLab project operations
| |-- github_service.py # GitHub repository operations
| |-- mirror_service.py # Mirror setup and sync
| |-- registry.py # JSON registry management
| |-- local_operations.py # Local git operations
|-- tests/ # Test suite
| |-- __init__.py
| |-- test_config.py
|-- .env.example # Environment template
|-- .gitignore
|-- pyproject.toml # Project configuration
`-- README.md
The tool uses environment variables for configuration:
GITLAB_TOKEN- GitLab Personal Access TokenGITHUB_TOKEN- GitHub Personal Access Token
GITLAB_URL- GitLab instance URL (default: https://gitlab.com)GITHUB_URL- GitHub instance URL (default: https://github.com)GITLAB_GROUP- GitLab group to mirror from (default: auto-detect)
GitLab Token Requirements:
apiscope - Full API access
GitHub Token Requirements:
reposcope - Full repository access
-
Set up development environment:
# Clone and install git clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git cd lab2hub # Install with dev dependencies uv sync --dev # Run the CLI uv run lab2hub
-
Run tests:
uv run pytest
-
Code formatting:
uv run black gitlab_mirror/
-
Linting:
uv run flake8 gitlab_mirror/
-
Type checking:
uv run mypy gitlab_mirror/
-
Set up development environment:
# Clone and create virtual environment git clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git cd lab2hub python -m venv .venv # Activate virtual environment # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate # Install with dev dependencies pip install -e ".[dev]"
-
Run tests:
pytest
-
Code formatting:
black gitlab_mirror/
-
Linting:
flake8 gitlab_mirror/
-
Type checking:
mypy gitlab_mirror/
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=lab2hub
# Run specific test file
uv run pytest tests/test_config.py# Run all tests
pytest
# Run with coverage
pytest --cov=lab2hub
# Run specific test file
pytest tests/test_config.py-
Build the package:
uv build
-
Install from wheel:
pip install dist/lab2hub-1.6.2-py3-none-any.whl
-
Build the package:
python -m build
-
Install from wheel:
pip install dist/lab2hub-1.6.2-py3-none-any.whl
The tool is distributed as a Python package. Deploy by:
pip install lab2hubgit clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git
cd lab2hub
uv run lab2hub# Clone and create virtual environment
git clone https://gitlab.com/user4302_Projects/coding/python/lab2hub.git
cd lab2hub
python -m venv .venv
# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
# Install the package
pip install -e .
# Run the CLI
lab2hubContributions are welcome! Please see CONTRIBUTING.md for guidelines.
For questions, bugs, features, or security, open an issue on GitLab: https://gitlab.com/user4302_Projects/coding/python/lab2hub/-/issues
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, bugs, features, or security, open an issue on GitLab: https://gitlab.com/user4302_Projects/coding/python/lab2hub/-/issues
No email or direct support.